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

Commit

Permalink
Disallow SpreadElement inside dynamic import (#529)
Browse files Browse the repository at this point in the history
* Disallow SpreadElement inside dynamic import

* tweak error message
  • Loading branch information
existentialism authored and hzoo committed May 17, 2017
1 parent 23ff45f commit dcef401
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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") {
this.raise(importArg.start, "... 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": "... is not allowed in import() (1:7)"
}

0 comments on commit dcef401

Please sign in to comment.