Relax import assertion key-is-type constraint (#13409)

This commit is contained in:
Huáng Jùnliàng
2021-06-02 07:51:56 -04:00
committed by GitHub
parent b281fe352c
commit b8175ec060
13 changed files with 83 additions and 52 deletions

View File

@@ -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,