Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Disallow SpreadElement inside dynamic import #529

Merged
merged 2 commits into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,15 @@ export default class ExpressionParser extends LValParser {
const node = this.startNodeAt(startPos, startLoc);
node.callee = base;
node.arguments = this.parseCallExpressionArguments(tt.parenR, possibleAsync);
if (node.callee.type === "Import" && node.arguments.length !== 1) {
this.raise(node.start, "import() requires exactly one argument");
if (node.callee.type === "Import") {
if (node.arguments.length !== 1) {
this.raise(node.start, "import() requires exactly one argument");
}

const importArg = node.arguments[0];
if (importArg && importArg.type === "SpreadElement") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use ... instead of SpreadElement and tt.ellipsis

this.raise(importArg.start, "SpreadElement is not allowed in import()");
}
}
base = this.finishNode(node, "CallExpression");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import(...[1])
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "SpreadElement is not allowed in import() (1:7)"
}