Parse attributes of import expression with estree plugin (#13284)

* Parse attributes of import expression with estree plugin

* Add tests

* Update packages/babel-parser/src/types.js

Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>

Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
This commit is contained in:
Sosuke Suzuki
2021-05-08 05:37:20 +09:00
committed by GitHub
parent e74b3fb1c6
commit 1d54419ec4
8 changed files with 110 additions and 0 deletions

View File

@@ -377,6 +377,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
if (node.callee.type === "Import") {
((node: N.Node): N.EstreeImportExpression).type = "ImportExpression";
((node: N.Node): N.EstreeImportExpression).source = node.arguments[0];
if (this.hasPlugin("importAssertions")) {
((node: N.Node): N.EstreeImportExpression).attributes =
node.arguments[1] ?? null;
}
// $FlowIgnore - arguments isn't optional in the type definition
delete node.arguments;
// $FlowIgnore - callee isn't optional in the type definition

View File

@@ -1095,6 +1095,7 @@ export type EstreeMethodDefinition = NodeBase & {
export type EstreeImportExpression = NodeBase & {
type: "ImportExpression",
source: Expression,
attributes?: Expression | null,
};
export type EstreePrivateIdentifier = NodeBase & {