Enable import.meta by default in @babel/parser (#11406)
This commit is contained in:
parent
75a6530abe
commit
5dd7f438c9
@ -1227,8 +1227,6 @@ export default class ExpressionParser extends LValParser {
|
||||
this.expect(tt.dot);
|
||||
|
||||
if (this.isContextual("meta")) {
|
||||
this.expectPlugin("importMeta");
|
||||
|
||||
if (!this.inModule) {
|
||||
this.raiseWithData(
|
||||
id.start,
|
||||
@ -1237,8 +1235,6 @@ export default class ExpressionParser extends LValParser {
|
||||
);
|
||||
}
|
||||
this.sawUnambiguousESM = true;
|
||||
} else if (!this.hasPlugin("importMeta")) {
|
||||
this.raise(id.start, Errors.ImportCallArityLtOne);
|
||||
}
|
||||
|
||||
return this.parseMetaProperty(node, id, "meta");
|
||||
|
||||
@ -68,7 +68,6 @@ export const Errors = Object.freeze({
|
||||
ImportCallArgumentTrailingComma:
|
||||
"Trailing comma is disallowed inside import(...) arguments",
|
||||
ImportCallArity: "import() requires exactly one argument",
|
||||
ImportCallArityLtOne: "Dynamic imports require a parameter: import('a.js')",
|
||||
ImportCallNotNewExpression: "Cannot use new with import(...)",
|
||||
ImportCallSpreadArgument: "... is not allowed in import()",
|
||||
ImportMetaOutsideModule: `import.meta may appear only with 'sourceType: "module"'`,
|
||||
|
||||
@ -49,4 +49,4 @@
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
"type": "File",
|
||||
"start":0,"end":49,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: Dynamic imports require a parameter: import('a.js') (2:9)",
|
||||
"SyntaxError: The only valid meta property for import is import.meta (2:16)"
|
||||
],
|
||||
"program": {
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
{
|
||||
"plugins": ["importMeta"],
|
||||
"sourceType": "script"
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/es2020/import-meta/no-other-prop-names/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2020/import-meta/no-other-prop-names/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"sourceType": "module"
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/es2020/import-meta/not-assignable/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2020/import-meta/not-assignable/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"sourceType": "module"
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/es2020/import-meta/valid-in-module/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2020/import-meta/valid-in-module/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"sourceType": "module"
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"throws": "This experimental syntax requires enabling the parser plugin: 'importMeta' (1:17)",
|
||||
"sourceType": "module",
|
||||
"plugins": []
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
const x = import.meta;
|
||||
@ -1,4 +0,0 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": ["importMeta"]
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": ["importMeta"]
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": ["importMeta"]
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
const x = import.meta;
|
||||
const url = import.meta.url;
|
||||
import.meta;
|
||||
import.meta.url;
|
||||
import.meta.couldBeMutable = true;
|
||||
@ -1,4 +0,0 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": ["importMeta"]
|
||||
}
|
||||
@ -1,167 +0,0 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":116,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":34}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":116,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":34}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "VariableDeclaration",
|
||||
"start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}},
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"start":6,"end":21,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":21}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"x"},
|
||||
"name": "x"
|
||||
},
|
||||
"init": {
|
||||
"type": "MetaProperty",
|
||||
"start":10,"end":21,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":21}},
|
||||
"meta": {
|
||||
"type": "Identifier",
|
||||
"start":10,"end":16,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":16},"identifierName":"import"},
|
||||
"name": "import"
|
||||
},
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":17,"end":21,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":21},"identifierName":"meta"},
|
||||
"name": "meta"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"kind": "const"
|
||||
},
|
||||
{
|
||||
"type": "VariableDeclaration",
|
||||
"start":23,"end":51,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":28}},
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"start":29,"end":50,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":27}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":29,"end":32,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":9},"identifierName":"url"},
|
||||
"name": "url"
|
||||
},
|
||||
"init": {
|
||||
"type": "MemberExpression",
|
||||
"start":35,"end":50,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":27}},
|
||||
"object": {
|
||||
"type": "MetaProperty",
|
||||
"start":35,"end":46,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":23}},
|
||||
"meta": {
|
||||
"type": "Identifier",
|
||||
"start":35,"end":41,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":18},"identifierName":"import"},
|
||||
"name": "import"
|
||||
},
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":42,"end":46,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":23},"identifierName":"meta"},
|
||||
"name": "meta"
|
||||
}
|
||||
},
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":47,"end":50,"loc":{"start":{"line":2,"column":24},"end":{"line":2,"column":27},"identifierName":"url"},
|
||||
"name": "url"
|
||||
},
|
||||
"computed": false
|
||||
}
|
||||
}
|
||||
],
|
||||
"kind": "const"
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":52,"end":64,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":12}},
|
||||
"expression": {
|
||||
"type": "MetaProperty",
|
||||
"start":52,"end":63,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":11}},
|
||||
"meta": {
|
||||
"type": "Identifier",
|
||||
"start":52,"end":58,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":6},"identifierName":"import"},
|
||||
"name": "import"
|
||||
},
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":59,"end":63,"loc":{"start":{"line":3,"column":7},"end":{"line":3,"column":11},"identifierName":"meta"},
|
||||
"name": "meta"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":65,"end":81,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":16}},
|
||||
"expression": {
|
||||
"type": "MemberExpression",
|
||||
"start":65,"end":80,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":15}},
|
||||
"object": {
|
||||
"type": "MetaProperty",
|
||||
"start":65,"end":76,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":11}},
|
||||
"meta": {
|
||||
"type": "Identifier",
|
||||
"start":65,"end":71,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":6},"identifierName":"import"},
|
||||
"name": "import"
|
||||
},
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":72,"end":76,"loc":{"start":{"line":4,"column":7},"end":{"line":4,"column":11},"identifierName":"meta"},
|
||||
"name": "meta"
|
||||
}
|
||||
},
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":77,"end":80,"loc":{"start":{"line":4,"column":12},"end":{"line":4,"column":15},"identifierName":"url"},
|
||||
"name": "url"
|
||||
},
|
||||
"computed": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":82,"end":116,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":34}},
|
||||
"expression": {
|
||||
"type": "AssignmentExpression",
|
||||
"start":82,"end":115,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":33}},
|
||||
"operator": "=",
|
||||
"left": {
|
||||
"type": "MemberExpression",
|
||||
"start":82,"end":108,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":26}},
|
||||
"object": {
|
||||
"type": "MetaProperty",
|
||||
"start":82,"end":93,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":11}},
|
||||
"meta": {
|
||||
"type": "Identifier",
|
||||
"start":82,"end":88,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":6},"identifierName":"import"},
|
||||
"name": "import"
|
||||
},
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":89,"end":93,"loc":{"start":{"line":5,"column":7},"end":{"line":5,"column":11},"identifierName":"meta"},
|
||||
"name": "meta"
|
||||
}
|
||||
},
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":94,"end":108,"loc":{"start":{"line":5,"column":12},"end":{"line":5,"column":26},"identifierName":"couldBeMutable"},
|
||||
"name": "couldBeMutable"
|
||||
},
|
||||
"computed": false
|
||||
},
|
||||
"right": {
|
||||
"type": "BooleanLiteral",
|
||||
"start":111,"end":115,"loc":{"start":{"line":5,"column":29},"end":{"line":5,"column":33}},
|
||||
"value": true
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
import.meta;
|
||||
@ -1,4 +0,0 @@
|
||||
{
|
||||
"throws": "This experimental syntax requires enabling the parser plugin: 'importMeta' (1:7)",
|
||||
"plugins": []
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user