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

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

* fix: record the directive expression value to extra AST properties
This commit is contained in:
Huáng Jùnliàng 2020-12-04 13:58:01 -05:00 committed by GitHub
parent 208acb1d6c
commit 3bd6a3d781
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 12 deletions

View File

@ -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(
@ -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;
}

View File

@ -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");