From ef0722b4b2c5b25a2cd049fd479820add3f8aa62 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Sat, 23 Mar 2019 16:47:50 -0700 Subject: [PATCH] Fix compatibility between estree and TS plugin (#9700) --- .../babel-parser/src/plugins/typescript.js | 24 +- .../fixtures/estree/typescript/enum/input.js | 4 + .../estree/typescript/enum/output.json | 132 +++++ .../estree/typescript/import-require/input.js | 1 + .../typescript/import-require/options.json | 3 + .../typescript/import-require/output.json | 99 ++++ .../estree/typescript/import/input.js | 3 + .../estree/typescript/import/output.json | 441 +++++++++++++++ .../estree/typescript/literals/input.js | 7 + .../estree/typescript/literals/output.json | 516 ++++++++++++++++++ .../fixtures/estree/typescript/options.json | 3 + .../types/literal-number-negative/output.json | 29 +- 12 files changed, 1242 insertions(+), 20 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/estree/typescript/enum/input.js create mode 100644 packages/babel-parser/test/fixtures/estree/typescript/enum/output.json create mode 100644 packages/babel-parser/test/fixtures/estree/typescript/import-require/input.js create mode 100644 packages/babel-parser/test/fixtures/estree/typescript/import-require/options.json create mode 100644 packages/babel-parser/test/fixtures/estree/typescript/import-require/output.json create mode 100644 packages/babel-parser/test/fixtures/estree/typescript/import/input.js create mode 100644 packages/babel-parser/test/fixtures/estree/typescript/import/output.json create mode 100644 packages/babel-parser/test/fixtures/estree/typescript/literals/input.js create mode 100644 packages/babel-parser/test/fixtures/estree/typescript/literals/output.json create mode 100644 packages/babel-parser/test/fixtures/estree/typescript/options.json diff --git a/packages/babel-parser/src/plugins/typescript.js b/packages/babel-parser/src/plugins/typescript.js index 07c560707dc2..e53749a9e510 100644 --- a/packages/babel-parser/src/plugins/typescript.js +++ b/packages/babel-parser/src/plugins/typescript.js @@ -232,7 +232,9 @@ export default (superClass: Class): Class => "Argument in a type import must be a string literal", ); } - node.argument = this.parseLiteral(this.state.value, "StringLiteral"); + + // For compatibility to estree we cannot call parseLiteral directly here + node.argument = this.parseExprAtom(); this.expect(tt.parenR); if (this.eat(tt.dot)) { @@ -646,12 +648,11 @@ export default (superClass: Class): Class => node.literal = (() => { switch (this.state.type) { case tt.num: - return this.parseLiteral(this.state.value, "NumericLiteral"); case tt.string: - return this.parseLiteral(this.state.value, "StringLiteral"); case tt._true: case tt._false: - return this.parseBooleanLiteral(); + // For compatibility to estree we cannot call parseLiteral directly here + return this.parseExprAtom(); default: throw this.unexpected(); } @@ -684,16 +685,10 @@ export default (superClass: Class): Class => case tt.plusMin: if (this.state.value === "-") { const node: N.TsLiteralType = this.startNode(); - this.next(); - if (!this.match(tt.num)) { + if (this.lookahead().type !== tt.num) { throw this.unexpected(); } - node.literal = this.parseLiteral( - -this.state.value, - "NumericLiteral", - node.start, - node.loc.start, - ); + node.literal = this.parseMaybeUnary(); return this.finishNode(node, "TSLiteralType"); } break; @@ -1108,7 +1103,7 @@ export default (superClass: Class): Class => const node: N.TsEnumMember = this.startNode(); // Computed property names are grammar errors in an enum, so accept just string literal or identifier. node.id = this.match(tt.string) - ? this.parseLiteral(this.state.value, "StringLiteral") + ? this.parseExprAtom() : this.parseIdentifier(/* liberal */ true); if (this.eat(tt.eq)) { node.initializer = this.parseMaybeAssign(); @@ -1213,7 +1208,8 @@ export default (superClass: Class): Class => if (!this.match(tt.string)) { throw this.unexpected(); } - node.expression = this.parseLiteral(this.state.value, "StringLiteral"); + // For compatibility to estree we cannot call parseLiteral directly here + node.expression = this.parseExprAtom(); this.expect(tt.parenR); return this.finishNode(node, "TSExternalModuleReference"); } diff --git a/packages/babel-parser/test/fixtures/estree/typescript/enum/input.js b/packages/babel-parser/test/fixtures/estree/typescript/enum/input.js new file mode 100644 index 000000000000..cf0b94467025 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/enum/input.js @@ -0,0 +1,4 @@ +enum A { + a, + "r" +} diff --git a/packages/babel-parser/test/fixtures/estree/typescript/enum/output.json b/packages/babel-parser/test/fixtures/estree/typescript/enum/output.json new file mode 100644 index 000000000000..7a0e9a0cbb8d --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/enum/output.json @@ -0,0 +1,132 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "TSEnumDeclaration", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "A" + }, + "name": "A" + }, + "members": [ + { + "type": "TSEnumMember", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + } + }, + { + "type": "TSEnumMember", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "id": { + "type": "Literal", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "value": "r", + "raw": "\"r\"" + } + } + ] + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/estree/typescript/import-require/input.js b/packages/babel-parser/test/fixtures/estree/typescript/import-require/input.js new file mode 100644 index 000000000000..6801238e6ff4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/import-require/input.js @@ -0,0 +1 @@ +import x = require ("asdfasdf"); diff --git a/packages/babel-parser/test/fixtures/estree/typescript/import-require/options.json b/packages/babel-parser/test/fixtures/estree/typescript/import-require/options.json new file mode 100644 index 000000000000..2104ca43283f --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/import-require/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/estree/typescript/import-require/output.json b/packages/babel-parser/test/fixtures/estree/typescript/import-require/output.json new file mode 100644 index 000000000000..65361fdc837c --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/import-require/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSImportEqualsDeclaration", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "isExport": false, + "id": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + }, + "moduleReference": { + "type": "TSExternalModuleReference", + "start": 11, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "expression": { + "type": "Literal", + "start": 20, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "value": "asdfasdf", + "raw": "\"asdfasdf\"" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/estree/typescript/import/input.js b/packages/babel-parser/test/fixtures/estree/typescript/import/input.js new file mode 100644 index 000000000000..7bae7e8301b3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/import/input.js @@ -0,0 +1,3 @@ +let x: typeof import('./x'); +let Y: import('./y').Y; +let z: import("/z").foo.bar; diff --git a/packages/babel-parser/test/fixtures/estree/typescript/import/output.json b/packages/babel-parser/test/fixtures/estree/typescript/import/output.json new file mode 100644 index 000000000000..48ff04ded091 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/import/output.json @@ -0,0 +1,441 @@ +{ + "type": "File", + "start": 0, + "end": 89, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 89, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "x" + }, + "name": "x", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 5, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "typeAnnotation": { + "type": "TSTypeQuery", + "start": 7, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "exprName": { + "type": "TSImportType", + "start": 14, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "argument": { + "type": "Literal", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "value": "./x", + "raw": "'./x'" + } + } + } + } + }, + "init": null + } + ], + "kind": "let" + }, + { + "type": "VariableDeclaration", + "start": 29, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 33, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "id": { + "type": "Identifier", + "start": 33, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 22 + }, + "identifierName": "Y" + }, + "name": "Y", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 34, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "typeAnnotation": { + "type": "TSImportType", + "start": 36, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "argument": { + "type": "Literal", + "start": 43, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "./y", + "raw": "'./y'" + }, + "qualifier": { + "type": "Identifier", + "start": 50, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 22 + }, + "identifierName": "Y" + }, + "name": "Y" + } + } + } + }, + "init": null + } + ], + "kind": "let" + }, + { + "type": "VariableDeclaration", + "start": 53, + "end": 89, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 57, + "end": 88, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 35 + } + }, + "id": { + "type": "Identifier", + "start": 57, + "end": 88, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 35 + }, + "identifierName": "z" + }, + "name": "z", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 58, + "end": 88, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 35 + } + }, + "typeAnnotation": { + "type": "TSImportType", + "start": 60, + "end": 88, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 35 + } + }, + "argument": { + "type": "Literal", + "start": 67, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "value": "/z", + "raw": "\"/z\"" + }, + "qualifier": { + "type": "TSQualifiedName", + "start": 73, + "end": 80, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 27 + } + }, + "left": { + "type": "Identifier", + "start": 73, + "end": 76, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 23 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "right": { + "type": "Identifier", + "start": 77, + "end": 80, + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 27 + }, + "identifierName": "bar" + }, + "name": "bar" + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start": 80, + "end": 88, + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 35 + } + }, + "params": [ + { + "type": "TSStringKeyword", + "start": 81, + "end": 87, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 34 + } + } + } + ] + } + } + } + }, + "init": null + } + ], + "kind": "let" + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/estree/typescript/literals/input.js b/packages/babel-parser/test/fixtures/estree/typescript/literals/input.js new file mode 100644 index 000000000000..59171967bb32 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/literals/input.js @@ -0,0 +1,7 @@ +type Foo = false; +type Foo2 = true; +type Foo3 = "string"; +type Foo4 = 123; +type Foo4 = 123.4; +type Foo5 = -123; +type Foo5 = -123.5; diff --git a/packages/babel-parser/test/fixtures/estree/typescript/literals/output.json b/packages/babel-parser/test/fixtures/estree/typescript/literals/output.json new file mode 100644 index 000000000000..833304ea89d6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/literals/output.json @@ -0,0 +1,516 @@ +{ + "type": "File", + "start": 0, + "end": 131, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 131, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "TSTypeAliasDeclaration", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": { + "type": "Identifier", + "start": 5, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 11, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "literal": { + "type": "Literal", + "start": 11, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "value": false, + "raw": "false" + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 18, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "Foo2" + }, + "name": "Foo2" + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 30, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "literal": { + "type": "Literal", + "start": 30, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": true, + "raw": "true" + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 36, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "id": { + "type": "Identifier", + "start": 41, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 9 + }, + "identifierName": "Foo3" + }, + "name": "Foo3" + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 48, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "literal": { + "type": "Literal", + "start": 48, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "value": "string", + "raw": "\"string\"" + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 58, + "end": 74, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "id": { + "type": "Identifier", + "start": 63, + "end": 67, + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 9 + }, + "identifierName": "Foo4" + }, + "name": "Foo4" + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 70, + "end": 73, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "literal": { + "type": "Literal", + "start": 70, + "end": 73, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "value": 123, + "raw": "123" + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 75, + "end": 93, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 80, + "end": 84, + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 9 + }, + "identifierName": "Foo4" + }, + "name": "Foo4" + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 87, + "end": 92, + "loc": { + "start": { + "line": 5, + "column": 12 + }, + "end": { + "line": 5, + "column": 17 + } + }, + "literal": { + "type": "Literal", + "start": 87, + "end": 92, + "loc": { + "start": { + "line": 5, + "column": 12 + }, + "end": { + "line": 5, + "column": 17 + } + }, + "value": 123.4, + "raw": "123.4" + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 94, + "end": 111, + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "id": { + "type": "Identifier", + "start": 99, + "end": 103, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 9 + }, + "identifierName": "Foo5" + }, + "name": "Foo5" + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 106, + "end": 110, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "literal": { + "type": "UnaryExpression", + "start": 106, + "end": 110, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "operator": "-", + "prefix": true, + "argument": { + "type": "Literal", + "start": 107, + "end": 110, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "value": 123, + "raw": "123" + } + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 112, + "end": 131, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "id": { + "type": "Identifier", + "start": 117, + "end": 121, + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 9 + }, + "identifierName": "Foo5" + }, + "name": "Foo5" + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 124, + "end": 130, + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "literal": { + "type": "UnaryExpression", + "start": 124, + "end": 130, + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "operator": "-", + "prefix": true, + "argument": { + "type": "Literal", + "start": 125, + "end": 130, + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "value": 123.5, + "raw": "123.5" + } + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/estree/typescript/options.json b/packages/babel-parser/test/fixtures/estree/typescript/options.json new file mode 100644 index 000000000000..d69381825ce5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["typescript", "estree"] +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/literal-number-negative/output.json b/packages/babel-parser/test/fixtures/typescript/types/literal-number-negative/output.json index c6b4a8b0384b..70e16143508f 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/literal-number-negative/output.json +++ b/packages/babel-parser/test/fixtures/typescript/types/literal-number-negative/output.json @@ -103,7 +103,7 @@ } }, "literal": { - "type": "NumericLiteral", + "type": "UnaryExpression", "start": 7, "end": 9, "loc": { @@ -116,11 +116,28 @@ "column": 9 } }, - "extra": { - "rawValue": -1, - "raw": "-1" - }, - "value": -1 + "operator": "-", + "prefix": true, + "argument": { + "type": "NumericLiteral", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } } } }