diff --git a/packages/babel-generator/src/generators/typescript.ts b/packages/babel-generator/src/generators/typescript.ts index 5b2c572d6971..c4f0c847dc0c 100644 --- a/packages/babel-generator/src/generators/typescript.ts +++ b/packages/babel-generator/src/generators/typescript.ts @@ -21,7 +21,11 @@ export function TSTypeParameterInstantiation( export { TSTypeParameterInstantiation as TSTypeParameterDeclaration }; export function TSTypeParameter(this: Printer, node: t.TSTypeParameter) { - this.word(node.name); + this.word( + !process.env.BABEL_8_BREAKING + ? (node.name as unknown as string) + : (node.name as unknown as t.Identifier).name, + ); if (node.constraint) { this.space(); @@ -387,7 +391,11 @@ export function TSMappedType(this: Printer, node: t.TSMappedType) { } this.token("["); - this.word(typeParameter.name); + this.word( + !process.env.BABEL_8_BREAKING + ? (typeParameter.name as unknown as string) + : (typeParameter.name as unknown as t.Identifier).name, + ); this.space(); this.word("in"); this.space(); diff --git a/packages/babel-generator/test/index.js b/packages/babel-generator/test/index.js index 3595900bb9dd..d07a4ce531fa 100644 --- a/packages/babel-generator/test/index.js +++ b/packages/babel-generator/test/index.js @@ -342,7 +342,13 @@ describe("generation", function () { it("wraps around infer inside an array type", () => { const type = t.tsArrayType( - t.tsInferType(t.tsTypeParameter(null, null, "T")), + t.tsInferType( + t.tsTypeParameter( + null, + null, + !process.env.BABEL_8_BREAKING ? "T" : t.identifier("T"), + ), + ), ); const output = generate(type).code; diff --git a/packages/babel-parser/src/plugins/typescript/index.js b/packages/babel-parser/src/plugins/typescript/index.js index a1f78c42955c..99cc2b1deb0d 100644 --- a/packages/babel-parser/src/plugins/typescript/index.js +++ b/packages/babel-parser/src/plugins/typescript/index.js @@ -485,7 +485,7 @@ export default (superClass: Class): Class => tsParseTypeParameter(): N.TsTypeParameter { const node: N.TsTypeParameter = this.startNode(); - node.name = this.parseIdentifierName(node.start); + node.name = this.tsParseTypeParameterName(); node.constraint = this.tsEatThenParseType(tt._extends); node.default = this.tsEatThenParseType(tt.eq); return this.finishNode(node, "TSTypeParameter"); @@ -777,7 +777,7 @@ export default (superClass: Class): Class => tsParseMappedTypeParameter(): N.TsTypeParameter { const node: N.TsTypeParameter = this.startNode(); - node.name = this.parseIdentifierName(node.start); + node.name = this.tsParseTypeParameterName(); node.constraint = this.tsExpectThenParseType(tt._in); return this.finishNode(node, "TSTypeParameter"); } @@ -1091,7 +1091,7 @@ export default (superClass: Class): Class => const node = this.startNode(); this.expectContextual("infer"); const typeParameter = this.startNode(); - typeParameter.name = this.parseIdentifierName(typeParameter.start); + typeParameter.name = this.tsParseTypeParameterName(); node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter"); return this.finishNode(node, "TSInferType"); } @@ -3191,6 +3191,11 @@ export default (superClass: Class): Class => return method; } + tsParseTypeParameterName(): N.Identifier | string { + const typeName: N.Identifier = this.parseIdentifier(); + return process.env.BABEL_8_BREAKING ? typeName : typeName.name; + } + shouldParseAsAmbientContext(): boolean { return !!this.getPluginOption("typescript", "dts"); } diff --git a/packages/babel-parser/src/types.js b/packages/babel-parser/src/types.js index 5001f7e1101c..4294833d510f 100644 --- a/packages/babel-parser/src/types.js +++ b/packages/babel-parser/src/types.js @@ -960,7 +960,7 @@ export type TsTypeAnnotation = NodeBase & { }; export type TypeParameterDeclarationBase = NodeBase & { - params: $ReadOnlyArray, + params: $ReadOnlyArray, }; export type TypeParameterDeclaration = TypeParameterDeclarationBase & { @@ -973,17 +973,16 @@ export type TsTypeParameterDeclaration = TypeParameterDeclarationBase & { params: $ReadOnlyArray, }; -export type TypeParameterBase = NodeBase & { - name: string, -}; - -export type TypeParameter = TypeParameterBase & { +export type TypeParameter = NodeBase & { type: "TypeParameter", + name: string, default?: TypeAnnotation, }; -export type TsTypeParameter = TypeParameterBase & { +export type TsTypeParameter = NodeBase & { type: "TSTypeParameter", + // TODO(Babel-8): remove string type support + name: string | Identifier, constraint?: TsType, default?: TsType, }; diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow-babel-7/input.js b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow-babel-7/input.js new file mode 100644 index 000000000000..2791c2c7a3a0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow-babel-7/input.js @@ -0,0 +1 @@ +
() => {} diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow-babel-7/options.json b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow-babel-7/options.json new file mode 100644 index 000000000000..6e3b1ab5fe1a --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow-babel-7/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["typescript"], + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow-babel-7/output.json b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow-babel-7/output.json new file mode 100644 index 000000000000..d1ca421c201b --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow-babel-7/output.json @@ -0,0 +1,42 @@ +{ + "type": "File", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "program": { + "type": "Program", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "expression": { + "type": "ArrowFunctionExpression", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":11,"end":13,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":13}}, + "body": [], + "directives": [] + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}, + "params": [ + { + "type": "TSTypeParameter", + "start":1,"end":4,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4}}, + "name": "div" + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/options.json b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/options.json index 5047d6993fe8..3645e6af68bf 100644 --- a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/options.json +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/options.json @@ -1,3 +1,4 @@ { - "plugins": ["typescript"] + "plugins": ["typescript"], + "BABEL_8_BREAKING": true } diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/output.json b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/output.json index d1ca421c201b..e0fcebce91a5 100644 --- a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/output.json +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/output.json @@ -30,7 +30,11 @@ { "type": "TSTypeParameter", "start":1,"end":4,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4}}, - "name": "div" + "name": { + "type": "Identifier", + "start":1,"end":4,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4},"identifierName":"div"}, + "name": "div" + } } ] } diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null-babel-7/input.ts new file mode 100644 index 000000000000..924ee33ccd2a --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null-babel-7/input.ts @@ -0,0 +1 @@ +async () => await null; diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null-babel-7/output.json new file mode 100644 index 000000000000..980a142db169 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null-babel-7/output.json @@ -0,0 +1,44 @@ +{ + "type": "File", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, + "program": { + "type": "Program", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, + "expression": { + "type": "ArrowFunctionExpression", + "start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9}}, + "params": [ + { + "type": "TSTypeParameter", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}}, + "name": "T" + } + ] + }, + "params": [], + "id": null, + "generator": false, + "async": true, + "body": { + "type": "AwaitExpression", + "start":15,"end":25,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":25}}, + "argument": { + "type": "NullLiteral", + "start":21,"end":25,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":25}} + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null/options.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null/output.json index 980a142db169..14403ad7aa31 100644 --- a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null/output.json +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-await-null/output.json @@ -20,7 +20,11 @@ { "type": "TSTypeParameter", "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}}, - "name": "T" + "name": { + "type": "Identifier", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await-babel-7/input.ts new file mode 100644 index 000000000000..cf80533f9bca --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await-babel-7/input.ts @@ -0,0 +1,4 @@ +async () => { + await null; + async () => null; +}; diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await-babel-7/output.json new file mode 100644 index 000000000000..f038e122ec39 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await-babel-7/output.json @@ -0,0 +1,71 @@ +{ + "type": "File", + "start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}}, + "program": { + "type": "Program", + "start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}}, + "expression": { + "type": "ArrowFunctionExpression", + "start":0,"end":52,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, + "id": null, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start":12,"end":52,"loc":{"start":{"line":1,"column":12},"end":{"line":4,"column":1}}, + "body": [ + { + "type": "ExpressionStatement", + "start":16,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":13}}, + "expression": { + "type": "AwaitExpression", + "start":16,"end":26,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":12}}, + "argument": { + "type": "NullLiteral", + "start":22,"end":26,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":12}} + } + } + }, + { + "type": "ExpressionStatement", + "start":30,"end":50,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":22}}, + "expression": { + "type": "ArrowFunctionExpression", + "start":30,"end":49,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":21}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":36,"end":39,"loc":{"start":{"line":3,"column":8},"end":{"line":3,"column":11}}, + "params": [ + { + "type": "TSTypeParameter", + "start":37,"end":38,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":10}}, + "name": "T" + } + ] + }, + "params": [], + "id": null, + "generator": false, + "async": true, + "body": { + "type": "NullLiteral", + "start":45,"end":49,"loc":{"start":{"line":3,"column":17},"end":{"line":3,"column":21}} + } + } + } + ], + "directives": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await/options.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await/output.json index f038e122ec39..8c8a56517aba 100644 --- a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await/output.json +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-after-await/output.json @@ -46,7 +46,11 @@ { "type": "TSTypeParameter", "start":37,"end":38,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":10}}, - "name": "T" + "name": { + "type": "Identifier", + "start":37,"end":38,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":10},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true-babel-7/input.ts new file mode 100644 index 000000000000..629580116850 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true-babel-7/input.ts @@ -0,0 +1 @@ +async (a: T): T => a; diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true-babel-7/options.json new file mode 100644 index 000000000000..5dfb10823c71 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true-babel-7/options.json @@ -0,0 +1,6 @@ +{ + "sourceType": "module", + "plugins": ["typescript"], + "tokens": true, + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true-babel-7/output.json new file mode 100644 index 000000000000..f7b98d25a7e6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true-babel-7/output.json @@ -0,0 +1,308 @@ +{ + "type": "File", + "start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}}, + "program": { + "type": "Program", + "start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}}, + "expression": { + "type": "ArrowFunctionExpression", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9}}, + "params": [ + { + "type": "TSTypeParameter", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}}, + "name": "T" + } + ] + }, + "params": [ + { + "type": "Identifier", + "start":10,"end":14,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":14},"identifierName":"a"}, + "name": "a", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":11,"end":14,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":14}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14}}, + "typeName": { + "type": "Identifier", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "start":15,"end":18,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":18}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":17,"end":18,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":18}}, + "typeName": { + "type": "Identifier", + "start":17,"end":18,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":18},"identifierName":"T"}, + "name": "T" + } + } + }, + "id": null, + "generator": false, + "async": true, + "body": { + "type": "Identifier", + "start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23},"identifierName":"a"}, + "name": "a" + } + } + } + ], + "directives": [] + }, + "tokens": [ + { + "type": { + "label": "name", + "beforeExpr": false, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "async", + "start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}} + }, + { + "type": { + "label": "/<=/>=", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": 7, + "updateContext": null + }, + "value": "<", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7}} + }, + { + "type": { + "label": "name", + "beforeExpr": false, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "T", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}} + }, + { + "type": { + "label": "/<=/>=", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": 7, + "updateContext": null + }, + "value": ">", + "start":8,"end":9,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":9}} + }, + { + "type": { + "label": "(", + "beforeExpr": true, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10}} + }, + { + "type": { + "label": "name", + "beforeExpr": false, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "a", + "start":10,"end":11,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11}} + }, + { + "type": { + "label": ":", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12}} + }, + { + "type": { + "label": "name", + "beforeExpr": false, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "T", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14}} + }, + { + "type": { + "label": ")", + "beforeExpr": false, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "start":14,"end":15,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":15}} + }, + { + "type": { + "label": ":", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "start":15,"end":16,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":16}} + }, + { + "type": { + "label": "name", + "beforeExpr": false, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "T", + "start":17,"end":18,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":18}} + }, + { + "type": { + "label": "=>", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "start":19,"end":21,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":21}} + }, + { + "type": { + "label": "name", + "beforeExpr": false, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "a", + "start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23}} + }, + { + "type": { + "label": ";", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "start":23,"end":24,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":24}} + }, + { + "type": { + "label": "eof", + "beforeExpr": false, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "start":24,"end":24,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":24}} + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true/options.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true/options.json index 359dbf5e9514..d428f4684767 100644 --- a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true/options.json +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true/options.json @@ -1,5 +1,6 @@ { "sourceType": "module", "plugins": ["typescript"], - "tokens": true + "tokens": true, + "BABEL_8_BREAKING": true } diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true/output.json index f7b98d25a7e6..1a71b80c8b93 100644 --- a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true/output.json +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-tokens-true/output.json @@ -20,7 +20,11 @@ { "type": "TSTypeParameter", "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}}, - "name": "T" + "name": { + "type": "Identifier", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-babel-7/input.ts new file mode 100644 index 000000000000..110f583654c0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-babel-7/input.ts @@ -0,0 +1 @@ +(a: T): T => a; diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-babel-7/output.json new file mode 100644 index 000000000000..53c4a1b036b0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-babel-7/output.json @@ -0,0 +1,73 @@ +{ + "type": "File", + "start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}}, + "program": { + "type": "Program", + "start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}}, + "expression": { + "type": "ArrowFunctionExpression", + "start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}}, + "returnType": { + "type": "TSTypeAnnotation", + "start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12}}, + "typeName": { + "type": "Identifier", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12},"identifierName":"T"}, + "name": "T" + } + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":4,"end":8,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":8},"identifierName":"a"}, + "name": "a", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":5,"end":8,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":8}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}}, + "typeName": { + "type": "Identifier", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "body": { + "type": "Identifier", + "start":16,"end":17,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":17},"identifierName":"a"}, + "name": "a" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}}, + "params": [ + { + "type": "TSTypeParameter", + "start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2}}, + "name": "T" + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx-babel-7/input.ts new file mode 100644 index 000000000000..b9eea2b05a59 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx-babel-7/input.ts @@ -0,0 +1,2 @@ +// Same as `generic`. Verify that JSX doesn't change things. +(a: T): T => a; diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx-babel-7/options.json new file mode 100644 index 000000000000..d8977ba49c7d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx-babel-7/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["jsx", "typescript"], + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx-babel-7/output.json new file mode 100644 index 000000000000..63b920fbf41c --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx-babel-7/output.json @@ -0,0 +1,87 @@ +{ + "type": "File", + "start":0,"end":79,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":18}}, + "program": { + "type": "Program", + "start":0,"end":79,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":18}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":61,"end":79,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":18}}, + "leadingComments": [ + { + "type": "CommentLine", + "value": " Same as `generic`. Verify that JSX doesn't change things.", + "start":0,"end":60,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":60}} + } + ], + "expression": { + "type": "ArrowFunctionExpression", + "start":61,"end":78,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":17}}, + "returnType": { + "type": "TSTypeAnnotation", + "start":70,"end":73,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":72,"end":73,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":12}}, + "typeName": { + "type": "Identifier", + "start":72,"end":73,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":12},"identifierName":"T"}, + "name": "T" + } + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":65,"end":69,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":8},"identifierName":"a"}, + "name": "a", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":66,"end":69,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":8}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":68,"end":69,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":8}}, + "typeName": { + "type": "Identifier", + "start":68,"end":69,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":8},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "body": { + "type": "Identifier", + "start":77,"end":78,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":17},"identifierName":"a"}, + "name": "a" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":61,"end":64,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":3}}, + "params": [ + { + "type": "TSTypeParameter", + "start":62,"end":63,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":2}}, + "name": "T" + } + ] + } + } + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " Same as `generic`. Verify that JSX doesn't change things.", + "start":0,"end":60,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":60}} + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx/options.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx/options.json index aa8780ac5180..b4bc5ff97eab 100644 --- a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx/options.json +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx/options.json @@ -1,3 +1,4 @@ { - "plugins": ["jsx", "typescript"] + "plugins": ["jsx", "typescript"], + "BABEL_8_BREAKING": true } diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx/output.json index 2d19c9f092ce..1756e5e2240e 100644 --- a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx/output.json +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx/output.json @@ -10,6 +10,13 @@ { "type": "ExpressionStatement", "start":61,"end":79,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":18}}, + "leadingComments": [ + { + "type": "CommentLine", + "value": " Same as `generic`. Verify that JSX doesn't change things.", + "start":0,"end":60,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":60}} + } + ], "expression": { "type": "ArrowFunctionExpression", "start":61,"end":78,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":17}}, @@ -61,18 +68,15 @@ { "type": "TSTypeParameter", "start":62,"end":63,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":2}}, - "name": "T" + "name": { + "type": "Identifier", + "start":62,"end":63,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":2},"identifierName":"T"}, + "name": "T" + } } ] } - }, - "leadingComments": [ - { - "type": "CommentLine", - "value": " Same as `generic`. Verify that JSX doesn't change things.", - "start":0,"end":60,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":60}} - } - ] + } } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic/options.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic/output.json index 53c4a1b036b0..2f93cffc330f 100644 --- a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic/output.json +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic/output.json @@ -61,7 +61,11 @@ { "type": "TSTypeParameter", "start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2}}, - "name": "T" + "name": { + "type": "Identifier", + "start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2},"identifierName":"T"}, + "name": "T" + } } ] } diff --git a/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters-babel-7/input.ts new file mode 100644 index 000000000000..0c51dfc5ebef --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters-babel-7/input.ts @@ -0,0 +1,3 @@ +class C { + constructor(foo: T) {} +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters-babel-7/output.json new file mode 100644 index 000000000000..38964cd9c251 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters-babel-7/output.json @@ -0,0 +1,84 @@ +{ + "type": "File", + "start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "errors": [ + "SyntaxError: Type parameters cannot appear on a constructor declaration. (2:13)" + ], + "program": { + "type": "Program", + "start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"}, + "name": "C" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":8,"end":39,"loc":{"start":{"line":1,"column":8},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassMethod", + "start":12,"end":37,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":27}}, + "static": false, + "key": { + "type": "Identifier", + "start":12,"end":23,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":13},"identifierName":"constructor"}, + "name": "constructor" + }, + "computed": false, + "kind": "constructor", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":23,"end":26,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":16}}, + "params": [ + { + "type": "TSTypeParameter", + "start":24,"end":25,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":15}}, + "name": "T" + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":27,"end":33,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":23},"identifierName":"foo"}, + "name": "foo", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":30,"end":33,"loc":{"start":{"line":2,"column":20},"end":{"line":2,"column":23}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":32,"end":33,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":23}}, + "typeName": { + "type": "Identifier", + "start":32,"end":33,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":23},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "body": { + "type": "BlockStatement", + "start":35,"end":37,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":27}}, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters/options.json b/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters/output.json b/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters/output.json index 38964cd9c251..76217c5c27bd 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters/output.json +++ b/packages/babel-parser/test/fixtures/typescript/class/constructor-with-type-parameters/output.json @@ -41,7 +41,11 @@ { "type": "TSTypeParameter", "start":24,"end":25,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":15}}, - "name": "T" + "name": { + "type": "Identifier", + "start":24,"end":25,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":15},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/class/expression-generic-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/class/expression-generic-babel-7/input.ts new file mode 100644 index 000000000000..94973f7a29df --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/expression-generic-babel-7/input.ts @@ -0,0 +1,2 @@ +(class {}); +(class C {}); diff --git a/packages/babel-parser/test/fixtures/typescript/class/expression-generic-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/class/expression-generic-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/expression-generic-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/expression-generic-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/class/expression-generic-babel-7/output.json new file mode 100644 index 000000000000..474f9a0a9c03 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/expression-generic-babel-7/output.json @@ -0,0 +1,77 @@ +{ + "type": "File", + "start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":16}}, + "program": { + "type": "Program", + "start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":16}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}}, + "expression": { + "type": "ClassExpression", + "start":1,"end":12,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":12}}, + "extra": { + "parenthesized": true, + "parenStart": 0 + }, + "id": null, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9}}, + "params": [ + { + "type": "TSTypeParameter", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}}, + "name": "T" + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":12,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":12}}, + "body": [] + } + } + }, + { + "type": "ExpressionStatement", + "start":15,"end":31,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":16}}, + "expression": { + "type": "ClassExpression", + "start":16,"end":29,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":14}}, + "extra": { + "parenthesized": true, + "parenStart": 15 + }, + "id": { + "type": "Identifier", + "start":22,"end":23,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":8},"identifierName":"C"}, + "name": "C" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":23,"end":26,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":11}}, + "params": [ + { + "type": "TSTypeParameter", + "start":24,"end":25,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":10}}, + "name": "T" + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":27,"end":29,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":14}}, + "body": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/class/expression-generic/options.json b/packages/babel-parser/test/fixtures/typescript/class/expression-generic/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/expression-generic/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/expression-generic/output.json b/packages/babel-parser/test/fixtures/typescript/class/expression-generic/output.json index 1947c1767de2..fd303566915e 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/expression-generic/output.json +++ b/packages/babel-parser/test/fixtures/typescript/class/expression-generic/output.json @@ -13,6 +13,10 @@ "expression": { "type": "ClassExpression", "start":1,"end":12,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":12}}, + "extra": { + "parenthesized": true, + "parenStart": 0 + }, "id": null, "typeParameters": { "type": "TSTypeParameterDeclaration", @@ -21,7 +25,11 @@ { "type": "TSTypeParameter", "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}}, - "name": "T" + "name": { + "type": "Identifier", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -30,10 +38,6 @@ "type": "ClassBody", "start":10,"end":12,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":12}}, "body": [] - }, - "extra": { - "parenthesized": true, - "parenStart": 0 } } }, @@ -43,6 +47,10 @@ "expression": { "type": "ClassExpression", "start":16,"end":29,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":14}}, + "extra": { + "parenthesized": true, + "parenStart": 15 + }, "id": { "type": "Identifier", "start":22,"end":23,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":8},"identifierName":"C"}, @@ -55,7 +63,11 @@ { "type": "TSTypeParameter", "start":24,"end":25,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":10}}, - "name": "T" + "name": { + "type": "Identifier", + "start":24,"end":25,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":10},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -64,10 +76,6 @@ "type": "ClassBody", "start":27,"end":29,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":14}}, "body": [] - }, - "extra": { - "parenthesized": true, - "parenStart": 15 } } } diff --git a/packages/babel-parser/test/fixtures/typescript/class/generic-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/class/generic-babel-7/input.ts new file mode 100644 index 000000000000..dbaeabda8c25 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/generic-babel-7/input.ts @@ -0,0 +1 @@ +class C {} diff --git a/packages/babel-parser/test/fixtures/typescript/class/generic-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/class/generic-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/generic-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/generic-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/class/generic-babel-7/output.json new file mode 100644 index 000000000000..a01ce54b0ac2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/generic-babel-7/output.json @@ -0,0 +1,67 @@ +{ + "type": "File", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}}, + "program": { + "type": "Program", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}}, + "id": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"}, + "name": "C" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":7,"end":41,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":41}}, + "params": [ + { + "type": "TSTypeParameter", + "start":8,"end":40,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":40}}, + "name": "T", + "constraint": { + "type": "TSObjectKeyword", + "start":18,"end":24,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":24}} + }, + "default": { + "type": "TSTypeLiteral", + "start":27,"end":40,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":40}}, + "members": [ + { + "type": "TSPropertySignature", + "start":29,"end":38,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":38}}, + "key": { + "type": "Identifier", + "start":29,"end":30,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":30},"identifierName":"x"}, + "name": "x" + }, + "computed": false, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":30,"end":38,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":38}}, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":32,"end":38,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":38}} + } + } + } + ] + } + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":42,"end":44,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":44}}, + "body": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/class/generic/options.json b/packages/babel-parser/test/fixtures/typescript/class/generic/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/generic/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/generic/output.json b/packages/babel-parser/test/fixtures/typescript/class/generic/output.json index a01ce54b0ac2..d65eb849a0f8 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/generic/output.json +++ b/packages/babel-parser/test/fixtures/typescript/class/generic/output.json @@ -22,7 +22,11 @@ { "type": "TSTypeParameter", "start":8,"end":40,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":40}}, - "name": "T", + "name": { + "type": "Identifier", + "start":8,"end":9,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":9},"identifierName":"T"}, + "name": "T" + }, "constraint": { "type": "TSObjectKeyword", "start":18,"end":24,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":24}} diff --git a/packages/babel-parser/test/fixtures/typescript/class/get-generic-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/class/get-generic-babel-7/input.ts new file mode 100644 index 000000000000..85739b3c2fae --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/get-generic-babel-7/input.ts @@ -0,0 +1,3 @@ +declare class C { + get(): void; +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/get-generic-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/class/get-generic-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/get-generic-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/get-generic-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/class/get-generic-babel-7/output.json new file mode 100644 index 000000000000..19af433cd482 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/get-generic-babel-7/output.json @@ -0,0 +1,65 @@ +{ + "type": "File", + "start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "declare": true, + "id": { + "type": "Identifier", + "start":14,"end":15,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":15},"identifierName":"C"}, + "name": "C" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":16,"end":39,"loc":{"start":{"line":1,"column":16},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "TSDeclareMethod", + "start":22,"end":37,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":19}}, + "static": false, + "key": { + "type": "Identifier", + "start":22,"end":25,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":7},"identifierName":"get"}, + "name": "get" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":25,"end":28,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":10}}, + "params": [ + { + "type": "TSTypeParameter", + "start":26,"end":27,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":9}}, + "name": "T" + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "returnType": { + "type": "TSTypeAnnotation", + "start":30,"end":36,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":18}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":32,"end":36,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":18}} + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/class/get-generic/options.json b/packages/babel-parser/test/fixtures/typescript/class/get-generic/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/get-generic/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/get-generic/output.json b/packages/babel-parser/test/fixtures/typescript/class/get-generic/output.json index 19af433cd482..36c1811b99d2 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/get-generic/output.json +++ b/packages/babel-parser/test/fixtures/typescript/class/get-generic/output.json @@ -39,7 +39,11 @@ { "type": "TSTypeParameter", "start":26,"end":27,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":9}}, - "name": "T" + "name": { + "type": "Identifier", + "start":26,"end":27,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":9},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names-babel-7/input.ts new file mode 100644 index 000000000000..97ead10b46c6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names-babel-7/input.ts @@ -0,0 +1,7 @@ +class C { + public(): void; + public static(): void; + readonly = 0; + async(): void; + abstract!:void; +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names-babel-7/output.json new file mode 100644 index 000000000000..6619ed4663eb --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names-babel-7/output.json @@ -0,0 +1,154 @@ +{ + "type": "File", + "start":0,"end":118,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":118,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":118,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"}, + "name": "C" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":8,"end":118,"loc":{"start":{"line":1,"column":8},"end":{"line":7,"column":1}}, + "body": [ + { + "type": "TSDeclareMethod", + "start":14,"end":29,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":19}}, + "static": false, + "key": { + "type": "Identifier", + "start":14,"end":20,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":10},"identifierName":"public"}, + "name": "public" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "returnType": { + "type": "TSTypeAnnotation", + "start":22,"end":28,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":18}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":24,"end":28,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":18}} + } + } + }, + { + "type": "TSDeclareMethod", + "start":34,"end":56,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":26}}, + "accessibility": "public", + "kind": "method", + "computed": false, + "key": { + "type": "Identifier", + "start":41,"end":47,"loc":{"start":{"line":3,"column":11},"end":{"line":3,"column":17},"identifierName":"static"}, + "name": "static" + }, + "static": false, + "id": null, + "generator": false, + "async": false, + "params": [], + "returnType": { + "type": "TSTypeAnnotation", + "start":49,"end":55,"loc":{"start":{"line":3,"column":19},"end":{"line":3,"column":25}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":51,"end":55,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":25}} + } + } + }, + { + "type": "ClassProperty", + "start":61,"end":74,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":17}}, + "static": false, + "key": { + "type": "Identifier", + "start":61,"end":69,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":12},"identifierName":"readonly"}, + "name": "readonly" + }, + "computed": false, + "value": { + "type": "NumericLiteral", + "start":72,"end":73,"loc":{"start":{"line":4,"column":15},"end":{"line":4,"column":16}}, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "TSDeclareMethod", + "start":79,"end":96,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":21}}, + "static": false, + "key": { + "type": "Identifier", + "start":79,"end":84,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":9},"identifierName":"async"}, + "name": "async" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":84,"end":87,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":12}}, + "params": [ + { + "type": "TSTypeParameter", + "start":85,"end":86,"loc":{"start":{"line":5,"column":10},"end":{"line":5,"column":11}}, + "name": "T" + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "returnType": { + "type": "TSTypeAnnotation", + "start":89,"end":95,"loc":{"start":{"line":5,"column":14},"end":{"line":5,"column":20}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":91,"end":95,"loc":{"start":{"line":5,"column":16},"end":{"line":5,"column":20}} + } + } + }, + { + "type": "ClassProperty", + "start":101,"end":116,"loc":{"start":{"line":6,"column":4},"end":{"line":6,"column":19}}, + "static": false, + "key": { + "type": "Identifier", + "start":101,"end":109,"loc":{"start":{"line":6,"column":4},"end":{"line":6,"column":12},"identifierName":"abstract"}, + "name": "abstract" + }, + "computed": false, + "definite": true, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":110,"end":115,"loc":{"start":{"line":6,"column":13},"end":{"line":6,"column":18}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":111,"end":115,"loc":{"start":{"line":6,"column":14},"end":{"line":6,"column":18}} + } + }, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/options.json b/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/output.json b/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/output.json index 6619ed4663eb..2945b53aa0b7 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/output.json +++ b/packages/babel-parser/test/fixtures/typescript/class/members-with-modifier-names/output.json @@ -107,7 +107,11 @@ { "type": "TSTypeParameter", "start":85,"end":86,"loc":{"start":{"line":5,"column":10},"end":{"line":5,"column":11}}, - "name": "T" + "name": { + "type": "Identifier", + "start":85,"end":86,"loc":{"start":{"line":5,"column":10},"end":{"line":5,"column":11},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/class/method-generic-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/class/method-generic-babel-7/input.ts new file mode 100644 index 000000000000..ceefb4d0ceb8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/method-generic-babel-7/input.ts @@ -0,0 +1,4 @@ +class C { + f(a: T, b?: T, ...c: T[]): T {} + [Symbol.iterator](): T {} +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/method-generic-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/class/method-generic-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/method-generic-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/method-generic-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/class/method-generic-babel-7/output.json new file mode 100644 index 000000000000..09d5607db30b --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/method-generic-babel-7/output.json @@ -0,0 +1,195 @@ +{ + "type": "File", + "start":0,"end":83,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":83,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":83,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"}, + "name": "C" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":8,"end":83,"loc":{"start":{"line":1,"column":8},"end":{"line":4,"column":1}}, + "body": [ + { + "type": "ClassMethod", + "start":14,"end":48,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":38}}, + "static": false, + "key": { + "type": "Identifier", + "start":14,"end":15,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":5},"identifierName":"f"}, + "name": "f" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":15,"end":18,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":8}}, + "params": [ + { + "type": "TSTypeParameter", + "start":16,"end":17,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":7}}, + "name": "T" + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":19,"end":23,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":13},"identifierName":"a"}, + "name": "a", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":20,"end":23,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":13}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":22,"end":23,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":13}}, + "typeName": { + "type": "Identifier", + "start":22,"end":23,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":13},"identifierName":"T"}, + "name": "T" + } + } + } + }, + { + "type": "Identifier", + "start":25,"end":30,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":20},"identifierName":"b"}, + "name": "b", + "optional": true, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":27,"end":30,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":20}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":29,"end":30,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":20}}, + "typeName": { + "type": "Identifier", + "start":29,"end":30,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":20},"identifierName":"T"}, + "name": "T" + } + } + } + }, + { + "type": "RestElement", + "start":32,"end":41,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":31}}, + "argument": { + "type": "Identifier", + "start":35,"end":36,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":26},"identifierName":"c"}, + "name": "c" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":36,"end":41,"loc":{"start":{"line":2,"column":26},"end":{"line":2,"column":31}}, + "typeAnnotation": { + "type": "TSArrayType", + "start":38,"end":41,"loc":{"start":{"line":2,"column":28},"end":{"line":2,"column":31}}, + "elementType": { + "type": "TSTypeReference", + "start":38,"end":39,"loc":{"start":{"line":2,"column":28},"end":{"line":2,"column":29}}, + "typeName": { + "type": "Identifier", + "start":38,"end":39,"loc":{"start":{"line":2,"column":28},"end":{"line":2,"column":29},"identifierName":"T"}, + "name": "T" + } + } + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "start":42,"end":45,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":35}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":44,"end":45,"loc":{"start":{"line":2,"column":34},"end":{"line":2,"column":35}}, + "typeName": { + "type": "Identifier", + "start":44,"end":45,"loc":{"start":{"line":2,"column":34},"end":{"line":2,"column":35},"identifierName":"T"}, + "name": "T" + } + } + }, + "body": { + "type": "BlockStatement", + "start":46,"end":48,"loc":{"start":{"line":2,"column":36},"end":{"line":2,"column":38}}, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start":53,"end":81,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":32}}, + "static": false, + "computed": true, + "key": { + "type": "MemberExpression", + "start":54,"end":69,"loc":{"start":{"line":3,"column":5},"end":{"line":3,"column":20}}, + "object": { + "type": "Identifier", + "start":54,"end":60,"loc":{"start":{"line":3,"column":5},"end":{"line":3,"column":11},"identifierName":"Symbol"}, + "name": "Symbol" + }, + "computed": false, + "property": { + "type": "Identifier", + "start":61,"end":69,"loc":{"start":{"line":3,"column":12},"end":{"line":3,"column":20},"identifierName":"iterator"}, + "name": "iterator" + } + }, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":70,"end":73,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":24}}, + "params": [ + { + "type": "TSTypeParameter", + "start":71,"end":72,"loc":{"start":{"line":3,"column":22},"end":{"line":3,"column":23}}, + "name": "T" + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "returnType": { + "type": "TSTypeAnnotation", + "start":75,"end":78,"loc":{"start":{"line":3,"column":26},"end":{"line":3,"column":29}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":77,"end":78,"loc":{"start":{"line":3,"column":28},"end":{"line":3,"column":29}}, + "typeName": { + "type": "Identifier", + "start":77,"end":78,"loc":{"start":{"line":3,"column":28},"end":{"line":3,"column":29},"identifierName":"T"}, + "name": "T" + } + } + }, + "body": { + "type": "BlockStatement", + "start":79,"end":81,"loc":{"start":{"line":3,"column":30},"end":{"line":3,"column":32}}, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/class/method-generic/options.json b/packages/babel-parser/test/fixtures/typescript/class/method-generic/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/method-generic/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/method-generic/output.json b/packages/babel-parser/test/fixtures/typescript/class/method-generic/output.json index 390658ca6609..6d08813ab319 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/method-generic/output.json +++ b/packages/babel-parser/test/fixtures/typescript/class/method-generic/output.json @@ -38,7 +38,11 @@ { "type": "TSTypeParameter", "start":16,"end":17,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":7}}, - "name": "T" + "name": { + "type": "Identifier", + "start":16,"end":17,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":7},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -143,12 +147,12 @@ "start":54,"end":60,"loc":{"start":{"line":3,"column":5},"end":{"line":3,"column":11},"identifierName":"Symbol"}, "name": "Symbol" }, + "computed": false, "property": { "type": "Identifier", "start":61,"end":69,"loc":{"start":{"line":3,"column":12},"end":{"line":3,"column":20},"identifierName":"iterator"}, "name": "iterator" - }, - "computed": false + } }, "kind": "method", "typeParameters": { @@ -158,7 +162,11 @@ { "type": "TSTypeParameter", "start":71,"end":72,"loc":{"start":{"line":3,"column":22},"end":{"line":3,"column":23}}, - "name": "T" + "name": { + "type": "Identifier", + "start":71,"end":72,"loc":{"start":{"line":3,"column":22},"end":{"line":3,"column":23},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters-babel-7/input.ts new file mode 100644 index 000000000000..ce489644016d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters-babel-7/input.ts @@ -0,0 +1,9 @@ +class C { + declare() {} + readonly() {} + abstract() {} + static() {} + private() {} + public() {} + protected() {} +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters-babel-7/output.json new file mode 100644 index 000000000000..c242a1291f45 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters-babel-7/output.json @@ -0,0 +1,260 @@ +{ + "type": "File", + "start":0,"end":139,"loc":{"start":{"line":1,"column":0},"end":{"line":9,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":139,"loc":{"start":{"line":1,"column":0},"end":{"line":9,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":139,"loc":{"start":{"line":1,"column":0},"end":{"line":9,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"}, + "name": "C" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":8,"end":139,"loc":{"start":{"line":1,"column":8},"end":{"line":9,"column":1}}, + "body": [ + { + "type": "ClassMethod", + "start":12,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}}, + "static": false, + "key": { + "type": "Identifier", + "start":12,"end":19,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":9},"identifierName":"declare"}, + "name": "declare" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":19,"end":22,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12}}, + "params": [ + { + "type": "TSTypeParameter", + "start":20,"end":21,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11}}, + "name": "T" + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":25,"end":27,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":17}}, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start":30,"end":46,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":18}}, + "static": false, + "key": { + "type": "Identifier", + "start":30,"end":38,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":10},"identifierName":"readonly"}, + "name": "readonly" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":38,"end":41,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":13}}, + "params": [ + { + "type": "TSTypeParameter", + "start":39,"end":40,"loc":{"start":{"line":3,"column":11},"end":{"line":3,"column":12}}, + "name": "T" + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":44,"end":46,"loc":{"start":{"line":3,"column":16},"end":{"line":3,"column":18}}, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start":49,"end":65,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":18}}, + "static": false, + "key": { + "type": "Identifier", + "start":49,"end":57,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":10},"identifierName":"abstract"}, + "name": "abstract" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":57,"end":60,"loc":{"start":{"line":4,"column":10},"end":{"line":4,"column":13}}, + "params": [ + { + "type": "TSTypeParameter", + "start":58,"end":59,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":12}}, + "name": "T" + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":63,"end":65,"loc":{"start":{"line":4,"column":16},"end":{"line":4,"column":18}}, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start":68,"end":82,"loc":{"start":{"line":5,"column":2},"end":{"line":5,"column":16}}, + "kind": "method", + "computed": false, + "key": { + "type": "Identifier", + "start":68,"end":74,"loc":{"start":{"line":5,"column":2},"end":{"line":5,"column":8},"identifierName":"static"}, + "name": "static" + }, + "static": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":74,"end":77,"loc":{"start":{"line":5,"column":8},"end":{"line":5,"column":11}}, + "params": [ + { + "type": "TSTypeParameter", + "start":75,"end":76,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":10}}, + "name": "T" + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":80,"end":82,"loc":{"start":{"line":5,"column":14},"end":{"line":5,"column":16}}, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start":85,"end":100,"loc":{"start":{"line":6,"column":2},"end":{"line":6,"column":17}}, + "static": false, + "key": { + "type": "Identifier", + "start":85,"end":92,"loc":{"start":{"line":6,"column":2},"end":{"line":6,"column":9},"identifierName":"private"}, + "name": "private" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":92,"end":95,"loc":{"start":{"line":6,"column":9},"end":{"line":6,"column":12}}, + "params": [ + { + "type": "TSTypeParameter", + "start":93,"end":94,"loc":{"start":{"line":6,"column":10},"end":{"line":6,"column":11}}, + "name": "T" + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":98,"end":100,"loc":{"start":{"line":6,"column":15},"end":{"line":6,"column":17}}, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start":103,"end":117,"loc":{"start":{"line":7,"column":2},"end":{"line":7,"column":16}}, + "static": false, + "key": { + "type": "Identifier", + "start":103,"end":109,"loc":{"start":{"line":7,"column":2},"end":{"line":7,"column":8},"identifierName":"public"}, + "name": "public" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":109,"end":112,"loc":{"start":{"line":7,"column":8},"end":{"line":7,"column":11}}, + "params": [ + { + "type": "TSTypeParameter", + "start":110,"end":111,"loc":{"start":{"line":7,"column":9},"end":{"line":7,"column":10}}, + "name": "T" + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":115,"end":117,"loc":{"start":{"line":7,"column":14},"end":{"line":7,"column":16}}, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start":120,"end":137,"loc":{"start":{"line":8,"column":2},"end":{"line":8,"column":19}}, + "static": false, + "key": { + "type": "Identifier", + "start":120,"end":129,"loc":{"start":{"line":8,"column":2},"end":{"line":8,"column":11},"identifierName":"protected"}, + "name": "protected" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":129,"end":132,"loc":{"start":{"line":8,"column":11},"end":{"line":8,"column":14}}, + "params": [ + { + "type": "TSTypeParameter", + "start":130,"end":131,"loc":{"start":{"line":8,"column":12},"end":{"line":8,"column":13}}, + "name": "T" + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":135,"end":137,"loc":{"start":{"line":8,"column":17},"end":{"line":8,"column":19}}, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters/options.json b/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters/output.json b/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters/output.json index c242a1291f45..f3dd150124f4 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters/output.json +++ b/packages/babel-parser/test/fixtures/typescript/class/method-modifier-name-with-type-parameters/output.json @@ -38,7 +38,11 @@ { "type": "TSTypeParameter", "start":20,"end":21,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11}}, - "name": "T" + "name": { + "type": "Identifier", + "start":20,"end":21,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -71,7 +75,11 @@ { "type": "TSTypeParameter", "start":39,"end":40,"loc":{"start":{"line":3,"column":11},"end":{"line":3,"column":12}}, - "name": "T" + "name": { + "type": "Identifier", + "start":39,"end":40,"loc":{"start":{"line":3,"column":11},"end":{"line":3,"column":12},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -104,7 +112,11 @@ { "type": "TSTypeParameter", "start":58,"end":59,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":12}}, - "name": "T" + "name": { + "type": "Identifier", + "start":58,"end":59,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":12},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -137,7 +149,11 @@ { "type": "TSTypeParameter", "start":75,"end":76,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":10}}, - "name": "T" + "name": { + "type": "Identifier", + "start":75,"end":76,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":10},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -170,7 +186,11 @@ { "type": "TSTypeParameter", "start":93,"end":94,"loc":{"start":{"line":6,"column":10},"end":{"line":6,"column":11}}, - "name": "T" + "name": { + "type": "Identifier", + "start":93,"end":94,"loc":{"start":{"line":6,"column":10},"end":{"line":6,"column":11},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -203,7 +223,11 @@ { "type": "TSTypeParameter", "start":110,"end":111,"loc":{"start":{"line":7,"column":9},"end":{"line":7,"column":10}}, - "name": "T" + "name": { + "type": "Identifier", + "start":110,"end":111,"loc":{"start":{"line":7,"column":9},"end":{"line":7,"column":10},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -236,7 +260,11 @@ { "type": "TSTypeParameter", "start":130,"end":131,"loc":{"start":{"line":8,"column":12},"end":{"line":8,"column":13}}, - "name": "T" + "name": { + "type": "Identifier", + "start":130,"end":131,"loc":{"start":{"line":8,"column":12},"end":{"line":8,"column":13},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/function/annotated-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/function/annotated-babel-7/input.ts new file mode 100644 index 000000000000..139772fad018 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/annotated-babel-7/input.ts @@ -0,0 +1 @@ +function f(x?: T): T {} diff --git a/packages/babel-parser/test/fixtures/typescript/function/annotated-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/function/annotated-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/annotated-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/function/annotated-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/function/annotated-babel-7/output.json new file mode 100644 index 000000000000..6db63dafc279 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/annotated-babel-7/output.json @@ -0,0 +1,75 @@ +{ + "type": "File", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, + "program": { + "type": "Program", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, + "id": { + "type": "Identifier", + "start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":10,"end":13,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":13}}, + "params": [ + { + "type": "TSTypeParameter", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12}}, + "name": "T" + } + ] + }, + "params": [ + { + "type": "Identifier", + "start":14,"end":19,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":19},"identifierName":"x"}, + "name": "x", + "optional": true, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":16,"end":19,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":19}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19}}, + "typeName": { + "type": "Identifier", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "start":20,"end":23,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":23}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23}}, + "typeName": { + "type": "Identifier", + "start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23},"identifierName":"T"}, + "name": "T" + } + } + }, + "body": { + "type": "BlockStatement", + "start":24,"end":26,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":26}}, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/function/annotated/options.json b/packages/babel-parser/test/fixtures/typescript/function/annotated/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/annotated/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/function/annotated/output.json b/packages/babel-parser/test/fixtures/typescript/function/annotated/output.json index 6db63dafc279..4b2ba802a89f 100644 --- a/packages/babel-parser/test/fixtures/typescript/function/annotated/output.json +++ b/packages/babel-parser/test/fixtures/typescript/function/annotated/output.json @@ -24,7 +24,11 @@ { "type": "TSTypeParameter", "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12}}, - "name": "T" + "name": { + "type": "Identifier", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/function/anonymous-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/function/anonymous-babel-7/input.ts new file mode 100644 index 000000000000..395ce03c0449 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/anonymous-babel-7/input.ts @@ -0,0 +1 @@ +const f = function(x?: T): T {}; diff --git a/packages/babel-parser/test/fixtures/typescript/function/anonymous-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/function/anonymous-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/anonymous-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/function/anonymous-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/function/anonymous-babel-7/output.json new file mode 100644 index 000000000000..ed420fce066c --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/anonymous-babel-7/output.json @@ -0,0 +1,87 @@ +{ + "type": "File", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "program": { + "type": "Program", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":6,"end":34,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":34}}, + "id": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"f"}, + "name": "f" + }, + "init": { + "type": "FunctionExpression", + "start":10,"end":34,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":34}}, + "id": null, + "generator": false, + "async": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":18,"end":21,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":21}}, + "params": [ + { + "type": "TSTypeParameter", + "start":19,"end":20,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":20}}, + "name": "T" + } + ] + }, + "params": [ + { + "type": "Identifier", + "start":22,"end":27,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":27},"identifierName":"x"}, + "name": "x", + "optional": true, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":24,"end":27,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":27}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":26,"end":27,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":27}}, + "typeName": { + "type": "Identifier", + "start":26,"end":27,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":27},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "start":28,"end":31,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":31}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":30,"end":31,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":31}}, + "typeName": { + "type": "Identifier", + "start":30,"end":31,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":31},"identifierName":"T"}, + "name": "T" + } + } + }, + "body": { + "type": "BlockStatement", + "start":32,"end":34,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":34}}, + "body": [], + "directives": [] + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator-babel-7/input.ts new file mode 100644 index 000000000000..33ce49c1f4a6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator-babel-7/input.ts @@ -0,0 +1,3 @@ +const fn = function* (input: T): Generator { + yield 2; +} diff --git a/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator-babel-7/output.json new file mode 100644 index 000000000000..b48b432ce19a --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator-babel-7/output.json @@ -0,0 +1,115 @@ +{ + "type": "File", + "start":0,"end":68,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":68,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":68,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":6,"end":68,"loc":{"start":{"line":1,"column":6},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":8,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":8},"identifierName":"fn"}, + "name": "fn" + }, + "init": { + "type": "FunctionExpression", + "start":11,"end":68,"loc":{"start":{"line":1,"column":11},"end":{"line":3,"column":1}}, + "id": null, + "generator": true, + "async": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":21,"end":24,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":24}}, + "params": [ + { + "type": "TSTypeParameter", + "start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23}}, + "name": "T" + } + ] + }, + "params": [ + { + "type": "Identifier", + "start":25,"end":33,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":33},"identifierName":"input"}, + "name": "input", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":30,"end":33,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":33}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":32,"end":33,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":33}}, + "typeName": { + "type": "Identifier", + "start":32,"end":33,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":33},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "start":34,"end":53,"loc":{"start":{"line":1,"column":34},"end":{"line":1,"column":53}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":36,"end":53,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":53}}, + "typeName": { + "type": "Identifier", + "start":36,"end":45,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":45},"identifierName":"Generator"}, + "name": "Generator" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":45,"end":53,"loc":{"start":{"line":1,"column":45},"end":{"line":1,"column":53}}, + "params": [ + { + "type": "TSNumberKeyword", + "start":46,"end":52,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":52}} + } + ] + } + } + }, + "body": { + "type": "BlockStatement", + "start":54,"end":68,"loc":{"start":{"line":1,"column":54},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ExpressionStatement", + "start":58,"end":66,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":10}}, + "expression": { + "type": "YieldExpression", + "start":58,"end":65,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":9}}, + "delegate": false, + "argument": { + "type": "NumericLiteral", + "start":64,"end":65,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":9}}, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + ], + "directives": [] + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator/options.json b/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator/output.json b/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator/output.json index b48b432ce19a..176fc3d5efc6 100644 --- a/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator/output.json +++ b/packages/babel-parser/test/fixtures/typescript/function/anonymous-generator/output.json @@ -32,7 +32,11 @@ { "type": "TSTypeParameter", "start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23}}, - "name": "T" + "name": { + "type": "Identifier", + "start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/function/anonymous/options.json b/packages/babel-parser/test/fixtures/typescript/function/anonymous/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/anonymous/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/function/anonymous/output.json b/packages/babel-parser/test/fixtures/typescript/function/anonymous/output.json index ed420fce066c..5a789338b1a7 100644 --- a/packages/babel-parser/test/fixtures/typescript/function/anonymous/output.json +++ b/packages/babel-parser/test/fixtures/typescript/function/anonymous/output.json @@ -32,7 +32,11 @@ { "type": "TSTypeParameter", "start":19,"end":20,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":20}}, - "name": "T" + "name": { + "type": "Identifier", + "start":19,"end":20,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":20},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/function/declare-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/function/declare-babel-7/input.ts new file mode 100644 index 000000000000..f3a0c553cfdb --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/declare-babel-7/input.ts @@ -0,0 +1,2 @@ +declare function f(): void; +declare function f(): T; diff --git a/packages/babel-parser/test/fixtures/typescript/function/declare-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/function/declare-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/declare-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/function/declare-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/function/declare-babel-7/output.json new file mode 100644 index 000000000000..9ed3253ebec2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/declare-babel-7/output.json @@ -0,0 +1,71 @@ +{ + "type": "File", + "start":0,"end":55,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":27}}, + "program": { + "type": "Program", + "start":0,"end":55,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":27}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSDeclareFunction", + "start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, + "declare": true, + "id": { + "type": "Identifier", + "start":17,"end":18,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":18},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": false, + "params": [], + "returnType": { + "type": "TSTypeAnnotation", + "start":20,"end":26,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":26}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":22,"end":26,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":26}} + } + } + }, + { + "type": "TSDeclareFunction", + "start":28,"end":55,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":27}}, + "declare": true, + "id": { + "type": "Identifier", + "start":45,"end":46,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":18},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":46,"end":49,"loc":{"start":{"line":2,"column":18},"end":{"line":2,"column":21}}, + "params": [ + { + "type": "TSTypeParameter", + "start":47,"end":48,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":20}}, + "name": "T" + } + ] + }, + "params": [], + "returnType": { + "type": "TSTypeAnnotation", + "start":51,"end":54,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":26}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":53,"end":54,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":26}}, + "typeName": { + "type": "Identifier", + "start":53,"end":54,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":26},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/function/declare/options.json b/packages/babel-parser/test/fixtures/typescript/function/declare/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/function/declare/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/function/declare/output.json b/packages/babel-parser/test/fixtures/typescript/function/declare/output.json index edf987a0149e..edd815914f2c 100644 --- a/packages/babel-parser/test/fixtures/typescript/function/declare/output.json +++ b/packages/babel-parser/test/fixtures/typescript/function/declare/output.json @@ -10,6 +10,7 @@ { "type": "TSDeclareFunction", "start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, + "declare": true, "id": { "type": "Identifier", "start":17,"end":18,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":18},"identifierName":"f"}, @@ -25,12 +26,12 @@ "type": "TSVoidKeyword", "start":22,"end":26,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":26}} } - }, - "declare": true + } }, { "type": "TSDeclareFunction", "start":28,"end":55,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":27}}, + "declare": true, "id": { "type": "Identifier", "start":45,"end":46,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":18},"identifierName":"f"}, @@ -45,7 +46,11 @@ { "type": "TSTypeParameter", "start":47,"end":48,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":20}}, - "name": "T" + "name": { + "type": "Identifier", + "start":47,"end":48,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":20},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -62,8 +67,7 @@ "name": "T" } } - }, - "declare": true + } } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/typescript/interface/generic-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/interface/generic-babel-7/input.ts new file mode 100644 index 000000000000..62f2ede348fd --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/interface/generic-babel-7/input.ts @@ -0,0 +1 @@ +interface I {} diff --git a/packages/babel-parser/test/fixtures/typescript/interface/generic-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/interface/generic-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/interface/generic-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/interface/generic-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/interface/generic-babel-7/output.json new file mode 100644 index 000000000000..7ab2f684e80c --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/interface/generic-babel-7/output.json @@ -0,0 +1,66 @@ +{ + "type": "File", + "start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":48}}, + "program": { + "type": "Program", + "start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":48}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSInterfaceDeclaration", + "start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":48}}, + "id": { + "type": "Identifier", + "start":10,"end":11,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11},"identifierName":"I"}, + "name": "I" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":11,"end":45,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":45}}, + "params": [ + { + "type": "TSTypeParameter", + "start":12,"end":44,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":44}}, + "name": "T", + "constraint": { + "type": "TSObjectKeyword", + "start":22,"end":28,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":28}} + }, + "default": { + "type": "TSTypeLiteral", + "start":31,"end":44,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":44}}, + "members": [ + { + "type": "TSPropertySignature", + "start":33,"end":42,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":42}}, + "key": { + "type": "Identifier", + "start":33,"end":34,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":34},"identifierName":"x"}, + "name": "x" + }, + "computed": false, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":34,"end":42,"loc":{"start":{"line":1,"column":34},"end":{"line":1,"column":42}}, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":36,"end":42,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":42}} + } + } + } + ] + } + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "start":46,"end":48,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":48}}, + "body": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/interface/generic/options.json b/packages/babel-parser/test/fixtures/typescript/interface/generic/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/interface/generic/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/interface/generic/output.json b/packages/babel-parser/test/fixtures/typescript/interface/generic/output.json index 7ab2f684e80c..5112dbecc737 100644 --- a/packages/babel-parser/test/fixtures/typescript/interface/generic/output.json +++ b/packages/babel-parser/test/fixtures/typescript/interface/generic/output.json @@ -22,7 +22,11 @@ { "type": "TSTypeParameter", "start":12,"end":44,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":44}}, - "name": "T", + "name": { + "type": "Identifier", + "start":12,"end":13,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":13},"identifierName":"T"}, + "name": "T" + }, "constraint": { "type": "TSObjectKeyword", "start":22,"end":28,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":28}} diff --git a/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters-babel-7/input.ts new file mode 100644 index 000000000000..085b06d811bf --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters-babel-7/input.ts @@ -0,0 +1,4 @@ +interface Foo { + get foo(): string; + set bar(v); +} diff --git a/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters-babel-7/output.json new file mode 100644 index 000000000000..0548c7796bf0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters-babel-7/output.json @@ -0,0 +1,92 @@ +{ + "type": "File", + "start":0,"end":58,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, + "errors": [ + "SyntaxError: An accessor cannot have type parameters. (2:10)", + "SyntaxError: An accessor cannot have type parameters. (3:10)" + ], + "program": { + "type": "Program", + "start":0,"end":58,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSInterfaceDeclaration", + "start":0,"end":58,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, + "id": { + "type": "Identifier", + "start":10,"end":13,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":13},"identifierName":"Foo"}, + "name": "Foo" + }, + "body": { + "type": "TSInterfaceBody", + "start":14,"end":58,"loc":{"start":{"line":1,"column":14},"end":{"line":4,"column":1}}, + "body": [ + { + "type": "TSMethodSignature", + "start":18,"end":39,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":23}}, + "key": { + "type": "Identifier", + "start":22,"end":25,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":9},"identifierName":"foo"}, + "name": "foo" + }, + "computed": false, + "kind": "get", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":25,"end":28,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12}}, + "params": [ + { + "type": "TSTypeParameter", + "start":26,"end":27,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11}}, + "name": "T" + } + ] + }, + "parameters": [], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":30,"end":38,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":22}}, + "typeAnnotation": { + "type": "TSStringKeyword", + "start":32,"end":38,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":22}} + } + } + }, + { + "type": "TSMethodSignature", + "start":42,"end":56,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":16}}, + "key": { + "type": "Identifier", + "start":46,"end":49,"loc":{"start":{"line":3,"column":6},"end":{"line":3,"column":9},"identifierName":"bar"}, + "name": "bar" + }, + "computed": false, + "kind": "set", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":49,"end":52,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":12}}, + "params": [ + { + "type": "TSTypeParameter", + "start":50,"end":51,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":11}}, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start":53,"end":54,"loc":{"start":{"line":3,"column":13},"end":{"line":3,"column":14},"identifierName":"v"}, + "name": "v" + } + ] + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters/options.json b/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters/output.json b/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters/output.json index 0548c7796bf0..c7bd340a73ae 100644 --- a/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters/output.json +++ b/packages/babel-parser/test/fixtures/typescript/interface/get-set-type-parameters/output.json @@ -40,7 +40,11 @@ { "type": "TSTypeParameter", "start":26,"end":27,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11}}, - "name": "T" + "name": { + "type": "Identifier", + "start":26,"end":27,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -71,7 +75,11 @@ { "type": "TSTypeParameter", "start":50,"end":51,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":11}}, - "name": "T" + "name": { + "type": "Identifier", + "start":50,"end":51,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":11},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/interface/method-generic-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/interface/method-generic-babel-7/input.ts new file mode 100644 index 000000000000..27f962006e43 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/interface/method-generic-babel-7/input.ts @@ -0,0 +1,3 @@ +interface I { + m(): T; +} diff --git a/packages/babel-parser/test/fixtures/typescript/interface/method-generic-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/interface/method-generic-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/interface/method-generic-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/interface/method-generic-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/interface/method-generic-babel-7/output.json new file mode 100644 index 000000000000..36810e05164b --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/interface/method-generic-babel-7/output.json @@ -0,0 +1,92 @@ +{ + "type": "File", + "start":0,"end":61,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":61,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSInterfaceDeclaration", + "start":0,"end":61,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":10,"end":11,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11},"identifierName":"I"}, + "name": "I" + }, + "body": { + "type": "TSInterfaceBody", + "start":12,"end":61,"loc":{"start":{"line":1,"column":12},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "TSMethodSignature", + "start":18,"end":59,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":45}}, + "key": { + "type": "Identifier", + "start":18,"end":19,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":5},"identifierName":"m"}, + "name": "m" + }, + "computed": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":19,"end":53,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":39}}, + "params": [ + { + "type": "TSTypeParameter", + "start":20,"end":52,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":38}}, + "name": "T", + "constraint": { + "type": "TSObjectKeyword", + "start":30,"end":36,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":22}} + }, + "default": { + "type": "TSTypeLiteral", + "start":39,"end":52,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":38}}, + "members": [ + { + "type": "TSPropertySignature", + "start":41,"end":50,"loc":{"start":{"line":2,"column":27},"end":{"line":2,"column":36}}, + "key": { + "type": "Identifier", + "start":41,"end":42,"loc":{"start":{"line":2,"column":27},"end":{"line":2,"column":28},"identifierName":"x"}, + "name": "x" + }, + "computed": false, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":42,"end":50,"loc":{"start":{"line":2,"column":28},"end":{"line":2,"column":36}}, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":44,"end":50,"loc":{"start":{"line":2,"column":30},"end":{"line":2,"column":36}} + } + } + } + ] + } + } + ] + }, + "parameters": [], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":55,"end":58,"loc":{"start":{"line":2,"column":41},"end":{"line":2,"column":44}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":57,"end":58,"loc":{"start":{"line":2,"column":43},"end":{"line":2,"column":44}}, + "typeName": { + "type": "Identifier", + "start":57,"end":58,"loc":{"start":{"line":2,"column":43},"end":{"line":2,"column":44},"identifierName":"T"}, + "name": "T" + } + } + }, + "kind": "method" + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/interface/method-generic/options.json b/packages/babel-parser/test/fixtures/typescript/interface/method-generic/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/interface/method-generic/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/interface/method-generic/output.json b/packages/babel-parser/test/fixtures/typescript/interface/method-generic/output.json index 36810e05164b..cc753d17cd14 100644 --- a/packages/babel-parser/test/fixtures/typescript/interface/method-generic/output.json +++ b/packages/babel-parser/test/fixtures/typescript/interface/method-generic/output.json @@ -35,7 +35,11 @@ { "type": "TSTypeParameter", "start":20,"end":52,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":38}}, - "name": "T", + "name": { + "type": "Identifier", + "start":20,"end":21,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":7},"identifierName":"T"}, + "name": "T" + }, "constraint": { "type": "TSObjectKeyword", "start":30,"end":36,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":22}} diff --git a/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560-babel-7/input.ts new file mode 100644 index 000000000000..2f1c5ce9190a --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560-babel-7/input.ts @@ -0,0 +1,8 @@ +class Cl { + a = async() => { + await 0; + }; + + b = async() => { + }; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560-babel-7/options.json new file mode 100644 index 000000000000..ef2637d63269 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560-babel-7/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["typescript", "classProperties"], + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560-babel-7/output.json new file mode 100644 index 000000000000..967a411d65cf --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560-babel-7/output.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start":0,"end":80,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":80,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":80,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":8,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":8},"identifierName":"Cl"}, + "name": "Cl" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":9,"end":80,"loc":{"start":{"line":1,"column":9},"end":{"line":8,"column":1}}, + "body": [ + { + "type": "ClassProperty", + "start":13,"end":50,"loc":{"start":{"line":2,"column":2},"end":{"line":4,"column":4}}, + "static": false, + "key": { + "type": "Identifier", + "start":13,"end":14,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":3},"identifierName":"a"}, + "name": "a" + }, + "computed": false, + "value": { + "type": "ArrowFunctionExpression", + "start":17,"end":49,"loc":{"start":{"line":2,"column":6},"end":{"line":4,"column":3}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":22,"end":25,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":14}}, + "params": [ + { + "type": "TSTypeParameter", + "start":23,"end":24,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":13}}, + "name": "T" + } + ] + }, + "params": [], + "id": null, + "generator": false, + "async": true, + "body": { + "type": "BlockStatement", + "start":31,"end":49,"loc":{"start":{"line":2,"column":20},"end":{"line":4,"column":3}}, + "body": [ + { + "type": "ExpressionStatement", + "start":37,"end":45,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":12}}, + "expression": { + "type": "AwaitExpression", + "start":37,"end":44,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":11}}, + "argument": { + "type": "NumericLiteral", + "start":43,"end":44,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":11}}, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + } + ], + "directives": [] + } + } + }, + { + "type": "ClassProperty", + "start":54,"end":78,"loc":{"start":{"line":6,"column":2},"end":{"line":7,"column":4}}, + "static": false, + "key": { + "type": "Identifier", + "start":54,"end":55,"loc":{"start":{"line":6,"column":2},"end":{"line":6,"column":3},"identifierName":"b"}, + "name": "b" + }, + "computed": false, + "value": { + "type": "ArrowFunctionExpression", + "start":58,"end":77,"loc":{"start":{"line":6,"column":6},"end":{"line":7,"column":3}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":63,"end":66,"loc":{"start":{"line":6,"column":11},"end":{"line":6,"column":14}}, + "params": [ + { + "type": "TSTypeParameter", + "start":64,"end":65,"loc":{"start":{"line":6,"column":12},"end":{"line":6,"column":13}}, + "name": "T" + } + ] + }, + "params": [], + "id": null, + "generator": false, + "async": true, + "body": { + "type": "BlockStatement", + "start":72,"end":77,"loc":{"start":{"line":6,"column":20},"end":{"line":7,"column":3}}, + "body": [], + "directives": [] + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560/options.json b/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560/options.json index 5047d6993fe8..3645e6af68bf 100644 --- a/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560/options.json +++ b/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560/options.json @@ -1,3 +1,4 @@ { - "plugins": ["typescript"] + "plugins": ["typescript"], + "BABEL_8_BREAKING": true } diff --git a/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560/output.json b/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560/output.json index 967a411d65cf..6b34a208690a 100644 --- a/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560/output.json +++ b/packages/babel-parser/test/fixtures/typescript/regression/async-arrow-generic-9560/output.json @@ -40,7 +40,11 @@ { "type": "TSTypeParameter", "start":23,"end":24,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":13}}, - "name": "T" + "name": { + "type": "Identifier", + "start":23,"end":24,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":13},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -94,7 +98,11 @@ { "type": "TSTypeParameter", "start":64,"end":65,"loc":{"start":{"line":6,"column":12},"end":{"line":6,"column":13}}, - "name": "T" + "name": { + "type": "Identifier", + "start":64,"end":65,"loc":{"start":{"line":6,"column":12},"end":{"line":6,"column":13},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/regression/issue-7742-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742-babel-7/input.ts new file mode 100644 index 000000000000..f347dca73764 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742-babel-7/input.ts @@ -0,0 +1,3 @@ +interface Foo { + (bar: G): T; +} diff --git a/packages/babel-parser/test/fixtures/typescript/regression/issue-7742-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742-babel-7/options.json new file mode 100644 index 000000000000..2574739d0f52 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742-babel-7/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["typescript", "jsx"], + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/regression/issue-7742-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742-babel-7/output.json new file mode 100644 index 000000000000..dee491112796 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742-babel-7/output.json @@ -0,0 +1,87 @@ +{ + "type": "File", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSInterfaceDeclaration", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":10,"end":13,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":13},"identifierName":"Foo"}, + "name": "Foo" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":13,"end":16,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":16}}, + "params": [ + { + "type": "TSTypeParameter", + "start":14,"end":15,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":15}}, + "name": "G" + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "start":17,"end":40,"loc":{"start":{"line":1,"column":17},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "TSCallSignatureDeclaration", + "start":23,"end":38,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":19}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":23,"end":26,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":7}}, + "params": [ + { + "type": "TSTypeParameter", + "start":24,"end":25,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":6}}, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start":27,"end":33,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":14},"identifierName":"bar"}, + "name": "bar", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":30,"end":33,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":14}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":32,"end":33,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":14}}, + "typeName": { + "type": "Identifier", + "start":32,"end":33,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":14},"identifierName":"G"}, + "name": "G" + } + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":34,"end":37,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":18}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":36,"end":37,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":18}}, + "typeName": { + "type": "Identifier", + "start":36,"end":37,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":18},"identifierName":"T"}, + "name": "T" + } + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/options.json b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/options.json index a0f82d16f05f..91a0075c3e69 100644 --- a/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/options.json +++ b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/options.json @@ -1,4 +1,5 @@ { "sourceType": "module", - "plugins": ["typescript", "jsx"] + "plugins": ["typescript", "jsx"], + "BABEL_8_BREAKING": true } diff --git a/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/output.json b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/output.json index dee491112796..ab9b0f495e05 100644 --- a/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/output.json +++ b/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/output.json @@ -22,7 +22,11 @@ { "type": "TSTypeParameter", "start":14,"end":15,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":15}}, - "name": "G" + "name": { + "type": "Identifier", + "start":14,"end":15,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":15},"identifierName":"G"}, + "name": "G" + } } ] }, @@ -40,7 +44,11 @@ { "type": "TSTypeParameter", "start":24,"end":25,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":6}}, - "name": "T" + "name": { + "type": "Identifier", + "start":24,"end":25,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":6},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator-babel-7/input.ts new file mode 100644 index 000000000000..33ce49c1f4a6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator-babel-7/input.ts @@ -0,0 +1,3 @@ +const fn = function* (input: T): Generator { + yield 2; +} diff --git a/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator-babel-7/output.json new file mode 100644 index 000000000000..b48b432ce19a --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator-babel-7/output.json @@ -0,0 +1,115 @@ +{ + "type": "File", + "start":0,"end":68,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":68,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":68,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":6,"end":68,"loc":{"start":{"line":1,"column":6},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":8,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":8},"identifierName":"fn"}, + "name": "fn" + }, + "init": { + "type": "FunctionExpression", + "start":11,"end":68,"loc":{"start":{"line":1,"column":11},"end":{"line":3,"column":1}}, + "id": null, + "generator": true, + "async": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":21,"end":24,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":24}}, + "params": [ + { + "type": "TSTypeParameter", + "start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23}}, + "name": "T" + } + ] + }, + "params": [ + { + "type": "Identifier", + "start":25,"end":33,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":33},"identifierName":"input"}, + "name": "input", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":30,"end":33,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":33}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":32,"end":33,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":33}}, + "typeName": { + "type": "Identifier", + "start":32,"end":33,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":33},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "start":34,"end":53,"loc":{"start":{"line":1,"column":34},"end":{"line":1,"column":53}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":36,"end":53,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":53}}, + "typeName": { + "type": "Identifier", + "start":36,"end":45,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":45},"identifierName":"Generator"}, + "name": "Generator" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":45,"end":53,"loc":{"start":{"line":1,"column":45},"end":{"line":1,"column":53}}, + "params": [ + { + "type": "TSNumberKeyword", + "start":46,"end":52,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":52}} + } + ] + } + } + }, + "body": { + "type": "BlockStatement", + "start":54,"end":68,"loc":{"start":{"line":1,"column":54},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ExpressionStatement", + "start":58,"end":66,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":10}}, + "expression": { + "type": "YieldExpression", + "start":58,"end":65,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":9}}, + "delegate": false, + "argument": { + "type": "NumericLiteral", + "start":64,"end":65,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":9}}, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + ], + "directives": [] + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator/options.json b/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator/output.json b/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator/output.json index b48b432ce19a..176fc3d5efc6 100644 --- a/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator/output.json +++ b/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator/output.json @@ -32,7 +32,11 @@ { "type": "TSTypeParameter", "start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23}}, - "name": "T" + "name": { + "type": "Identifier", + "start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters-babel-7/input.ts new file mode 100644 index 000000000000..ce70d2452609 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters-babel-7/input.ts @@ -0,0 +1 @@ +function f(): () => number {} diff --git a/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters-babel-7/output.json new file mode 100644 index 000000000000..f4a610d0d307 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters-babel-7/output.json @@ -0,0 +1,59 @@ +{ + "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": "FunctionDeclaration", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}}, + "id": { + "type": "Identifier", + "start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": false, + "params": [], + "returnType": { + "type": "TSTypeAnnotation", + "start":12,"end":29,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":29}}, + "typeAnnotation": { + "type": "TSFunctionType", + "start":14,"end":29,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":29}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":14,"end":17,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":17}}, + "params": [ + { + "type": "TSTypeParameter", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":16}}, + "name": "T" + } + ] + }, + "parameters": [], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":20,"end":29,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":29}}, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":23,"end":29,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":29}} + } + } + } + }, + "body": { + "type": "BlockStatement", + "start":30,"end":32,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":32}}, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters/options.json b/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters/output.json b/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters/output.json index f4a610d0d307..31b54c353dc5 100644 --- a/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters/output.json +++ b/packages/babel-parser/test/fixtures/typescript/tsx/type-parameters/output.json @@ -31,7 +31,11 @@ { "type": "TSTypeParameter", "start":15,"end":16,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":16}}, - "name": "T" + "name": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":16},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/input.ts new file mode 100644 index 000000000000..0e910abfc66e --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/input.ts @@ -0,0 +1 @@ +type T = U; diff --git a/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/output.json new file mode 100644 index 000000000000..436c0c9bfea0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/output.json @@ -0,0 +1,42 @@ +{ + "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": "module", + "interpreter": null, + "body": [ + { + "type": "TSTypeAliasDeclaration", + "start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}}, + "id": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"T"}, + "name": "T" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9}}, + "params": [ + { + "type": "TSTypeParameter", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}}, + "name": "U" + } + ] + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start":12,"end":13,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":13}}, + "typeName": { + "type": "Identifier", + "start":12,"end":13,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":13},"identifierName":"U"}, + "name": "U" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true-babel-7/input.ts new file mode 100644 index 000000000000..9fb8928d4fc1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true-babel-7/input.ts @@ -0,0 +1 @@ +type T = Array; diff --git a/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true-babel-7/options.json new file mode 100644 index 000000000000..5dfb10823c71 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true-babel-7/options.json @@ -0,0 +1,6 @@ +{ + "sourceType": "module", + "plugins": ["typescript"], + "tokens": true, + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true-babel-7/output.json new file mode 100644 index 000000000000..0fccbaf3b2ec --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true-babel-7/output.json @@ -0,0 +1,401 @@ +{ + "type": "File", + "start":0,"end":52,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":52}}, + "program": { + "type": "Program", + "start":0,"end":52,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":52}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSTypeAliasDeclaration", + "start":0,"end":52,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":52}}, + "id": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"T"}, + "name": "T" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":6,"end":40,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":40}}, + "params": [ + { + "type": "TSTypeParameter", + "start":7,"end":39,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":39}}, + "name": "U", + "constraint": { + "type": "TSObjectKeyword", + "start":17,"end":23,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":23}} + }, + "default": { + "type": "TSTypeLiteral", + "start":26,"end":39,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":39}}, + "members": [ + { + "type": "TSPropertySignature", + "start":28,"end":37,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":37}}, + "key": { + "type": "Identifier", + "start":28,"end":29,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":29},"identifierName":"x"}, + "name": "x" + }, + "computed": false, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":29,"end":37,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":37}}, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":31,"end":37,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":37}} + } + } + } + ] + } + } + ] + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start":43,"end":51,"loc":{"start":{"line":1,"column":43},"end":{"line":1,"column":51}}, + "typeName": { + "type": "Identifier", + "start":43,"end":48,"loc":{"start":{"line":1,"column":43},"end":{"line":1,"column":48},"identifierName":"Array"}, + "name": "Array" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":48,"end":51,"loc":{"start":{"line":1,"column":48},"end":{"line":1,"column":51}}, + "params": [ + { + "type": "TSTypeReference", + "start":49,"end":50,"loc":{"start":{"line":1,"column":49},"end":{"line":1,"column":50}}, + "typeName": { + "type": "Identifier", + "start":49,"end":50,"loc":{"start":{"line":1,"column":49},"end":{"line":1,"column":50},"identifierName":"U"}, + "name": "U" + } + } + ] + } + } + } + ], + "directives": [] + }, + "tokens": [ + { + "type": { + "label": "name", + "beforeExpr": false, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "type", + "start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}} + }, + { + "type": { + "label": "name", + "beforeExpr": false, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "T", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6}} + }, + { + "type": { + "label": "/<=/>=", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": 7, + "updateContext": null + }, + "value": "<", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7}} + }, + { + "type": { + "label": "name", + "beforeExpr": false, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "U", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}} + }, + { + "type": { + "label": "extends", + "keyword": "extends", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "extends", + "start":9,"end":16,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":16}} + }, + { + "type": { + "label": "name", + "beforeExpr": false, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "object", + "start":17,"end":23,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":23}} + }, + { + "type": { + "label": "=", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": true, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "=", + "start":24,"end":25,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":25}} + }, + { + "type": { + "label": "{", + "beforeExpr": true, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null + }, + "start":26,"end":27,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":27}} + }, + { + "type": { + "label": "name", + "beforeExpr": false, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "x", + "start":28,"end":29,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":29}} + }, + { + "type": { + "label": ":", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "start":29,"end":30,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":30}} + }, + { + "type": { + "label": "name", + "beforeExpr": false, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "number", + "start":31,"end":37,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":37}} + }, + { + "type": { + "label": "}", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null + }, + "start":38,"end":39,"loc":{"start":{"line":1,"column":38},"end":{"line":1,"column":39}} + }, + { + "type": { + "label": "/<=/>=", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": 7, + "updateContext": null + }, + "value": ">", + "start":39,"end":40,"loc":{"start":{"line":1,"column":39},"end":{"line":1,"column":40}} + }, + { + "type": { + "label": "=", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": true, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "=", + "start":41,"end":42,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":42}} + }, + { + "type": { + "label": "name", + "beforeExpr": false, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "Array", + "start":43,"end":48,"loc":{"start":{"line":1,"column":43},"end":{"line":1,"column":48}} + }, + { + "type": { + "label": "/<=/>=", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": 7, + "updateContext": null + }, + "value": "<", + "start":48,"end":49,"loc":{"start":{"line":1,"column":48},"end":{"line":1,"column":49}} + }, + { + "type": { + "label": "name", + "beforeExpr": false, + "startsExpr": true, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "value": "U", + "start":49,"end":50,"loc":{"start":{"line":1,"column":49},"end":{"line":1,"column":50}} + }, + { + "type": { + "label": "/<=/>=", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": 7, + "updateContext": null + }, + "value": ">", + "start":50,"end":51,"loc":{"start":{"line":1,"column":50},"end":{"line":1,"column":51}} + }, + { + "type": { + "label": ";", + "beforeExpr": true, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "start":51,"end":52,"loc":{"start":{"line":1,"column":51},"end":{"line":1,"column":52}} + }, + { + "type": { + "label": "eof", + "beforeExpr": false, + "startsExpr": false, + "rightAssociative": false, + "isLoop": false, + "isAssign": false, + "prefix": false, + "postfix": false, + "binop": null, + "updateContext": null + }, + "start":52,"end":52,"loc":{"start":{"line":1,"column":52},"end":{"line":1,"column":52}} + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true/options.json b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true/options.json index 359dbf5e9514..d428f4684767 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true/options.json +++ b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true/options.json @@ -1,5 +1,6 @@ { "sourceType": "module", "plugins": ["typescript"], - "tokens": true + "tokens": true, + "BABEL_8_BREAKING": true } diff --git a/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true/output.json b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true/output.json index 0fccbaf3b2ec..e6ed3d9fbc82 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-complex-tokens-true/output.json @@ -22,7 +22,11 @@ { "type": "TSTypeParameter", "start":7,"end":39,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":39}}, - "name": "U", + "name": { + "type": "Identifier", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"U"}, + "name": "U" + }, "constraint": { "type": "TSObjectKeyword", "start":17,"end":23,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":23}} diff --git a/packages/babel-parser/test/fixtures/typescript/type-alias/generic/options.json b/packages/babel-parser/test/fixtures/typescript/type-alias/generic/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-alias/generic/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-alias/generic/output.json b/packages/babel-parser/test/fixtures/typescript/type-alias/generic/output.json index 436c0c9bfea0..e206b9b5aceb 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-alias/generic/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-alias/generic/output.json @@ -22,7 +22,11 @@ { "type": "TSTypeParameter", "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}}, - "name": "U" + "name": { + "type": "Identifier", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"U"}, + "name": "U" + } } ] }, @@ -39,4 +43,4 @@ ], "directives": [] } -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace-babel-7/input.ts new file mode 100644 index 000000000000..56d367c193d4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace-babel-7/input.ts @@ -0,0 +1 @@ +function f< T >() {} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace-babel-7/output.json new file mode 100644 index 000000000000..503d9fd01ccf --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace-babel-7/output.json @@ -0,0 +1,42 @@ +{ + "type": "File", + "start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}}, + "program": { + "type": "Program", + "start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}}, + "id": { + "type": "Identifier", + "start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10},"identifierName":"f"}, + "name": "f" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":10,"end":19,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":19}}, + "params": [ + { + "type": "TSTypeParameter", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14}}, + "name": "T" + } + ] + }, + "params": [], + "body": { + "type": "BlockStatement", + "start":22,"end":24,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":24}}, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace/output.json index 503d9fd01ccf..576bef62ca1b 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/whitespace/output.json @@ -24,7 +24,11 @@ { "type": "TSTypeParameter", "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14}}, - "name": "T" + "name": { + "type": "Identifier", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/types/conditional-infer-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/types/conditional-infer-babel-7/input.ts new file mode 100644 index 000000000000..fc9bc48546e6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/conditional-infer-babel-7/input.ts @@ -0,0 +1 @@ +type Element = T extends (infer U)[] ? U : T; diff --git a/packages/babel-parser/test/fixtures/typescript/types/conditional-infer-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/types/conditional-infer-babel-7/options.json new file mode 100644 index 000000000000..44a5d447f014 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/conditional-infer-babel-7/options.json @@ -0,0 +1,5 @@ +{ + "plugins": ["typescript"], + "createParenthesizedExpressions": true, + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/conditional-infer-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/types/conditional-infer-babel-7/output.json new file mode 100644 index 000000000000..72dae30c84ec --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/conditional-infer-babel-7/output.json @@ -0,0 +1,81 @@ +{ + "type": "File", + "start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":48}}, + "program": { + "type": "Program", + "start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":48}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSTypeAliasDeclaration", + "start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":48}}, + "id": { + "type": "Identifier", + "start":5,"end":12,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":12},"identifierName":"Element"}, + "name": "Element" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":12,"end":15,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":15}}, + "params": [ + { + "type": "TSTypeParameter", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14}}, + "name": "T" + } + ] + }, + "typeAnnotation": { + "type": "TSConditionalType", + "start":18,"end":47,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":47}}, + "checkType": { + "type": "TSTypeReference", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19}}, + "typeName": { + "type": "Identifier", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19},"identifierName":"T"}, + "name": "T" + } + }, + "extendsType": { + "type": "TSArrayType", + "start":28,"end":39,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":39}}, + "elementType": { + "type": "TSParenthesizedType", + "start":28,"end":37,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":37}}, + "typeAnnotation": { + "type": "TSInferType", + "start":29,"end":36,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":36}}, + "typeParameter": { + "type": "TSTypeParameter", + "start":35,"end":36,"loc":{"start":{"line":1,"column":35},"end":{"line":1,"column":36}}, + "name": "U" + } + } + } + }, + "trueType": { + "type": "TSTypeReference", + "start":42,"end":43,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":43}}, + "typeName": { + "type": "Identifier", + "start":42,"end":43,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":43},"identifierName":"U"}, + "name": "U" + } + }, + "falseType": { + "type": "TSTypeReference", + "start":46,"end":47,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":47}}, + "typeName": { + "type": "Identifier", + "start":46,"end":47,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":47},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/types/conditional-infer/options.json b/packages/babel-parser/test/fixtures/typescript/types/conditional-infer/options.json index 6c000354211c..d23b5d2af90e 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/conditional-infer/options.json +++ b/packages/babel-parser/test/fixtures/typescript/types/conditional-infer/options.json @@ -1,4 +1,5 @@ { "plugins": ["typescript"], - "createParenthesizedExpressions": true + "createParenthesizedExpressions": true, + "BABEL_8_BREAKING": true } diff --git a/packages/babel-parser/test/fixtures/typescript/types/conditional-infer/output.json b/packages/babel-parser/test/fixtures/typescript/types/conditional-infer/output.json index 72dae30c84ec..823f7c25b9fe 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/conditional-infer/output.json +++ b/packages/babel-parser/test/fixtures/typescript/types/conditional-infer/output.json @@ -22,7 +22,11 @@ { "type": "TSTypeParameter", "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14}}, - "name": "T" + "name": { + "type": "Identifier", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -50,7 +54,11 @@ "typeParameter": { "type": "TSTypeParameter", "start":35,"end":36,"loc":{"start":{"line":1,"column":35},"end":{"line":1,"column":36}}, - "name": "U" + "name": { + "type": "Identifier", + "start":35,"end":36,"loc":{"start":{"line":1,"column":35},"end":{"line":1,"column":36},"identifierName":"U"}, + "name": "U" + } } } } diff --git a/packages/babel-parser/test/fixtures/typescript/types/function-generic-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/types/function-generic-babel-7/input.ts new file mode 100644 index 000000000000..61d8ece714c9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/function-generic-babel-7/input.ts @@ -0,0 +1 @@ +let f: (a: T) => T; diff --git a/packages/babel-parser/test/fixtures/typescript/types/function-generic-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/types/function-generic-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/function-generic-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/function-generic-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/types/function-generic-babel-7/output.json new file mode 100644 index 000000000000..e359150e7331 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/function-generic-babel-7/output.json @@ -0,0 +1,82 @@ +{ + "type": "File", + "start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}}, + "program": { + "type": "Program", + "start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}}, + "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":4,"end":21,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":21}}, + "id": { + "type": "Identifier", + "start":4,"end":21,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":21},"identifierName":"f"}, + "name": "f", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":5,"end":21,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":21}}, + "typeAnnotation": { + "type": "TSFunctionType", + "start":7,"end":21,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":21}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}}, + "params": [ + { + "type": "TSTypeParameter", + "start":8,"end":9,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":9}}, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start":11,"end":15,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":15},"identifierName":"a"}, + "name": "a", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":12,"end":15,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":15}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":14,"end":15,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":15}}, + "typeName": { + "type": "Identifier", + "start":14,"end":15,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":15},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":17,"end":21,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":21}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":20,"end":21,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":21}}, + "typeName": { + "type": "Identifier", + "start":20,"end":21,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":21},"identifierName":"T"}, + "name": "T" + } + } + } + } + } + }, + "init": null + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/types/function-generic/options.json b/packages/babel-parser/test/fixtures/typescript/types/function-generic/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/function-generic/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/function-generic/output.json b/packages/babel-parser/test/fixtures/typescript/types/function-generic/output.json index e359150e7331..4233036c87be 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/function-generic/output.json +++ b/packages/babel-parser/test/fixtures/typescript/types/function-generic/output.json @@ -31,7 +31,11 @@ { "type": "TSTypeParameter", "start":8,"end":9,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":9}}, - "name": "T" + "name": { + "type": "Identifier", + "start":8,"end":9,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":9},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword-babel-7/input.ts new file mode 100644 index 000000000000..943c60afcbb6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword-babel-7/input.ts @@ -0,0 +1,2 @@ +type Foo = intrinsic; +type Bar = intrinsic; diff --git a/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword-babel-7/output.json new file mode 100644 index 000000000000..9b61e78eb132 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword-babel-7/output.json @@ -0,0 +1,50 @@ +{ + "type": "File", + "start":0,"end":46,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":24}}, + "program": { + "type": "Program", + "start":0,"end":46,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":24}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSTypeAliasDeclaration", + "start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":21}}, + "id": { + "type": "Identifier", + "start":5,"end":8,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":8},"identifierName":"Foo"}, + "name": "Foo" + }, + "typeAnnotation": { + "type": "TSIntrinsicKeyword", + "start":11,"end":20,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":20}} + } + }, + { + "type": "TSTypeAliasDeclaration", + "start":22,"end":46,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":24}}, + "id": { + "type": "Identifier", + "start":27,"end":30,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":8},"identifierName":"Bar"}, + "name": "Bar" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":30,"end":33,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":11}}, + "params": [ + { + "type": "TSTypeParameter", + "start":31,"end":32,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":10}}, + "name": "T" + } + ] + }, + "typeAnnotation": { + "type": "TSIntrinsicKeyword", + "start":36,"end":45,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":23}} + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword/options.json b/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword/output.json b/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword/output.json index 9b61e78eb132..a77569ec5229 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword/output.json +++ b/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword/output.json @@ -35,7 +35,11 @@ { "type": "TSTypeParameter", "start":31,"end":32,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":10}}, - "name": "T" + "name": { + "type": "Identifier", + "start":31,"end":32,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":10},"identifierName":"T"}, + "name": "T" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/typescript/types/literal-string-4-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/types/literal-string-4-babel-7/input.ts new file mode 100644 index 000000000000..020b98d485d3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/literal-string-4-babel-7/input.ts @@ -0,0 +1 @@ +let x: `foo-${infer bar}`; diff --git a/packages/babel-parser/test/fixtures/typescript/types/literal-string-4-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/types/literal-string-4-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/literal-string-4-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/literal-string-4-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/types/literal-string-4-babel-7/output.json new file mode 100644 index 000000000000..5bc58ae9d4ba --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/literal-string-4-babel-7/output.json @@ -0,0 +1,73 @@ +{ + "type": "File", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, + "program": { + "type": "Program", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":4,"end":25,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":25}}, + "id": { + "type": "Identifier", + "start":4,"end":25,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":25},"identifierName":"x"}, + "name": "x", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":5,"end":25,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":25}}, + "typeAnnotation": { + "type": "TSLiteralType", + "start":7,"end":25,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":25}}, + "literal": { + "type": "TemplateLiteral", + "start":7,"end":25,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":25}}, + "expressions": [ + { + "type": "TSInferType", + "start":14,"end":23,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":23}}, + "typeParameter": { + "type": "TSTypeParameter", + "start":20,"end":23,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":23}}, + "name": "bar" + } + } + ], + "quasis": [ + { + "type": "TemplateElement", + "start":8,"end":12,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":12}}, + "value": { + "raw": "foo-", + "cooked": "foo-" + }, + "tail": false + }, + { + "type": "TemplateElement", + "start":24,"end":24,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":24}}, + "value": { + "raw": "", + "cooked": "" + }, + "tail": true + } + ] + } + } + } + }, + "init": null + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/types/literal-string-4/options.json b/packages/babel-parser/test/fixtures/typescript/types/literal-string-4/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/literal-string-4/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/literal-string-4/output.json b/packages/babel-parser/test/fixtures/typescript/types/literal-string-4/output.json index 5bc58ae9d4ba..ece1b9eadda4 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/literal-string-4/output.json +++ b/packages/babel-parser/test/fixtures/typescript/types/literal-string-4/output.json @@ -34,7 +34,11 @@ "typeParameter": { "type": "TSTypeParameter", "start":20,"end":23,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":23}}, - "name": "bar" + "name": { + "type": "Identifier", + "start":20,"end":23,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":23},"identifierName":"bar"}, + "name": "bar" + } } } ], diff --git a/packages/babel-parser/test/fixtures/typescript/types/mapped-as-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/types/mapped-as-babel-7/input.ts new file mode 100644 index 000000000000..3d2123649d0d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/mapped-as-babel-7/input.ts @@ -0,0 +1,11 @@ +type MappedTypeWithNewKeys = { + [K in keyof T as NewKeyType]: T[K] +}; + +type RemoveKindField = { + [K in keyof T as Exclude]: T[K] +}; + +type PickByValueType = { + [K in keyof T as T[K] extends U ? K : never]: T[K] +}; diff --git a/packages/babel-parser/test/fixtures/typescript/types/mapped-as-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/types/mapped-as-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/mapped-as-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/mapped-as-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/types/mapped-as-babel-7/output.json new file mode 100644 index 000000000000..3b8d16fbe15a --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/mapped-as-babel-7/output.json @@ -0,0 +1,307 @@ +{ + "type": "File", + "start":0,"end":238,"loc":{"start":{"line":1,"column":0},"end":{"line":11,"column":2}}, + "program": { + "type": "Program", + "start":0,"end":238,"loc":{"start":{"line":1,"column":0},"end":{"line":11,"column":2}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSTypeAliasDeclaration", + "start":0,"end":73,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":2}}, + "id": { + "type": "Identifier", + "start":5,"end":26,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":26},"identifierName":"MappedTypeWithNewKeys"}, + "name": "MappedTypeWithNewKeys" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":26,"end":29,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":29}}, + "params": [ + { + "type": "TSTypeParameter", + "start":27,"end":28,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":28}}, + "name": "T" + } + ] + }, + "typeAnnotation": { + "type": "TSMappedType", + "start":32,"end":72,"loc":{"start":{"line":1,"column":32},"end":{"line":3,"column":1}}, + "typeParameter": { + "type": "TSTypeParameter", + "start":37,"end":49,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":15}}, + "name": "K", + "constraint": { + "type": "TSTypeOperator", + "start":42,"end":49,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":15}}, + "operator": "keyof", + "typeAnnotation": { + "type": "TSTypeReference", + "start":48,"end":49,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":15}}, + "typeName": { + "type": "Identifier", + "start":48,"end":49,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":15},"identifierName":"T"}, + "name": "T" + } + } + } + }, + "nameType": { + "type": "TSTypeReference", + "start":53,"end":63,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":29}}, + "typeName": { + "type": "Identifier", + "start":53,"end":63,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":29},"identifierName":"NewKeyType"}, + "name": "NewKeyType" + } + }, + "typeAnnotation": { + "type": "TSIndexedAccessType", + "start":66,"end":70,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":36}}, + "objectType": { + "type": "TSTypeReference", + "start":66,"end":67,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":33}}, + "typeName": { + "type": "Identifier", + "start":66,"end":67,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":33},"identifierName":"T"}, + "name": "T" + } + }, + "indexType": { + "type": "TSTypeReference", + "start":68,"end":69,"loc":{"start":{"line":2,"column":34},"end":{"line":2,"column":35}}, + "typeName": { + "type": "Identifier", + "start":68,"end":69,"loc":{"start":{"line":2,"column":34},"end":{"line":2,"column":35},"identifierName":"K"}, + "name": "K" + } + } + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start":75,"end":150,"loc":{"start":{"line":5,"column":0},"end":{"line":7,"column":2}}, + "id": { + "type": "Identifier", + "start":80,"end":95,"loc":{"start":{"line":5,"column":5},"end":{"line":5,"column":20},"identifierName":"RemoveKindField"}, + "name": "RemoveKindField" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":95,"end":98,"loc":{"start":{"line":5,"column":20},"end":{"line":5,"column":23}}, + "params": [ + { + "type": "TSTypeParameter", + "start":96,"end":97,"loc":{"start":{"line":5,"column":21},"end":{"line":5,"column":22}}, + "name": "T" + } + ] + }, + "typeAnnotation": { + "type": "TSMappedType", + "start":101,"end":149,"loc":{"start":{"line":5,"column":26},"end":{"line":7,"column":1}}, + "typeParameter": { + "type": "TSTypeParameter", + "start":106,"end":118,"loc":{"start":{"line":6,"column":3},"end":{"line":6,"column":15}}, + "name": "K", + "constraint": { + "type": "TSTypeOperator", + "start":111,"end":118,"loc":{"start":{"line":6,"column":8},"end":{"line":6,"column":15}}, + "operator": "keyof", + "typeAnnotation": { + "type": "TSTypeReference", + "start":117,"end":118,"loc":{"start":{"line":6,"column":14},"end":{"line":6,"column":15}}, + "typeName": { + "type": "Identifier", + "start":117,"end":118,"loc":{"start":{"line":6,"column":14},"end":{"line":6,"column":15},"identifierName":"T"}, + "name": "T" + } + } + } + }, + "nameType": { + "type": "TSTypeReference", + "start":122,"end":140,"loc":{"start":{"line":6,"column":19},"end":{"line":6,"column":37}}, + "typeName": { + "type": "Identifier", + "start":122,"end":129,"loc":{"start":{"line":6,"column":19},"end":{"line":6,"column":26},"identifierName":"Exclude"}, + "name": "Exclude" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":129,"end":140,"loc":{"start":{"line":6,"column":26},"end":{"line":6,"column":37}}, + "params": [ + { + "type": "TSTypeReference", + "start":130,"end":131,"loc":{"start":{"line":6,"column":27},"end":{"line":6,"column":28}}, + "typeName": { + "type": "Identifier", + "start":130,"end":131,"loc":{"start":{"line":6,"column":27},"end":{"line":6,"column":28},"identifierName":"K"}, + "name": "K" + } + }, + { + "type": "TSLiteralType", + "start":133,"end":139,"loc":{"start":{"line":6,"column":30},"end":{"line":6,"column":36}}, + "literal": { + "type": "StringLiteral", + "start":133,"end":139,"loc":{"start":{"line":6,"column":30},"end":{"line":6,"column":36}}, + "extra": { + "rawValue": "kind", + "raw": "\"kind\"" + }, + "value": "kind" + } + } + ] + } + }, + "typeAnnotation": { + "type": "TSIndexedAccessType", + "start":143,"end":147,"loc":{"start":{"line":6,"column":40},"end":{"line":6,"column":44}}, + "objectType": { + "type": "TSTypeReference", + "start":143,"end":144,"loc":{"start":{"line":6,"column":40},"end":{"line":6,"column":41}}, + "typeName": { + "type": "Identifier", + "start":143,"end":144,"loc":{"start":{"line":6,"column":40},"end":{"line":6,"column":41},"identifierName":"T"}, + "name": "T" + } + }, + "indexType": { + "type": "TSTypeReference", + "start":145,"end":146,"loc":{"start":{"line":6,"column":42},"end":{"line":6,"column":43}}, + "typeName": { + "type": "Identifier", + "start":145,"end":146,"loc":{"start":{"line":6,"column":42},"end":{"line":6,"column":43},"identifierName":"K"}, + "name": "K" + } + } + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start":152,"end":238,"loc":{"start":{"line":9,"column":0},"end":{"line":11,"column":2}}, + "id": { + "type": "Identifier", + "start":157,"end":172,"loc":{"start":{"line":9,"column":5},"end":{"line":9,"column":20},"identifierName":"PickByValueType"}, + "name": "PickByValueType" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":172,"end":178,"loc":{"start":{"line":9,"column":20},"end":{"line":9,"column":26}}, + "params": [ + { + "type": "TSTypeParameter", + "start":173,"end":174,"loc":{"start":{"line":9,"column":21},"end":{"line":9,"column":22}}, + "name": "T" + }, + { + "type": "TSTypeParameter", + "start":176,"end":177,"loc":{"start":{"line":9,"column":24},"end":{"line":9,"column":25}}, + "name": "U" + } + ] + }, + "typeAnnotation": { + "type": "TSMappedType", + "start":181,"end":237,"loc":{"start":{"line":9,"column":29},"end":{"line":11,"column":1}}, + "typeParameter": { + "type": "TSTypeParameter", + "start":186,"end":198,"loc":{"start":{"line":10,"column":3},"end":{"line":10,"column":15}}, + "name": "K", + "constraint": { + "type": "TSTypeOperator", + "start":191,"end":198,"loc":{"start":{"line":10,"column":8},"end":{"line":10,"column":15}}, + "operator": "keyof", + "typeAnnotation": { + "type": "TSTypeReference", + "start":197,"end":198,"loc":{"start":{"line":10,"column":14},"end":{"line":10,"column":15}}, + "typeName": { + "type": "Identifier", + "start":197,"end":198,"loc":{"start":{"line":10,"column":14},"end":{"line":10,"column":15},"identifierName":"T"}, + "name": "T" + } + } + } + }, + "nameType": { + "type": "TSConditionalType", + "start":202,"end":228,"loc":{"start":{"line":10,"column":19},"end":{"line":10,"column":45}}, + "checkType": { + "type": "TSIndexedAccessType", + "start":202,"end":206,"loc":{"start":{"line":10,"column":19},"end":{"line":10,"column":23}}, + "objectType": { + "type": "TSTypeReference", + "start":202,"end":203,"loc":{"start":{"line":10,"column":19},"end":{"line":10,"column":20}}, + "typeName": { + "type": "Identifier", + "start":202,"end":203,"loc":{"start":{"line":10,"column":19},"end":{"line":10,"column":20},"identifierName":"T"}, + "name": "T" + } + }, + "indexType": { + "type": "TSTypeReference", + "start":204,"end":205,"loc":{"start":{"line":10,"column":21},"end":{"line":10,"column":22}}, + "typeName": { + "type": "Identifier", + "start":204,"end":205,"loc":{"start":{"line":10,"column":21},"end":{"line":10,"column":22},"identifierName":"K"}, + "name": "K" + } + } + }, + "extendsType": { + "type": "TSTypeReference", + "start":215,"end":216,"loc":{"start":{"line":10,"column":32},"end":{"line":10,"column":33}}, + "typeName": { + "type": "Identifier", + "start":215,"end":216,"loc":{"start":{"line":10,"column":32},"end":{"line":10,"column":33},"identifierName":"U"}, + "name": "U" + } + }, + "trueType": { + "type": "TSTypeReference", + "start":219,"end":220,"loc":{"start":{"line":10,"column":36},"end":{"line":10,"column":37}}, + "typeName": { + "type": "Identifier", + "start":219,"end":220,"loc":{"start":{"line":10,"column":36},"end":{"line":10,"column":37},"identifierName":"K"}, + "name": "K" + } + }, + "falseType": { + "type": "TSNeverKeyword", + "start":223,"end":228,"loc":{"start":{"line":10,"column":40},"end":{"line":10,"column":45}} + } + }, + "typeAnnotation": { + "type": "TSIndexedAccessType", + "start":231,"end":235,"loc":{"start":{"line":10,"column":48},"end":{"line":10,"column":52}}, + "objectType": { + "type": "TSTypeReference", + "start":231,"end":232,"loc":{"start":{"line":10,"column":48},"end":{"line":10,"column":49}}, + "typeName": { + "type": "Identifier", + "start":231,"end":232,"loc":{"start":{"line":10,"column":48},"end":{"line":10,"column":49},"identifierName":"T"}, + "name": "T" + } + }, + "indexType": { + "type": "TSTypeReference", + "start":233,"end":234,"loc":{"start":{"line":10,"column":50},"end":{"line":10,"column":51}}, + "typeName": { + "type": "Identifier", + "start":233,"end":234,"loc":{"start":{"line":10,"column":50},"end":{"line":10,"column":51},"identifierName":"K"}, + "name": "K" + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/types/mapped-as/options.json b/packages/babel-parser/test/fixtures/typescript/types/mapped-as/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/mapped-as/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/mapped-as/output.json b/packages/babel-parser/test/fixtures/typescript/types/mapped-as/output.json index 3b8d16fbe15a..70328595c633 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/mapped-as/output.json +++ b/packages/babel-parser/test/fixtures/typescript/types/mapped-as/output.json @@ -22,7 +22,11 @@ { "type": "TSTypeParameter", "start":27,"end":28,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":28}}, - "name": "T" + "name": { + "type": "Identifier", + "start":27,"end":28,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":28},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -32,7 +36,11 @@ "typeParameter": { "type": "TSTypeParameter", "start":37,"end":49,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":15}}, - "name": "K", + "name": { + "type": "Identifier", + "start":37,"end":38,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":4},"identifierName":"K"}, + "name": "K" + }, "constraint": { "type": "TSTypeOperator", "start":42,"end":49,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":15}}, @@ -96,7 +104,11 @@ { "type": "TSTypeParameter", "start":96,"end":97,"loc":{"start":{"line":5,"column":21},"end":{"line":5,"column":22}}, - "name": "T" + "name": { + "type": "Identifier", + "start":96,"end":97,"loc":{"start":{"line":5,"column":21},"end":{"line":5,"column":22},"identifierName":"T"}, + "name": "T" + } } ] }, @@ -106,7 +118,11 @@ "typeParameter": { "type": "TSTypeParameter", "start":106,"end":118,"loc":{"start":{"line":6,"column":3},"end":{"line":6,"column":15}}, - "name": "K", + "name": { + "type": "Identifier", + "start":106,"end":107,"loc":{"start":{"line":6,"column":3},"end":{"line":6,"column":4},"identifierName":"K"}, + "name": "K" + }, "constraint": { "type": "TSTypeOperator", "start":111,"end":118,"loc":{"start":{"line":6,"column":8},"end":{"line":6,"column":15}}, @@ -198,12 +214,20 @@ { "type": "TSTypeParameter", "start":173,"end":174,"loc":{"start":{"line":9,"column":21},"end":{"line":9,"column":22}}, - "name": "T" + "name": { + "type": "Identifier", + "start":173,"end":174,"loc":{"start":{"line":9,"column":21},"end":{"line":9,"column":22},"identifierName":"T"}, + "name": "T" + } }, { "type": "TSTypeParameter", "start":176,"end":177,"loc":{"start":{"line":9,"column":24},"end":{"line":9,"column":25}}, - "name": "U" + "name": { + "type": "Identifier", + "start":176,"end":177,"loc":{"start":{"line":9,"column":24},"end":{"line":9,"column":25},"identifierName":"U"}, + "name": "U" + } } ] }, @@ -213,7 +237,11 @@ "typeParameter": { "type": "TSTypeParameter", "start":186,"end":198,"loc":{"start":{"line":10,"column":3},"end":{"line":10,"column":15}}, - "name": "K", + "name": { + "type": "Identifier", + "start":186,"end":187,"loc":{"start":{"line":10,"column":3},"end":{"line":10,"column":4},"identifierName":"K"}, + "name": "K" + }, "constraint": { "type": "TSTypeOperator", "start":191,"end":198,"loc":{"start":{"line":10,"column":8},"end":{"line":10,"column":15}}, diff --git a/packages/babel-parser/test/fixtures/typescript/types/mapped-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/types/mapped-babel-7/input.ts new file mode 100644 index 000000000000..4ea2b0c8a9a4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/mapped-babel-7/input.ts @@ -0,0 +1,4 @@ +let map1: { [P in string]: number; }; +let map2: { readonly [P in string]?: number; }; +let map3: { +readonly [P in string]+?: number; }; +let map4: { -readonly [P in string]-?: number }; diff --git a/packages/babel-parser/test/fixtures/typescript/types/mapped-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/types/mapped-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/mapped-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/mapped-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/types/mapped-babel-7/output.json new file mode 100644 index 000000000000..47f82fab7476 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/mapped-babel-7/output.json @@ -0,0 +1,175 @@ +{ + "type": "File", + "start":0,"end":184,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":48}}, + "program": { + "type": "Program", + "start":0,"end":184,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":48}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":37}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":4,"end":36,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":36}}, + "id": { + "type": "Identifier", + "start":4,"end":36,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":36},"identifierName":"map1"}, + "name": "map1", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":8,"end":36,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":36}}, + "typeAnnotation": { + "type": "TSMappedType", + "start":10,"end":36,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":36}}, + "typeParameter": { + "type": "TSTypeParameter", + "start":13,"end":24,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":24}}, + "name": "P", + "constraint": { + "type": "TSStringKeyword", + "start":18,"end":24,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":24}} + } + }, + "nameType": null, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":27,"end":33,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":33}} + } + } + } + }, + "init": null + } + ], + "kind": "let" + }, + { + "type": "VariableDeclaration", + "start":38,"end":85,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":47}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":42,"end":84,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":46}}, + "id": { + "type": "Identifier", + "start":42,"end":84,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":46},"identifierName":"map2"}, + "name": "map2", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":46,"end":84,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":46}}, + "typeAnnotation": { + "type": "TSMappedType", + "start":48,"end":84,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":46}}, + "readonly": true, + "typeParameter": { + "type": "TSTypeParameter", + "start":60,"end":71,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":33}}, + "name": "P", + "constraint": { + "type": "TSStringKeyword", + "start":65,"end":71,"loc":{"start":{"line":2,"column":27},"end":{"line":2,"column":33}} + } + }, + "nameType": null, + "optional": true, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":75,"end":81,"loc":{"start":{"line":2,"column":37},"end":{"line":2,"column":43}} + } + } + } + }, + "init": null + } + ], + "kind": "let" + }, + { + "type": "VariableDeclaration", + "start":86,"end":135,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":49}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":90,"end":134,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":48}}, + "id": { + "type": "Identifier", + "start":90,"end":134,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":48},"identifierName":"map3"}, + "name": "map3", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":94,"end":134,"loc":{"start":{"line":3,"column":8},"end":{"line":3,"column":48}}, + "typeAnnotation": { + "type": "TSMappedType", + "start":96,"end":134,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":48}}, + "readonly": "+", + "typeParameter": { + "type": "TSTypeParameter", + "start":109,"end":120,"loc":{"start":{"line":3,"column":23},"end":{"line":3,"column":34}}, + "name": "P", + "constraint": { + "type": "TSStringKeyword", + "start":114,"end":120,"loc":{"start":{"line":3,"column":28},"end":{"line":3,"column":34}} + } + }, + "nameType": null, + "optional": "+", + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":125,"end":131,"loc":{"start":{"line":3,"column":39},"end":{"line":3,"column":45}} + } + } + } + }, + "init": null + } + ], + "kind": "let" + }, + { + "type": "VariableDeclaration", + "start":136,"end":184,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":48}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":140,"end":183,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":47}}, + "id": { + "type": "Identifier", + "start":140,"end":183,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":47},"identifierName":"map4"}, + "name": "map4", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":144,"end":183,"loc":{"start":{"line":4,"column":8},"end":{"line":4,"column":47}}, + "typeAnnotation": { + "type": "TSMappedType", + "start":146,"end":183,"loc":{"start":{"line":4,"column":10},"end":{"line":4,"column":47}}, + "readonly": "-", + "typeParameter": { + "type": "TSTypeParameter", + "start":159,"end":170,"loc":{"start":{"line":4,"column":23},"end":{"line":4,"column":34}}, + "name": "P", + "constraint": { + "type": "TSStringKeyword", + "start":164,"end":170,"loc":{"start":{"line":4,"column":28},"end":{"line":4,"column":34}} + } + }, + "nameType": null, + "optional": "-", + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":175,"end":181,"loc":{"start":{"line":4,"column":39},"end":{"line":4,"column":45}} + } + } + } + }, + "init": null + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/types/mapped/options.json b/packages/babel-parser/test/fixtures/typescript/types/mapped/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/mapped/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/mapped/output.json b/packages/babel-parser/test/fixtures/typescript/types/mapped/output.json index 47f82fab7476..724d1041ef37 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/mapped/output.json +++ b/packages/babel-parser/test/fixtures/typescript/types/mapped/output.json @@ -27,7 +27,11 @@ "typeParameter": { "type": "TSTypeParameter", "start":13,"end":24,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":24}}, - "name": "P", + "name": { + "type": "Identifier", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14},"identifierName":"P"}, + "name": "P" + }, "constraint": { "type": "TSStringKeyword", "start":18,"end":24,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":24}} @@ -67,7 +71,11 @@ "typeParameter": { "type": "TSTypeParameter", "start":60,"end":71,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":33}}, - "name": "P", + "name": { + "type": "Identifier", + "start":60,"end":61,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":23},"identifierName":"P"}, + "name": "P" + }, "constraint": { "type": "TSStringKeyword", "start":65,"end":71,"loc":{"start":{"line":2,"column":27},"end":{"line":2,"column":33}} @@ -108,7 +116,11 @@ "typeParameter": { "type": "TSTypeParameter", "start":109,"end":120,"loc":{"start":{"line":3,"column":23},"end":{"line":3,"column":34}}, - "name": "P", + "name": { + "type": "Identifier", + "start":109,"end":110,"loc":{"start":{"line":3,"column":23},"end":{"line":3,"column":24},"identifierName":"P"}, + "name": "P" + }, "constraint": { "type": "TSStringKeyword", "start":114,"end":120,"loc":{"start":{"line":3,"column":28},"end":{"line":3,"column":34}} @@ -149,7 +161,11 @@ "typeParameter": { "type": "TSTypeParameter", "start":159,"end":170,"loc":{"start":{"line":4,"column":23},"end":{"line":4,"column":34}}, - "name": "P", + "name": { + "type": "Identifier", + "start":159,"end":160,"loc":{"start":{"line":4,"column":23},"end":{"line":4,"column":24},"identifierName":"P"}, + "name": "P" + }, "constraint": { "type": "TSStringKeyword", "start":164,"end":170,"loc":{"start":{"line":4,"column":28},"end":{"line":4,"column":34}} diff --git a/packages/babel-parser/test/fixtures/typescript/types/object-shorthand-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/types/object-shorthand-babel-7/input.ts new file mode 100644 index 000000000000..62012de4ebac --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/object-shorthand-babel-7/input.ts @@ -0,0 +1,5 @@ +const table = { + put(value: T) { + // actually put. + } +}; diff --git a/packages/babel-parser/test/fixtures/typescript/types/object-shorthand-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/types/object-shorthand-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/object-shorthand-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/object-shorthand-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/types/object-shorthand-babel-7/output.json new file mode 100644 index 000000000000..cf6101ace1e6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/object-shorthand-babel-7/output.json @@ -0,0 +1,125 @@ +{ + "type": "File", + "start":0,"end":87,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}}, + "program": { + "type": "Program", + "start":0,"end":87,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":87,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":6,"end":86,"loc":{"start":{"line":1,"column":6},"end":{"line":5,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":11,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":11},"identifierName":"table"}, + "name": "table" + }, + "init": { + "type": "ObjectExpression", + "start":14,"end":86,"loc":{"start":{"line":1,"column":14},"end":{"line":5,"column":1}}, + "properties": [ + { + "type": "ObjectMethod", + "start":18,"end":84,"loc":{"start":{"line":2,"column":2},"end":{"line":4,"column":3}}, + "method": true, + "key": { + "type": "Identifier", + "start":18,"end":21,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":5},"identifierName":"put"}, + "name": "put" + }, + "computed": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":21,"end":47,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":31}}, + "params": [ + { + "type": "TSTypeParameter", + "start":22,"end":46,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":30}}, + "name": "T", + "constraint": { + "type": "TSTypeLiteral", + "start":32,"end":46,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":30}}, + "members": [ + { + "type": "TSPropertySignature", + "start":34,"end":44,"loc":{"start":{"line":2,"column":18},"end":{"line":2,"column":28}}, + "key": { + "type": "Identifier", + "start":34,"end":36,"loc":{"start":{"line":2,"column":18},"end":{"line":2,"column":20},"identifierName":"id"}, + "name": "id" + }, + "computed": false, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":36,"end":44,"loc":{"start":{"line":2,"column":20},"end":{"line":2,"column":28}}, + "typeAnnotation": { + "type": "TSStringKeyword", + "start":38,"end":44,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":28}} + } + } + } + ] + } + } + ] + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":48,"end":56,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":40},"identifierName":"value"}, + "name": "value", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":53,"end":56,"loc":{"start":{"line":2,"column":37},"end":{"line":2,"column":40}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":55,"end":56,"loc":{"start":{"line":2,"column":39},"end":{"line":2,"column":40}}, + "typeName": { + "type": "Identifier", + "start":55,"end":56,"loc":{"start":{"line":2,"column":39},"end":{"line":2,"column":40},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "body": { + "type": "BlockStatement", + "start":58,"end":84,"loc":{"start":{"line":2,"column":42},"end":{"line":4,"column":3}}, + "innerComments": [ + { + "type": "CommentLine", + "value": " actually put.", + "start":64,"end":80,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":20}} + } + ], + "body": [], + "directives": [] + } + } + ] + } + } + ], + "kind": "const" + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " actually put.", + "start":64,"end":80,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":20}} + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/types/object-shorthand/options.json b/packages/babel-parser/test/fixtures/typescript/types/object-shorthand/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/object-shorthand/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/object-shorthand/output.json b/packages/babel-parser/test/fixtures/typescript/types/object-shorthand/output.json index 5b8fb1442f77..843282ace95d 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/object-shorthand/output.json +++ b/packages/babel-parser/test/fixtures/typescript/types/object-shorthand/output.json @@ -40,7 +40,11 @@ { "type": "TSTypeParameter", "start":22,"end":46,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":30}}, - "name": "T", + "name": { + "type": "Identifier", + "start":22,"end":23,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":7},"identifierName":"T"}, + "name": "T" + }, "constraint": { "type": "TSTypeLiteral", "start":32,"end":46,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":30}}, @@ -95,15 +99,15 @@ "body": { "type": "BlockStatement", "start":58,"end":84,"loc":{"start":{"line":2,"column":42},"end":{"line":4,"column":3}}, - "body": [], - "directives": [], "innerComments": [ { "type": "CommentLine", "value": " actually put.", "start":64,"end":80,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":20}} } - ] + ], + "body": [], + "directives": [] } } ] diff --git a/packages/babel-types/src/definitions/typescript.ts b/packages/babel-types/src/definitions/typescript.ts index 5d2f7d764b91..2cb997a440dd 100644 --- a/packages/babel-types/src/definitions/typescript.ts +++ b/packages/babel-types/src/definitions/typescript.ts @@ -534,7 +534,9 @@ defineType("TSTypeParameter", { visitor: ["constraint", "default"], fields: { name: { - validate: assertValueType("string"), + validate: !process.env.BABEL_TYPES_8_BREAKING + ? assertValueType("string") + : assertNodeType("Identifier"), }, constraint: { validate: assertNodeType("TSType"), diff --git a/packages/babel-types/test/builders/typescript/__snapshots__/tsTypeParameter.js.snap b/packages/babel-types/test/builders/typescript/__snapshots__/tsTypeParameter.js.snap index 51940ca2d50a..bd67ae976525 100644 --- a/packages/babel-types/test/builders/typescript/__snapshots__/tsTypeParameter.js.snap +++ b/packages/babel-types/test/builders/typescript/__snapshots__/tsTypeParameter.js.snap @@ -18,7 +18,7 @@ Object { }, "typeParameters": null, }, - "name": "foo", + "name": Anything, "type": "TSTypeParameter", } `; diff --git a/packages/babel-types/test/builders/typescript/tsTypeParameter.js b/packages/babel-types/test/builders/typescript/tsTypeParameter.js index 61ca0986d1e7..917faf5adaff 100644 --- a/packages/babel-types/test/builders/typescript/tsTypeParameter.js +++ b/packages/babel-types/test/builders/typescript/tsTypeParameter.js @@ -7,9 +7,22 @@ describe("builders", function () { const tsTypeParameter = t.tsTypeParameter( t.tsTypeReference(t.identifier("bar")), t.tsTypeReference(t.identifier("baz")), - "foo", + !process.env.BABEL_TYPES_8_BREAKING ? "foo" : t.identifier("foo"), + ); + expect(tsTypeParameter).toMatchSnapshot({ + name: expect.anything(), + }); + // TODO(babel-8): move this check to the snapshot + expect(tsTypeParameter).toEqual( + expect.objectContaining({ + name: !process.env.BABEL_TYPES_8_BREAKING + ? "foo" + : expect.objectContaining({ + name: "foo", + type: "Identifier", + }), + }), ); - expect(tsTypeParameter).toMatchSnapshot(); }); it("throws when name is missing", function () { expect(() => { @@ -17,7 +30,11 @@ describe("builders", function () { t.tsTypeReference(t.identifier("bar")), t.tsTypeReference(t.identifier("baz")), ); - }).toThrow("Property name expected type of string but got null"); + }).toThrow( + !process.env.BABEL_TYPES_8_BREAKING + ? "Property name expected type of string but got null" + : 'Property name of TSTypeParameter expected node to be of a type ["Identifier"] but instead got undefined', + ); }); }); });