Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure estree test should not throw if babel parser does not throw #12443

Merged
merged 2 commits into from Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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