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

fix: add ImportExpression visitorKeys #11932

Merged
merged 1 commit into from Aug 8, 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
2 changes: 2 additions & 0 deletions eslint/babel-eslint-parser/src/convert/convertAST.js
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions eslint/babel-eslint-parser/src/visitor-keys.js
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion eslint/babel-eslint-parser/test/index.js
Expand Up @@ -569,7 +569,7 @@ describe("Babel and Espree", () => {

it("Dynamic Import", () => {
parseAndAssertSame(`
const a = import('a');
const a = import(moduleName);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test example is revised so that if we do not update VISITOR_KEYS, the identifier will not be traversed and the test will fail due to mismatch AST. Note that when traversing AST we remove loc.identifierName.

`);
});
});
Expand Down