Skip to content

Commit

Permalink
fix: allow new (import(foo))
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jun 26, 2023
1 parent 9cb963f commit 4050d88
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/babel-parser/src/parser/expression.ts
Expand Up @@ -1935,9 +1935,13 @@ export default abstract class ExpressionParser extends LValParser {
}

parseNewCallee(this: Parser, node: Undone<N.NewExpression>): void {
const isImport = this.match(tt._import);
const callee = this.parseNoCallExpr();
node.callee = callee;
if (callee.type === "Import" || callee.type === "ImportExpression") {
if (
isImport &&
(callee.type === "Import" || callee.type === "ImportExpression")
) {
this.raise(Errors.ImportCallNotNewExpression, { at: callee });
}
}
Expand Down
@@ -0,0 +1 @@
new (import("foo"));
@@ -0,0 +1,45 @@
{
"type": "File",
"start":0,"end":20,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":20,"index":20}},
"program": {
"type": "Program",
"start":0,"end":20,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":20,"index":20}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":20,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":20,"index":20}},
"expression": {
"type": "NewExpression",
"start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":19,"index":19}},
"callee": {
"type": "CallExpression",
"start":5,"end":18,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":18,"index":18}},
"callee": {
"type": "Import",
"start":5,"end":11,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":11,"index":11}}
},
"arguments": [
{
"type": "StringLiteral",
"start":12,"end":17,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":17,"index":17}},
"extra": {
"rawValue": "foo",
"raw": "\"foo\""
},
"value": "foo"
}
],
"extra": {
"parenthesized": true,
"parenStart": 4
}
},
"arguments": []
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
new (import("foo"));
@@ -0,0 +1,39 @@
{
"type": "File",
"start":0,"end":20,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":20,"index":20}},
"program": {
"type": "Program",
"start":0,"end":20,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":20,"index":20}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":20,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":20,"index":20}},
"expression": {
"type": "NewExpression",
"start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":19,"index":19}},
"callee": {
"type": "ImportExpression",
"start":5,"end":18,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":18,"index":18}},
"source": {
"type": "StringLiteral",
"start":12,"end":17,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":17,"index":17}},
"extra": {
"rawValue": "foo",
"raw": "\"foo\""
},
"value": "foo"
},
"extra": {
"parenthesized": true,
"parenStart": 4
}
},
"arguments": []
}
}
],
"directives": []
}
}

0 comments on commit 4050d88

Please sign in to comment.