Relax import assertion key-is-type constraint (#13409)
This commit is contained in:
parent
b281fe352c
commit
b8175ec060
@ -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,
|
||||
|
||||
@ -0,0 +1,2 @@
|
||||
import "foo"
|
||||
assert { type: "json" }
|
||||
@ -0,0 +1,69 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":36,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":23}},
|
||||
"errors": [
|
||||
"SyntaxError: Missing semicolon. (2:6)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":36,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":23}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ImportDeclaration",
|
||||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
|
||||
"specifiers": [],
|
||||
"source": {
|
||||
"type": "StringLiteral",
|
||||
"start":7,"end":12,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":12}},
|
||||
"extra": {
|
||||
"rawValue": "foo",
|
||||
"raw": "\"foo\""
|
||||
},
|
||||
"value": "foo"
|
||||
},
|
||||
"assertions": []
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":13,"end":19,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":6}},
|
||||
"expression": {
|
||||
"type": "Identifier",
|
||||
"start":13,"end":19,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":6},"identifierName":"assert"},
|
||||
"name": "assert"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "BlockStatement",
|
||||
"start":20,"end":36,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":23}},
|
||||
"body": [
|
||||
{
|
||||
"type": "LabeledStatement",
|
||||
"start":22,"end":34,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":21}},
|
||||
"body": {
|
||||
"type": "ExpressionStatement",
|
||||
"start":28,"end":34,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":21}},
|
||||
"expression": {
|
||||
"type": "StringLiteral",
|
||||
"start":28,"end":34,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":21}},
|
||||
"extra": {
|
||||
"rawValue": "json",
|
||||
"raw": "\"json\""
|
||||
},
|
||||
"value": "json"
|
||||
}
|
||||
},
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"start":22,"end":26,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":13},"identifierName":"type"},
|
||||
"name": "type"
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,6 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":101,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":52}},
|
||||
"errors": [
|
||||
"SyntaxError: The only accepted module attribute is `type`. (1:36)",
|
||||
"SyntaxError: The only accepted module attribute is `type`. (2:40)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":101,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":52}},
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":55,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":55}},
|
||||
"errors": [
|
||||
"SyntaxError: The only accepted module attribute is `type`. (1:40)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":55,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":55}},
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":79,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":79}},
|
||||
"errors": [
|
||||
"SyntaxError: The only accepted module attribute is `type`. (1:54)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":79,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":79}},
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":51,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":51}},
|
||||
"errors": [
|
||||
"SyntaxError: The only accepted module attribute is `type`. (1:36)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":51,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":51}},
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":75,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":75}},
|
||||
"errors": [
|
||||
"SyntaxError: The only accepted module attribute is `type`. (1:50)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":75,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":75}},
|
||||
|
||||
@ -1,16 +1 @@
|
||||
language/module-code/import-assertion-key-identifiername.js(default)
|
||||
language/module-code/import-assertion-key-identifiername.js(strict mode)
|
||||
language/module-code/import-assertion-key-string-double.js(default)
|
||||
language/module-code/import-assertion-key-string-double.js(strict mode)
|
||||
language/module-code/import-assertion-key-string-single.js(default)
|
||||
language/module-code/import-assertion-key-string-single.js(strict mode)
|
||||
language/module-code/import-assertion-many.js(default)
|
||||
language/module-code/import-assertion-many.js(strict mode)
|
||||
language/module-code/import-assertion-newlines.js(default)
|
||||
language/module-code/import-assertion-newlines.js(strict mode)
|
||||
language/module-code/import-assertion-trlng-comma.js(default)
|
||||
language/module-code/import-assertion-trlng-comma.js(strict mode)
|
||||
language/module-code/import-assertion-value-string-double.js(default)
|
||||
language/module-code/import-assertion-value-string-double.js(strict mode)
|
||||
language/module-code/import-assertion-value-string-single.js(default)
|
||||
language/module-code/import-assertion-value-string-single.js(strict mode)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user