added basic support for module attributes and tests updated (#10962)

Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
Vivek Nayyar
2020-05-25 01:26:28 +02:00
committed by GitHub
parent c5ba345ac2
commit 66b86e088c
66 changed files with 1231 additions and 184 deletions

View File

@@ -765,12 +765,22 @@ export default class ExpressionParser extends LValParser {
optional: boolean,
): N.Expression {
if (node.callee.type === "Import") {
if (node.arguments.length !== 1) {
this.raise(node.start, Errors.ImportCallArity);
if (node.arguments.length === 2) {
this.expectPlugin("moduleAttributes");
}
if (node.arguments.length === 0 || node.arguments.length > 2) {
this.raise(
node.start,
Errors.ImportCallArity,
this.hasPlugin("moduleAttributes")
? "one or two arguments"
: "one argument",
);
} else {
const importArg = node.arguments[0];
if (importArg?.type === "SpreadElement") {
this.raise(importArg.start, Errors.ImportCallSpreadArgument);
for (const arg of node.arguments) {
if (arg.type === "SpreadElement") {
this.raise(arg.start, Errors.ImportCallSpreadArgument);
}
}
}
}
@@ -799,7 +809,7 @@ export default class ExpressionParser extends LValParser {
} else {
this.expect(tt.comma);
if (this.match(close)) {
if (dynamicImport) {
if (dynamicImport && !this.hasPlugin("moduleAttributes")) {
this.raise(
this.state.lastTokStart,
Errors.ImportCallArgumentTrailingComma,