Disallow SpreadElement inside dynamic import (#529)

* Disallow SpreadElement inside dynamic import

* tweak error message
This commit is contained in:
Brian Ng 2017-05-17 11:07:09 -05:00 committed by Henry Zhu
parent 23ff45fcfa
commit dcef4012a0
3 changed files with 13 additions and 2 deletions

View File

@ -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");

View File

@ -0,0 +1 @@
import(...[1])

View File

@ -0,0 +1,3 @@
{
"throws": "... is not allowed in import() (1:7)"
}