From 69c9f1ecec19d8dba71ccc04027ba3ab7eb57f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sat, 8 Aug 2020 08:10:45 -0400 Subject: [PATCH] fix: add ImportExpression visitorKeys --- eslint/babel-eslint-parser/src/convert/convertAST.js | 2 ++ eslint/babel-eslint-parser/src/visitor-keys.js | 1 + eslint/babel-eslint-parser/test/index.js | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/eslint/babel-eslint-parser/src/convert/convertAST.js b/eslint/babel-eslint-parser/src/convert/convertAST.js index d44cce84b203..0d714ba5d00b 100644 --- a/eslint/babel-eslint-parser/src/convert/convertAST.js +++ b/eslint/babel-eslint-parser/src/convert/convertAST.js @@ -87,6 +87,7 @@ function convertNodes(ast, code) { try { // Monkey patch visitor keys in order to be able to traverse the estree nodes t.VISITOR_KEYS.ChainExpression = VISITOR_KEYS.ChainExpression; + t.VISITOR_KEYS.ImportExpression = VISITOR_KEYS.ImportExpression; t.VISITOR_KEYS.Property = VISITOR_KEYS.Property; t.VISITOR_KEYS.MethodDefinition = VISITOR_KEYS.MethodDefinition; @@ -99,6 +100,7 @@ function convertNodes(ast, code) { } finally { // These can be safely deleted because they are not defined in the original visitor keys. delete t.VISITOR_KEYS.ChainExpression; + delete t.VISITOR_KEYS.ImportExpression; delete t.VISITOR_KEYS.MethodDefinition; delete t.VISITOR_KEYS.Property; diff --git a/eslint/babel-eslint-parser/src/visitor-keys.js b/eslint/babel-eslint-parser/src/visitor-keys.js index 9908664dced8..3d28bde44cac 100644 --- a/eslint/babel-eslint-parser/src/visitor-keys.js +++ b/eslint/babel-eslint-parser/src/visitor-keys.js @@ -8,6 +8,7 @@ export default Object.assign( { ChainExpression: ESLINT_VISITOR_KEYS.ChainExpression, ExportAllDeclaration: ESLINT_VISITOR_KEYS.ExportAllDeclaration, + ImportExpression: ESLINT_VISITOR_KEYS.ImportExpression, Literal: ESLINT_VISITOR_KEYS.Literal, MethodDefinition: ["decorators"].concat( ESLINT_VISITOR_KEYS.MethodDefinition, diff --git a/eslint/babel-eslint-parser/test/index.js b/eslint/babel-eslint-parser/test/index.js index a7f2d3e91ef6..7c98083d4f61 100644 --- a/eslint/babel-eslint-parser/test/index.js +++ b/eslint/babel-eslint-parser/test/index.js @@ -569,7 +569,7 @@ describe("Babel and Espree", () => { it("Dynamic Import", () => { parseAndAssertSame(` - const a = import('a'); + const a = import(moduleName); `); }); });