From 3bd6a3d781bcfb4580d5c1f3c5f27b05267c1b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 4 Dec 2020 13:58:01 -0500 Subject: [PATCH] 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 --- packages/babel-parser/src/plugins/estree.js | 9 +++++---- packages/babel-parser/test/helpers/runFixtureTests.js | 8 -------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/packages/babel-parser/src/plugins/estree.js b/packages/babel-parser/src/plugins/estree.js index 3368b0f138..d9416b95e3 100644 --- a/packages/babel-parser/src/plugins/estree.js +++ b/packages/babel-parser/src/plugins/estree.js @@ -61,7 +61,7 @@ export default (superClass: Class): Class => 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): Class => 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; } diff --git a/packages/babel-parser/test/helpers/runFixtureTests.js b/packages/babel-parser/test/helpers/runFixtureTests.js index 2ce9e888d5..46d19c2a1a 100644 --- a/packages/babel-parser/test/helpers/runFixtureTests.js +++ b/packages/babel-parser/test/helpers/runFixtureTests.js @@ -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");