Parse import-assertions (#12139)
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com> Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
@@ -829,13 +829,18 @@ export default class ExpressionParser extends LValParser {
|
||||
): N.Expression {
|
||||
if (node.callee.type === "Import") {
|
||||
if (node.arguments.length === 2) {
|
||||
this.expectPlugin("moduleAttributes");
|
||||
// todo(Babel 8): remove the if condition,
|
||||
// moduleAttributes is renamed to importAssertions
|
||||
if (!this.hasPlugin("moduleAttributes")) {
|
||||
this.expectPlugin("importAssertions");
|
||||
}
|
||||
}
|
||||
if (node.arguments.length === 0 || node.arguments.length > 2) {
|
||||
this.raise(
|
||||
node.start,
|
||||
Errors.ImportCallArity,
|
||||
this.hasPlugin("moduleAttributes")
|
||||
this.hasPlugin("importAssertions") ||
|
||||
this.hasPlugin("moduleAttributes")
|
||||
? "one or two arguments"
|
||||
: "one argument",
|
||||
);
|
||||
@@ -872,7 +877,11 @@ export default class ExpressionParser extends LValParser {
|
||||
} else {
|
||||
this.expect(tt.comma);
|
||||
if (this.match(close)) {
|
||||
if (dynamicImport && !this.hasPlugin("moduleAttributes")) {
|
||||
if (
|
||||
dynamicImport &&
|
||||
!this.hasPlugin("importAssertions") &&
|
||||
!this.hasPlugin("moduleAttributes")
|
||||
) {
|
||||
this.raise(
|
||||
this.state.lastTokStart,
|
||||
Errors.ImportCallArgumentTrailingComma,
|
||||
|
||||
Reference in New Issue
Block a user