diff --git a/README.md b/README.md index c2b511d2e8..e11a0c4cde 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ require("babylon").parse("code", { - `dynamicImport` ([proposal](https://github.com/tc39/proposal-dynamic-import)) - `numericSeparator` ([proposal](https://github.com/samuelgoto/proposal-numeric-separator)) - `optionalChaining` ([proposal](https://github.com/tc39/proposal-optional-chaining)) + - `importMeta` ([proposal](https://github.com/tc39/proposal-import-meta)) ### FAQ diff --git a/package.json b/package.json index 56928ae0c1..64c9cc0654 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "babylon", - "version": "7.0.0-beta.11", + "version": "7.0.0-beta.12", "description": "A JavaScript parser", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", diff --git a/src/parser/expression.js b/src/parser/expression.js index 51ce2ee690..0941a6b587 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -459,6 +459,10 @@ export default class ExpressionParser extends LValParser { return this.finishNode(node, "Super"); case tt._import: + if (this.hasPlugin("importMeta") && this.lookahead().type === tt.dot) { + return this.parseImportMetaProperty(); + } + if (!this.hasPlugin("dynamicImport")) this.unexpected(); node = this.startNode(); @@ -620,12 +624,22 @@ export default class ExpressionParser extends LValParser { node.property = this.parseIdentifier(true); if (node.property.name !== propertyName) { - this.raise(node.property.start, `The only valid meta property for new is ${meta.name}.${propertyName}`); + this.raise(node.property.start, `The only valid meta property for ${meta.name} is ${meta.name}.${propertyName}`); } return this.finishNode(node, "MetaProperty"); } + parseImportMetaProperty(): N.MetaProperty { + const node = this.startNode(); + const id = this.parseIdentifier(true); + this.expect(tt.dot); + if (!this.inModule) { + this.raise(id.start, "import.meta may appear only with 'sourceType: module'"); + } + return this.parseMetaProperty(node, id, "meta"); + } + parseLiteral(value: any, type: /*T["kind"]*/string, startPos?: number, startLoc?: Position): T { startPos = startPos || this.state.start; startLoc = startLoc || this.state.startLoc; diff --git a/src/parser/statement.js b/src/parser/statement.js index 080b3a0e02..012066d822 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -106,7 +106,8 @@ export default class StatementParser extends ExpressionParser { case tt.semi: return this.parseEmptyStatement(node); case tt._export: case tt._import: - if (this.hasPlugin("dynamicImport") && this.lookahead().type === tt.parenL) break; + if ((this.hasPlugin("dynamicImport") && this.lookahead().type === tt.parenL) || + (this.hasPlugin("importMeta") && this.lookahead().type === tt.dot)) break; if (!this.options.allowImportExportEverywhere) { if (!topLevel) { diff --git a/src/tokenizer/index.js b/src/tokenizer/index.js index acc145de03..538597df3a 100644 --- a/src/tokenizer/index.js +++ b/src/tokenizer/index.js @@ -17,18 +17,24 @@ import State from "./state"; // The following character codes are forbidden from being // an immediate sibling of NumericLiteralSeparator _ -const forbiddenNumericLiteralSeparatorSiblings = [ - 46, // . - 66, // B - 69, // E - 79, // O - 88, // X - 95, // _ (multiple separators are not allowed) - 98, // b - 101, // e - 111, // o - 120, // x -]; +const forbiddenNumericSeparatorSiblings = { + decBinOct: [ + 46, // . + 66, // B + 69, // E + 79, // O + 95, // _ (multiple separators are not allowed) + 98, // b + 101, // e + 111, // o + ], + hex: [ + 46, // . + 88, // X + 95, // _ (multiple separators are not allowed) + 120, // x + ], +}; // Object type used to represent tokens. Note that normally, tokens // simply exist as properties on the parser object. This is only @@ -579,6 +585,9 @@ export default class Tokenizer extends LocationParser { readInt(radix: number, len?: number): number | null { const start = this.state.pos; + const forbiddenSiblings = radix === 16 ? + forbiddenNumericSeparatorSiblings.hex : + forbiddenNumericSeparatorSiblings.decBinOct; let total = 0; for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) { @@ -589,8 +598,8 @@ export default class Tokenizer extends LocationParser { const prev = this.input.charCodeAt(this.state.pos - 1); const next = this.input.charCodeAt(this.state.pos + 1); if (code === 95) { - if ((forbiddenNumericLiteralSeparatorSiblings.indexOf(prev) > -1) || - (forbiddenNumericLiteralSeparatorSiblings.indexOf(next) > -1) || + if ((forbiddenSiblings.indexOf(prev) > -1) || + (forbiddenSiblings.indexOf(next) > -1) || Number.isNaN(next)) { this.raise(this.state.pos, "Invalid NumericLiteralSeparator"); } diff --git a/test/fixtures/experimental/import-meta/error-in-script/actual.js b/test/fixtures/experimental/import-meta/error-in-script/actual.js new file mode 100644 index 0000000000..e1cfc5468e --- /dev/null +++ b/test/fixtures/experimental/import-meta/error-in-script/actual.js @@ -0,0 +1 @@ +const x = import.meta; diff --git a/test/fixtures/experimental/import-meta/error-in-script/options.json b/test/fixtures/experimental/import-meta/error-in-script/options.json new file mode 100644 index 0000000000..8fc6ce37a5 --- /dev/null +++ b/test/fixtures/experimental/import-meta/error-in-script/options.json @@ -0,0 +1,5 @@ +{ + "throws": "import.meta may appear only with 'sourceType: module' (1:10)", + "plugins": ["dynamicImport", "importMeta"], + "sourceType": "script" +} diff --git a/test/fixtures/experimental/import-meta/no-other-prop-names/actual.js b/test/fixtures/experimental/import-meta/no-other-prop-names/actual.js new file mode 100644 index 0000000000..cfa01aa85e --- /dev/null +++ b/test/fixtures/experimental/import-meta/no-other-prop-names/actual.js @@ -0,0 +1 @@ +import.notMeta; diff --git a/test/fixtures/experimental/import-meta/no-other-prop-names/options.json b/test/fixtures/experimental/import-meta/no-other-prop-names/options.json new file mode 100644 index 0000000000..97ba83ec46 --- /dev/null +++ b/test/fixtures/experimental/import-meta/no-other-prop-names/options.json @@ -0,0 +1,5 @@ +{ + "throws": "The only valid meta property for import is import.meta (1:7)", + "sourceType": "module", + "plugins": ["dynamicImport", "importMeta"] +} diff --git a/test/fixtures/experimental/import-meta/not-assignable/actual.js b/test/fixtures/experimental/import-meta/not-assignable/actual.js new file mode 100644 index 0000000000..d1f20b1c0a --- /dev/null +++ b/test/fixtures/experimental/import-meta/not-assignable/actual.js @@ -0,0 +1 @@ +import.meta = true; diff --git a/test/fixtures/experimental/import-meta/not-assignable/options.json b/test/fixtures/experimental/import-meta/not-assignable/options.json new file mode 100644 index 0000000000..647ad9f65d --- /dev/null +++ b/test/fixtures/experimental/import-meta/not-assignable/options.json @@ -0,0 +1,5 @@ +{ + "throws": "Invalid left-hand side in assignment expression (1:0)", + "sourceType": "module", + "plugins": ["dynamicImport", "importMeta"] +} diff --git a/test/fixtures/experimental/import-meta/valid-in-module/actual.js b/test/fixtures/experimental/import-meta/valid-in-module/actual.js new file mode 100644 index 0000000000..fd4422fc6f --- /dev/null +++ b/test/fixtures/experimental/import-meta/valid-in-module/actual.js @@ -0,0 +1,5 @@ +const x = import.meta; +const url = import.meta.url; +import.meta; +import.meta.url; +import.meta.couldBeMutable = true; diff --git a/test/fixtures/experimental/import-meta/valid-in-module/expected.json b/test/fixtures/experimental/import-meta/valid-in-module/expected.json new file mode 100644 index 0000000000..dc33442309 --- /dev/null +++ b/test/fixtures/experimental/import-meta/valid-in-module/expected.json @@ -0,0 +1,555 @@ +{ + "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", + "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": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/import-meta/valid-in-module/options.json b/test/fixtures/experimental/import-meta/valid-in-module/options.json new file mode 100644 index 0000000000..be1070ffed --- /dev/null +++ b/test/fixtures/experimental/import-meta/valid-in-module/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "plugins": ["dynamicImport", "importMeta"] +} diff --git a/test/fixtures/experimental/import-meta/without-dynamic-import/actual.js b/test/fixtures/experimental/import-meta/without-dynamic-import/actual.js new file mode 100644 index 0000000000..fd4422fc6f --- /dev/null +++ b/test/fixtures/experimental/import-meta/without-dynamic-import/actual.js @@ -0,0 +1,5 @@ +const x = import.meta; +const url = import.meta.url; +import.meta; +import.meta.url; +import.meta.couldBeMutable = true; diff --git a/test/fixtures/experimental/import-meta/without-dynamic-import/expected.json b/test/fixtures/experimental/import-meta/without-dynamic-import/expected.json new file mode 100644 index 0000000000..dc33442309 --- /dev/null +++ b/test/fixtures/experimental/import-meta/without-dynamic-import/expected.json @@ -0,0 +1,555 @@ +{ + "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", + "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": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/import-meta/without-dynamic-import/options.json b/test/fixtures/experimental/import-meta/without-dynamic-import/options.json new file mode 100644 index 0000000000..a6638b6528 --- /dev/null +++ b/test/fixtures/experimental/import-meta/without-dynamic-import/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "plugins": ["importMeta"] +} diff --git a/test/fixtures/experimental/numeric-literal-separator/identifier-start-0/actual.js b/test/fixtures/experimental/numeric-literal-separator/identifier-start-0/actual.js new file mode 100644 index 0000000000..adc9bff555 --- /dev/null +++ b/test/fixtures/experimental/numeric-literal-separator/identifier-start-0/actual.js @@ -0,0 +1 @@ +_123 diff --git a/test/fixtures/experimental/numeric-literal-separator/identifier-start-0/expected.json b/test/fixtures/experimental/numeric-literal-separator/identifier-start-0/expected.json new file mode 100644 index 0000000000..70cf57a548 --- /dev/null +++ b/test/fixtures/experimental/numeric-literal-separator/identifier-start-0/expected.json @@ -0,0 +1,66 @@ +{ + "type": "File", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "Identifier", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "_123" + }, + "name": "_123" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/numeric-literal-separator/valid-12/actual.js b/test/fixtures/experimental/numeric-literal-separator/valid-12/actual.js new file mode 100644 index 0000000000..4115d0bd97 --- /dev/null +++ b/test/fixtures/experimental/numeric-literal-separator/valid-12/actual.js @@ -0,0 +1 @@ +0xBE_be_EB_eb; diff --git a/test/fixtures/experimental/numeric-literal-separator/valid-12/expected.json b/test/fixtures/experimental/numeric-literal-separator/valid-12/expected.json new file mode 100644 index 0000000000..8719155cde --- /dev/null +++ b/test/fixtures/experimental/numeric-literal-separator/valid-12/expected.json @@ -0,0 +1,69 @@ +{ + "type": "File", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "extra": { + "rawValue": 3200183275, + "raw": "0xBE_be_EB_eb" + }, + "value": 3200183275 + } + } + ], + "directives": [] + } +} \ No newline at end of file