Skip to content

Commit

Permalink
Make sure estree test should not throw if babel parser does not throw (
Browse files Browse the repository at this point in the history
…#12443)

* test: run estree on tests that does not expect an errors

* fix: record the directive expression value to extra AST properties
  • Loading branch information
JLHwung committed Dec 4, 2020
1 parent 208acb1 commit 3bd6a3d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
9 changes: 5 additions & 4 deletions packages/babel-parser/src/plugins/estree.js
Expand Up @@ -61,7 +61,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
directiveLiteral.loc.start,
);

expression.value = directiveLiteral.value;
expression.value = directiveLiteral.extra.expressionValue;
expression.raw = directiveLiteral.extra.raw;

stmt.expression = this.finishNodeAt(
Expand Down Expand Up @@ -118,9 +118,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const directive = super.stmtToDirective(stmt);
const value = stmt.expression.value;

// Reset value to the actual value as in estree mode we want
// the stmt to have the real value and not the raw value
directive.value.value = value;
// Record the expression value as in estree mode we want
// the stmt to have the real value e.g. ("use strict") and
// not the raw value e.g. ("use\\x20strict")
this.addExtra(directive.value, "expressionValue", value);

return directive;
}
Expand Down
8 changes: 0 additions & 8 deletions packages/babel-parser/test/helpers/runFixtureTests.js
Expand Up @@ -83,14 +83,6 @@ export function runThrowTestsWithEstree(fixturesPath, parseFunction) {
Object.keys(fixtures).forEach(function (name) {
fixtures[name].forEach(function (testSuite) {
testSuite.tests.forEach(function (task) {
if (!task.options.throws) {
const hasErrors =
!task.disabled && "errors" in JSON.parse(task.expect.code);
if (!hasErrors) {
return;
}
}

task.options.plugins = task.options.plugins || [];
task.options.plugins.push("estree");

Expand Down

0 comments on commit 3bd6a3d

Please sign in to comment.