diff --git a/src/parser/expression.js b/src/parser/expression.js index 23f6875077..5d08afd31b 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -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"); diff --git a/test/fixtures/experimental/dynamic-import/invalid-arguments-spread/actual.js b/test/fixtures/experimental/dynamic-import/invalid-arguments-spread/actual.js new file mode 100644 index 0000000000..87bfc54932 --- /dev/null +++ b/test/fixtures/experimental/dynamic-import/invalid-arguments-spread/actual.js @@ -0,0 +1 @@ +import(...[1]) diff --git a/test/fixtures/experimental/dynamic-import/invalid-arguments-spread/options.json b/test/fixtures/experimental/dynamic-import/invalid-arguments-spread/options.json new file mode 100644 index 0000000000..c4e1e2ffeb --- /dev/null +++ b/test/fixtures/experimental/dynamic-import/invalid-arguments-spread/options.json @@ -0,0 +1,3 @@ +{ + "throws": "... is not allowed in import() (1:7)" +}