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:
@@ -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
|
||||
|
||||
@@ -1095,6 +1095,7 @@ export type EstreeMethodDefinition = NodeBase & {
|
||||
export type EstreeImportExpression = NodeBase & {
|
||||
type: "ImportExpression",
|
||||
source: Expression,
|
||||
attributes?: Expression | null,
|
||||
};
|
||||
|
||||
export type EstreePrivateIdentifier = NodeBase & {
|
||||
|
||||
Reference in New Issue
Block a user