Skip to content

Commit

Permalink
@babel/eslint-parser: fix ImportExpression node to match ESTree spec
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Dec 6, 2019
1 parent c9a6898 commit f83e53f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion eslint/babel-eslint-parser/test/babel-eslint-parser.js
Expand Up @@ -27,7 +27,7 @@ function parseAndAssertSame(code) {
loc: true,
range: true,
comment: true,
ecmaVersion: 2018,
ecmaVersion: 2020,
sourceType: "module",
});
const babylonAST = parseForESLint(code, {
Expand Down Expand Up @@ -518,5 +518,11 @@ describe("babylon-to-espree", () => {
}
`);
});

it("Dynamic Import", () => {
parseAndAssertSame(`
const a = import('a');
`);
});
});
});
10 changes: 6 additions & 4 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -785,6 +785,7 @@ export default class ExpressionParser extends LValParser {
node: T,
optional: boolean,
): T {
let nodeType = optional ? "OptionalCallExpression" : "CallExpression";
if (node.callee.type === "Import") {
if (node.arguments.length !== 1) {
this.raise(node.start, "import() requires exactly one argument");
Expand All @@ -794,11 +795,12 @@ export default class ExpressionParser extends LValParser {
this.raise(importArg.start, "... is not allowed in import()");
}
}

if (this.hasPlugin("estree")) {
nodeType = "ImportExpression";
}
}
return this.finishNode(
node,
optional ? "OptionalCallExpression" : "CallExpression",
);
return this.finishNode(node, nodeType);
}

parseCallExpressionArguments(
Expand Down

0 comments on commit f83e53f

Please sign in to comment.