Relax import assertion key-is-type constraint (#13409)
This commit is contained in:
@@ -2255,6 +2255,17 @@ export default class StatementParser extends ExpressionParser {
|
||||
|
||||
// parse AssertionKey : IdentifierName, StringLiteral
|
||||
const keyName = this.state.value;
|
||||
// check if we already have an entry for an attribute
|
||||
// if a duplicate entry is found, throw an error
|
||||
// for now this logic will come into play only when someone declares `type` twice
|
||||
if (attrNames.has(keyName)) {
|
||||
this.raise(
|
||||
this.state.start,
|
||||
Errors.ModuleAttributesWithDuplicateKeys,
|
||||
keyName,
|
||||
);
|
||||
}
|
||||
attrNames.add(keyName);
|
||||
if (this.match(tt.string)) {
|
||||
node.key = this.parseStringLiteral(keyName);
|
||||
} else {
|
||||
@@ -2262,26 +2273,6 @@ export default class StatementParser extends ExpressionParser {
|
||||
}
|
||||
this.expect(tt.colon);
|
||||
|
||||
// for now we are only allowing `type` as the only allowed module attribute
|
||||
if (keyName !== "type") {
|
||||
this.raise(
|
||||
node.key.start,
|
||||
Errors.ModuleAttributeDifferentFromType,
|
||||
keyName,
|
||||
);
|
||||
}
|
||||
// check if we already have an entry for an attribute
|
||||
// if a duplicate entry is found, throw an error
|
||||
// for now this logic will come into play only when someone declares `type` twice
|
||||
if (attrNames.has(keyName)) {
|
||||
this.raise(
|
||||
node.key.start,
|
||||
Errors.ModuleAttributesWithDuplicateKeys,
|
||||
keyName,
|
||||
);
|
||||
}
|
||||
attrNames.add(keyName);
|
||||
|
||||
if (!this.match(tt.string)) {
|
||||
throw this.unexpected(
|
||||
this.state.start,
|
||||
|
||||
Reference in New Issue
Block a user