Skip to content

Commit

Permalink
provide compatibility with legacy ESTree AST
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jun 7, 2023
1 parent 7f3c847 commit 682e32d
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/babel-parser/src/plugins/estree.ts
Expand Up @@ -426,6 +426,9 @@ export default (superClass: typeof Parser) =>
) {
(node as N.Node as N.EstreeImportExpression).options =
node.arguments[1] ?? null;
// compatibility with previous ESTree AST
(node as N.Node as N.EstreeImportExpression).attributes =
node.arguments[1] ?? null;
}
// arguments isn't optional in the type definition
delete node.arguments;
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-parser/src/types.d.ts
Expand Up @@ -1220,6 +1220,10 @@ export interface EstreeImportExpression extends NodeBase {
type: "ImportExpression";
source: Expression;
options?: Expression | null;
/**
* @deprecated Use options instead
*/
attributes?: Expression | null;
}

export interface EstreePrivateIdentifier extends NodeBase {
Expand Down
Expand Up @@ -19,9 +19,10 @@
"value": "module",
"raw": "\"module\""
},
"options": null
"options": null,
"attributes": null
}
}
]
}
}
}
Expand Up @@ -62,9 +62,53 @@
"kind": "init"
}
]
},
"attributes": {
"type": "ObjectExpression",
"start":17,"end":45,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":45}},
"properties": [
{
"type": "Property",
"start":19,"end":43,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":43}},
"method": false,
"key": {
"type": "Identifier",
"start":19,"end":25,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":25},"identifierName":"assert"},
"name": "assert"
},
"computed": false,
"shorthand": false,
"value": {
"type": "ObjectExpression",
"start":27,"end":43,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":43}},
"properties": [
{
"type": "Property",
"start":29,"end":41,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":41}},
"method": false,
"key": {
"type": "Identifier",
"start":29,"end":33,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":33},"identifierName":"type"},
"name": "type"
},
"computed": false,
"shorthand": false,
"value": {
"type": "Literal",
"start":35,"end":41,"loc":{"start":{"line":1,"column":35},"end":{"line":1,"column":41}},
"value": "json",
"raw": "\"json\""
},
"kind": "init"
}
]
},
"kind": "init"
}
]
}
}
}
]
}
}
}
Expand Up @@ -19,9 +19,10 @@
"value": "module",
"raw": "\"module\""
},
"options": null
"options": null,
"attributes": null
}
}
]
}
}
}
Expand Up @@ -62,6 +62,50 @@
"kind": "init"
}
]
},
"attributes": {
"type": "ObjectExpression",
"start":17,"end":43,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":43}},
"properties": [
{
"type": "Property",
"start":19,"end":41,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":41}},
"method": false,
"key": {
"type": "Identifier",
"start":19,"end":23,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":23},"identifierName":"with"},
"name": "with"
},
"computed": false,
"shorthand": false,
"value": {
"type": "ObjectExpression",
"start":25,"end":41,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":41}},
"properties": [
{
"type": "Property",
"start":27,"end":39,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":39}},
"method": false,
"key": {
"type": "Identifier",
"start":27,"end":31,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":31},"identifierName":"type"},
"name": "type"
},
"computed": false,
"shorthand": false,
"value": {
"type": "Literal",
"start":33,"end":39,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":39}},
"value": "json",
"raw": "\"json\""
},
"kind": "init"
}
]
},
"kind": "init"
}
]
}
}
}
Expand Down

0 comments on commit 682e32d

Please sign in to comment.