diff --git a/packages/babel-generator/src/generators/expressions.ts b/packages/babel-generator/src/generators/expressions.ts index c9b8e5f35fc7..766490d326f7 100644 --- a/packages/babel-generator/src/generators/expressions.ts +++ b/packages/babel-generator/src/generators/expressions.ts @@ -93,8 +93,11 @@ export function NewExpression( return; } - this.print(node.typeArguments); // Flow - this.print(node.typeParameters); // TS + this.print(node.typeArguments); + if (!process.env.BABEL_8_BREAKING) { + // @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8 + this.print(node.typeParameters); // Legacy TS AST + } // @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8 if (node.optional) { @@ -186,13 +189,16 @@ export function OptionalCallExpression( ) { this.print(node.callee); - this.print(node.typeParameters); // TS + if (!process.env.BABEL_8_BREAKING) { + // @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8 + this.print(node.typeParameters); // legacy TS AST + } if (node.optional) { this.token("?."); } - this.print(node.typeArguments); // Flow + this.print(node.typeArguments); this.token("("); const exit = this.enterDelimited(); @@ -204,8 +210,11 @@ export function OptionalCallExpression( export function CallExpression(this: Printer, node: t.CallExpression) { this.print(node.callee); - this.print(node.typeArguments); // Flow - this.print(node.typeParameters); // TS + this.print(node.typeArguments); + if (!process.env.BABEL_8_BREAKING) { + // @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8 + this.print(node.typeParameters); // legacy TS AST + } this.token("("); const exit = this.enterDelimited(); this.printList(node.arguments, this.shouldPrintTrailingComma(")")); diff --git a/packages/babel-generator/src/generators/jsx.ts b/packages/babel-generator/src/generators/jsx.ts index b42aec0653e3..2d4b8fb3c754 100644 --- a/packages/babel-generator/src/generators/jsx.ts +++ b/packages/babel-generator/src/generators/jsx.ts @@ -82,7 +82,14 @@ function spaceSeparator(this: Printer) { export function JSXOpeningElement(this: Printer, node: t.JSXOpeningElement) { this.token("<"); this.print(node.name); - this.print(node.typeParameters); // TS + if (process.env.BABEL_8_BREAKING) { + //@ts-ignore(Babel 7 vs Babel 8) Babel 8 AST + this.print(node.typeArguments); + } else { + // @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8 + this.print(node.typeParameters); // Legacy TS AST + } + if (node.attributes.length > 0) { this.space(); this.printJoin(node.attributes, undefined, undefined, spaceSeparator); diff --git a/packages/babel-generator/src/generators/template-literals.ts b/packages/babel-generator/src/generators/template-literals.ts index 7bbfc01f005f..80394a506b34 100644 --- a/packages/babel-generator/src/generators/template-literals.ts +++ b/packages/babel-generator/src/generators/template-literals.ts @@ -6,7 +6,13 @@ export function TaggedTemplateExpression( node: t.TaggedTemplateExpression, ) { this.print(node.tag); - this.print(node.typeParameters); // TS + if (process.env.BABEL_8_BREAKING) { + // @ts-ignore(Babel 7 vs Babel 8) Babel 8 AST + this.print(node.typeArguments); + } else { + // @ts-ignore(Babel 7 vs Babel 8) Babel 7 AST + this.print(node.typeParameters); + } this.print(node.quasi); } diff --git a/packages/babel-generator/src/generators/typescript.ts b/packages/babel-generator/src/generators/typescript.ts index da33421397cc..1fbde1e4c838 100644 --- a/packages/babel-generator/src/generators/typescript.ts +++ b/packages/babel-generator/src/generators/typescript.ts @@ -594,7 +594,13 @@ export function TSInstantiationExpression( node: t.TSInstantiationExpression, ) { this.print(node.expression); - this.print(node.typeParameters); + if (process.env.BABEL_8_BREAKING) { + // @ts-ignore(Babel 7 vs Babel 8) Babel 8 AST + this.print(node.typeArguments); + } else { + // @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8 + this.print(node.typeParameters); + } } export function TSEnumDeclaration(this: Printer, node: t.TSEnumDeclaration) { diff --git a/packages/babel-generator/src/node/parentheses.ts b/packages/babel-generator/src/node/parentheses.ts index 15d64064bf90..eb37aa3a70d9 100644 --- a/packages/babel-generator/src/node/parentheses.ts +++ b/packages/babel-generator/src/node/parentheses.ts @@ -268,7 +268,11 @@ export function TSInstantiationExpression( parentType === "OptionalCallExpression" || parentType === "NewExpression" || parentType === "TSInstantiationExpression") && - !!parent.typeParameters + !!(process.env.BABEL_8_BREAKING + ? // @ts-ignore(Babel 7 vs Babel 8) Babel 8 AST + parent.typeArguments + : // @ts-ignore(Babel 7 vs Babel 8) Babel 7 AST + parent.typeParameters) ); } diff --git a/packages/babel-parser/src/plugins/typescript/index.ts b/packages/babel-parser/src/plugins/typescript/index.ts index d37b33375537..c33a73dcfe32 100644 --- a/packages/babel-parser/src/plugins/typescript/index.ts +++ b/packages/babel-parser/src/plugins/typescript/index.ts @@ -2556,7 +2556,11 @@ export default (superClass: ClassWithMixin) => startLoc, state, ); - result.typeParameters = typeArguments; + if (process.env.BABEL_8_BREAKING) { + result.typeArguments = typeArguments; + } else { + result.typeParameters = typeArguments; + } return result; } @@ -2571,7 +2575,12 @@ export default (superClass: ClassWithMixin) => // Handles invalid case: `f(a:b)` this.tsCheckForInvalidTypeCasts(node.arguments); - node.typeParameters = typeArguments; + if (process.env.BABEL_8_BREAKING) { + node.typeArguments = typeArguments; + } else { + node.typeParameters = typeArguments; + } + if (state.optionalChainMember) { (node as Undone).optional = isOptionalCall; @@ -2597,7 +2606,11 @@ export default (superClass: ClassWithMixin) => const node = this.startNodeAt(startLoc); node.expression = base; - node.typeParameters = typeArguments; + if (process.env.BABEL_8_BREAKING) { + node.typeArguments = typeArguments; + } else { + node.typeParameters = typeArguments; + } return this.finishNode(node, "TSInstantiationExpression"); }); @@ -2632,7 +2645,11 @@ export default (superClass: ClassWithMixin) => callee.type === "TSInstantiationExpression" && !callee.extra?.parenthesized ) { - node.typeParameters = callee.typeParameters; + if (process.env.BABEL_8_BREAKING) { + node.typeArguments = callee.typeArguments; + } else { + node.typeParameters = callee.typeParameters; + } node.callee = callee.expression; } } @@ -3776,7 +3793,12 @@ export default (superClass: ClassWithMixin) => expr, startLoc, ) as N.CallExpression; - call.typeParameters = typeArguments; + if (process.env.BABEL_8_BREAKING) { + call.typeArguments = typeArguments; + } else { + call.typeParameters = typeArguments; + } + return call; } @@ -3915,7 +3937,13 @@ export default (superClass: ClassWithMixin) => const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression(), ); - if (typeArguments) node.typeParameters = typeArguments; + if (typeArguments) { + if (process.env.BABEL_8_BREAKING) { + node.typeArguments = typeArguments; + } else { + node.typeParameters = typeArguments; + } + } } return super.jsxParseOpeningElementAfterName(node); } diff --git a/packages/babel-parser/src/types.ts b/packages/babel-parser/src/types.ts index cc789096407a..6ac76bd8782a 100644 --- a/packages/babel-parser/src/types.ts +++ b/packages/babel-parser/src/types.ts @@ -716,6 +716,9 @@ export interface CallOrNewBase extends NodeBase { callee: Expression | Super | Import; arguments: Array; // TODO: $ReadOnlyArray, typeArguments: TypeParameterInstantiationBase | undefined | null; + /** + * @deprecated + */ typeParameters?: TypeParameterInstantiationBase | null; // TODO: Not in spec } @@ -799,6 +802,10 @@ export interface TaggedTemplateExpression extends NodeBase { type: "TaggedTemplateExpression"; tag: Expression; quasi: TemplateLiteral; + typeArguments?: TypeParameterInstantiationBase | null; // TODO: Not in spec + /** + * @deprecated + */ typeParameters?: TypeParameterInstantiationBase | null; // TODO: Not in spec } @@ -1127,6 +1134,10 @@ export type JSXSpreadAttribute = NodeAny<"JSXSpreadAttribute">; export interface JSXOpeningElement extends NodeBase { type: "JSXOpeningElement"; name: JSXNamespacedName | JSXMemberExpression; + typeArguments?: TypeParameterInstantiationBase | null; // TODO: Not in spec, + /** + * @deprecated + */ typeParameters?: TypeParameterInstantiationBase | null; // TODO: Not in spec, attributes: (JSXAttribute | JSXSpreadAttribute)[]; selfClosing: boolean; @@ -1886,7 +1897,11 @@ export interface TsNonNullExpression extends NodeBase { export interface TsInstantiationExpression extends NodeBase { type: "TSInstantiationExpression"; expression: Expression; - typeParameters: TsTypeParameterInstantiation; + typeArguments?: TsTypeParameterInstantiation; + /** + * @deprecated + */ + typeParameters?: TsTypeParameterInstantiation; } // ================ diff --git a/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining-babel-7/input.js b/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining-babel-7/input.js new file mode 100644 index 000000000000..998e39643ae7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining-babel-7/input.js @@ -0,0 +1,2 @@ +foo?.foo(); +foo?.foo?.(); diff --git a/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining-babel-7/options.json b/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining-babel-7/output.json b/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining-babel-7/output.json new file mode 100644 index 000000000000..6c4536f6c78d --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining-babel-7/output.json @@ -0,0 +1,102 @@ +{ + "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": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}}, + "expression": { + "type": "ChainExpression", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "expression": { + "type": "CallExpression", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "callee": { + "type": "MemberExpression", + "start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}}, + "object": { + "type": "Identifier", + "start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3},"identifierName":"foo"}, + "name": "foo" + }, + "computed": false, + "property": { + "type": "Identifier", + "start":5,"end":8,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":8},"identifierName":"foo"}, + "name": "foo" + }, + "optional": true + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":8,"end":11,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":11}}, + "params": [ + { + "type": "TSTypeReference", + "start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10}}, + "typeName": { + "type": "Identifier", + "start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "optional": false + } + } + }, + { + "type": "ExpressionStatement", + "start":15,"end":31,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":16}}, + "expression": { + "type": "ChainExpression", + "start":15,"end":30,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":15}}, + "expression": { + "type": "CallExpression", + "start":15,"end":30,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":15}}, + "callee": { + "type": "MemberExpression", + "start":15,"end":23,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":8}}, + "object": { + "type": "Identifier", + "start":15,"end":18,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":3},"identifierName":"foo"}, + "name": "foo" + }, + "computed": false, + "property": { + "type": "Identifier", + "start":20,"end":23,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":8},"identifierName":"foo"}, + "name": "foo" + }, + "optional": true + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":25,"end":28,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":13}}, + "params": [ + { + "type": "TSTypeReference", + "start":26,"end":27,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":12}}, + "typeName": { + "type": "Identifier", + "start":26,"end":27,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":12},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "optional": true + } + } + } + ] + } +} diff --git a/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining/options.json b/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining/output.json b/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining/output.json index 47edad448613..e2a7f2b53a82 100644 --- a/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining/output.json +++ b/packages/babel-parser/test/fixtures/estree/typescript/optional-chaining/output.json @@ -33,7 +33,7 @@ "optional": true }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":8,"end":11,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":11}}, "params": [ @@ -78,7 +78,7 @@ "optional": true }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":25,"end":28,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":13}}, "params": [ @@ -99,4 +99,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive-babel-7/input.ts new file mode 100644 index 000000000000..29986ed4d0e7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive-babel-7/input.ts @@ -0,0 +1,2 @@ +async < 1; +async() == 0; diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive-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-false-positive-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive-babel-7/output.json new file mode 100644 index 000000000000..f86d12cf2123 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive-babel-7/output.json @@ -0,0 +1,82 @@ +{ + "type": "File", + "start":0,"end":27,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":16,"index":27}}, + "program": { + "type": "Program", + "start":0,"end":27,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":16,"index":27}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":10,"index":10}}, + "expression": { + "type": "BinaryExpression", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":9,"index":9}}, + "left": { + "type": "Identifier", + "start":0,"end":5,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":5,"index":5},"identifierName":"async"}, + "name": "async" + }, + "operator": "<", + "right": { + "type": "NumericLiteral", + "start":8,"end":9,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":9,"index":9}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + }, + { + "type": "ExpressionStatement", + "start":11,"end":27,"loc":{"start":{"line":2,"column":0,"index":11},"end":{"line":2,"column":16,"index":27}}, + "expression": { + "type": "BinaryExpression", + "start":11,"end":26,"loc":{"start":{"line":2,"column":0,"index":11},"end":{"line":2,"column":15,"index":26}}, + "left": { + "type": "CallExpression", + "start":11,"end":21,"loc":{"start":{"line":2,"column":0,"index":11},"end":{"line":2,"column":10,"index":21}}, + "callee": { + "type": "Identifier", + "start":11,"end":16,"loc":{"start":{"line":2,"column":0,"index":11},"end":{"line":2,"column":5,"index":16},"identifierName":"async"}, + "name": "async" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":16,"end":19,"loc":{"start":{"line":2,"column":5,"index":16},"end":{"line":2,"column":8,"index":19}}, + "params": [ + { + "type": "TSTypeReference", + "start":17,"end":18,"loc":{"start":{"line":2,"column":6,"index":17},"end":{"line":2,"column":7,"index":18}}, + "typeName": { + "type": "Identifier", + "start":17,"end":18,"loc":{"start":{"line":2,"column":6,"index":17},"end":{"line":2,"column":7,"index":18},"identifierName":"T"}, + "name": "T" + } + } + ] + } + }, + "operator": "==", + "right": { + "type": "NumericLiteral", + "start":25,"end":26,"loc":{"start":{"line":2,"column":14,"index":25},"end":{"line":2,"column":15,"index":26}}, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive/options.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive/output.json index f86d12cf2123..d4a33cb470b3 100644 --- a/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive/output.json +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/async-generic-false-positive/output.json @@ -45,7 +45,7 @@ "name": "async" }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":16,"end":19,"loc":{"start":{"line":2,"column":5,"index":16},"end":{"line":2,"column":8,"index":19}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/assign/TSTypeParameterInstantiation-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/assign/TSTypeParameterInstantiation-babel-7/options.json index 088fb893488a..0bfb449fe86c 100644 --- a/packages/babel-parser/test/fixtures/typescript/assign/TSTypeParameterInstantiation-babel-7/options.json +++ b/packages/babel-parser/test/fixtures/typescript/assign/TSTypeParameterInstantiation-babel-7/options.json @@ -1,4 +1,6 @@ { "BABEL_8_BREAKING": false, - "plugins": ["typescript"] + "plugins": [ + "typescript" + ] } diff --git a/packages/babel-parser/test/fixtures/typescript/assign/TSTypeParameterInstantiation/options.json b/packages/babel-parser/test/fixtures/typescript/assign/TSTypeParameterInstantiation/options.json index 08d8091d4386..5cf6f8009f9e 100644 --- a/packages/babel-parser/test/fixtures/typescript/assign/TSTypeParameterInstantiation/options.json +++ b/packages/babel-parser/test/fixtures/typescript/assign/TSTypeParameterInstantiation/options.json @@ -1,4 +1,6 @@ { "BABEL_8_BREAKING": true, - "plugins": ["typescript"] + "plugins": [ + "typescript" + ] } diff --git a/packages/babel-parser/test/fixtures/typescript/assign/TSTypeParameterInstantiation/output.json b/packages/babel-parser/test/fixtures/typescript/assign/TSTypeParameterInstantiation/output.json index 8c80b9008845..ef6ae296f816 100644 --- a/packages/babel-parser/test/fixtures/typescript/assign/TSTypeParameterInstantiation/output.json +++ b/packages/babel-parser/test/fixtures/typescript/assign/TSTypeParameterInstantiation/output.json @@ -246,7 +246,7 @@ "name": "myFunc" } }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":317,"end":332,"loc":{"start":{"line":15,"column":14,"index":317},"end":{"line":15,"column":29,"index":332}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast-babel-7/input.ts new file mode 100644 index 000000000000..0a26da3585bc --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast-babel-7/input.ts @@ -0,0 +1,2 @@ +func(a: T); +func(a: T); diff --git a/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast-babel-7/output.json new file mode 100644 index 000000000000..3107994eaf99 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast-babel-7/output.json @@ -0,0 +1,109 @@ +{ + "type": "File", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":14,"index":26}}, + "errors": [ + "SyntaxError: Did not expect a type annotation here. (1:6)", + "SyntaxError: Did not expect a type annotation here. (2:9)" + ], + "program": { + "type": "Program", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":14,"index":26}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":11,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":11,"index":11}}, + "expression": { + "type": "CallExpression", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":10,"index":10}}, + "callee": { + "type": "Identifier", + "start":0,"end":4,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":4,"index":4},"identifierName":"func"}, + "name": "func" + }, + "arguments": [ + { + "type": "TSTypeCastExpression", + "start":5,"end":9,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":9,"index":9}}, + "expression": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6},"identifierName":"a"}, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":9,"index":9}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":8,"end":9,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":9,"index":9}}, + "typeName": { + "type": "Identifier", + "start":8,"end":9,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":9,"index":9},"identifierName":"T"}, + "name": "T" + } + } + } + } + ] + } + }, + { + "type": "ExpressionStatement", + "start":12,"end":26,"loc":{"start":{"line":2,"column":0,"index":12},"end":{"line":2,"column":14,"index":26}}, + "expression": { + "type": "CallExpression", + "start":12,"end":25,"loc":{"start":{"line":2,"column":0,"index":12},"end":{"line":2,"column":13,"index":25}}, + "callee": { + "type": "Identifier", + "start":12,"end":16,"loc":{"start":{"line":2,"column":0,"index":12},"end":{"line":2,"column":4,"index":16},"identifierName":"func"}, + "name": "func" + }, + "arguments": [ + { + "type": "TSTypeCastExpression", + "start":20,"end":24,"loc":{"start":{"line":2,"column":8,"index":20},"end":{"line":2,"column":12,"index":24}}, + "expression": { + "type": "Identifier", + "start":20,"end":21,"loc":{"start":{"line":2,"column":8,"index":20},"end":{"line":2,"column":9,"index":21},"identifierName":"a"}, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":21,"end":24,"loc":{"start":{"line":2,"column":9,"index":21},"end":{"line":2,"column":12,"index":24}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":23,"end":24,"loc":{"start":{"line":2,"column":11,"index":23},"end":{"line":2,"column":12,"index":24}}, + "typeName": { + "type": "Identifier", + "start":23,"end":24,"loc":{"start":{"line":2,"column":11,"index":23},"end":{"line":2,"column":12,"index":24},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":16,"end":19,"loc":{"start":{"line":2,"column":4,"index":16},"end":{"line":2,"column":7,"index":19}}, + "params": [ + { + "type": "TSTypeReference", + "start":17,"end":18,"loc":{"start":{"line":2,"column":5,"index":17},"end":{"line":2,"column":6,"index":18}}, + "typeName": { + "type": "Identifier", + "start":17,"end":18,"loc":{"start":{"line":2,"column":5,"index":17},"end":{"line":2,"column":6,"index":18},"identifierName":"T"}, + "name": "T" + } + } + ] + } + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast/options.json b/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast/output.json b/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast/output.json index 3107994eaf99..8646b1fed58b 100644 --- a/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast/output.json +++ b/packages/babel-parser/test/fixtures/typescript/cast/parameter-typecast/output.json @@ -83,7 +83,7 @@ } } ], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":16,"end":19,"loc":{"start":{"line":2,"column":4,"index":16},"end":{"line":2,"column":7,"index":19}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments-babel-7/input.ts new file mode 100644 index 000000000000..cb1c5dd44784 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments-babel-7/input.ts @@ -0,0 +1,2 @@ +@decorator() +class Test {} diff --git a/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments-babel-7/options.json new file mode 100644 index 000000000000..601e925cb3f4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments-babel-7/options.json @@ -0,0 +1,12 @@ +{ + "plugins": [ + "typescript", + [ + "decorators", + { + "decoratorsBeforeExport": true + } + ] + ], + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments-babel-7/output.json new file mode 100644 index 000000000000..1d0b1c29e81c --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments-babel-7/output.json @@ -0,0 +1,57 @@ +{ + "type": "File", + "start":0,"end":34,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":13,"index":34}}, + "program": { + "type": "Program", + "start":0,"end":34,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":13,"index":34}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":34,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":13,"index":34}}, + "decorators": [ + { + "type": "Decorator", + "start":0,"end":20,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":20,"index":20}}, + "expression": { + "type": "CallExpression", + "start":1,"end":20,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":20,"index":20}}, + "callee": { + "type": "Identifier", + "start":1,"end":10,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":10,"index":10},"identifierName":"decorator"}, + "name": "decorator" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":10,"end":18,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":18,"index":18}}, + "params": [ + { + "type": "TSStringKeyword", + "start":11,"end":17,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":17,"index":17}} + } + ] + } + } + } + ], + "id": { + "type": "Identifier", + "start":27,"end":31,"loc":{"start":{"line":2,"column":6,"index":27},"end":{"line":2,"column":10,"index":31},"identifierName":"Test"}, + "name": "Test" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":32,"end":34,"loc":{"start":{"line":2,"column":11,"index":32},"end":{"line":2,"column":13,"index":34}}, + "body": [] + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments/options.json b/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments/options.json index 6e9dea51e823..a666be432bc9 100644 --- a/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments/options.json +++ b/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments/options.json @@ -1,3 +1,12 @@ { - "plugins": ["typescript", ["decorators", { "decoratorsBeforeExport": true }]] + "plugins": [ + "typescript", + [ + "decorators", + { + "decoratorsBeforeExport": true + } + ] + ], + "BABEL_8_BREAKING": true } diff --git a/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments/output.json b/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments/output.json index 1d0b1c29e81c..dcac93d968df 100644 --- a/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments/output.json +++ b/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments/output.json @@ -23,7 +23,7 @@ "name": "decorator" }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":10,"end":18,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":18,"index":18}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments-babel-7/input.ts new file mode 100644 index 000000000000..cb1c5dd44784 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments-babel-7/input.ts @@ -0,0 +1,2 @@ +@decorator() +class Test {} diff --git a/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments-babel-7/options.json new file mode 100644 index 000000000000..1df13c6bab0f --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments-babel-7/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "typescript", + "decorators-legacy" + ], + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments-babel-7/output.json new file mode 100644 index 000000000000..1d0b1c29e81c --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments-babel-7/output.json @@ -0,0 +1,57 @@ +{ + "type": "File", + "start":0,"end":34,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":13,"index":34}}, + "program": { + "type": "Program", + "start":0,"end":34,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":13,"index":34}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":34,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":13,"index":34}}, + "decorators": [ + { + "type": "Decorator", + "start":0,"end":20,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":20,"index":20}}, + "expression": { + "type": "CallExpression", + "start":1,"end":20,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":20,"index":20}}, + "callee": { + "type": "Identifier", + "start":1,"end":10,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":10,"index":10},"identifierName":"decorator"}, + "name": "decorator" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":10,"end":18,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":18,"index":18}}, + "params": [ + { + "type": "TSStringKeyword", + "start":11,"end":17,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":17,"index":17}} + } + ] + } + } + } + ], + "id": { + "type": "Identifier", + "start":27,"end":31,"loc":{"start":{"line":2,"column":6,"index":27},"end":{"line":2,"column":10,"index":31},"identifierName":"Test"}, + "name": "Test" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":32,"end":34,"loc":{"start":{"line":2,"column":11,"index":32},"end":{"line":2,"column":13,"index":34}}, + "body": [] + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments/options.json b/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments/options.json index b95c143bc24f..ad85417c9d1d 100644 --- a/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments/options.json +++ b/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments/options.json @@ -1,3 +1,7 @@ { - "plugins": ["typescript", "decorators-legacy"] + "plugins": [ + "typescript", + "decorators-legacy" + ], + "BABEL_8_BREAKING": true } diff --git a/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments/output.json b/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments/output.json index 1d0b1c29e81c..dcac93d968df 100644 --- a/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments/output.json +++ b/packages/babel-parser/test/fixtures/typescript/legacy-decorators/type-arguments/output.json @@ -23,7 +23,7 @@ "name": "decorator" }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":10,"end":18,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":18,"index":18}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments-babel-7/input.ts new file mode 100644 index 000000000000..731a05f63b36 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments-babel-7/input.ts @@ -0,0 +1 @@ +example.inner?.greet() diff --git a/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments-babel-7/output.json new file mode 100644 index 000000000000..d35e95166cd0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments-babel-7/output.json @@ -0,0 +1,62 @@ +{ + "type": "File", + "start":0,"end":30,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":30,"index":30}}, + "program": { + "type": "Program", + "start":0,"end":30,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":30,"index":30}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":30,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":30,"index":30}}, + "expression": { + "type": "OptionalCallExpression", + "start":0,"end":30,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":30,"index":30}}, + "callee": { + "type": "OptionalMemberExpression", + "start":0,"end":20,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":20,"index":20}}, + "object": { + "type": "MemberExpression", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":13,"index":13}}, + "object": { + "type": "Identifier", + "start":0,"end":7,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":7,"index":7},"identifierName":"example"}, + "name": "example" + }, + "computed": false, + "property": { + "type": "Identifier", + "start":8,"end":13,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":13,"index":13},"identifierName":"inner"}, + "name": "inner" + } + }, + "computed": false, + "property": { + "type": "Identifier", + "start":15,"end":20,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":20,"index":20},"identifierName":"greet"}, + "name": "greet" + }, + "optional": true + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":20,"end":28,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":28,"index":28}}, + "params": [ + { + "type": "TSStringKeyword", + "start":21,"end":27,"loc":{"start":{"line":1,"column":21,"index":21},"end":{"line":1,"column":27,"index":27}} + } + ] + }, + "optional": false + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments/options.json b/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments/output.json b/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments/output.json index d35e95166cd0..e372679efa48 100644 --- a/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments/output.json +++ b/packages/babel-parser/test/fixtures/typescript/optional-chaining/type-arguments/output.json @@ -40,7 +40,7 @@ "optional": true }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":20,"end":28,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":28,"index":28}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/tsx/type-arguments-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/tsx/type-arguments-babel-7/options.json index e0cab152aa06..29a3f0e84167 100644 --- a/packages/babel-parser/test/fixtures/typescript/tsx/type-arguments-babel-7/options.json +++ b/packages/babel-parser/test/fixtures/typescript/tsx/type-arguments-babel-7/options.json @@ -1,3 +1,3 @@ { "BABEL_8_BREAKING": false -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/typescript/tsx/type-arguments/options.json b/packages/babel-parser/test/fixtures/typescript/tsx/type-arguments/options.json index 93a7d7404aa9..cbf6d1595427 100644 --- a/packages/babel-parser/test/fixtures/typescript/tsx/type-arguments/options.json +++ b/packages/babel-parser/test/fixtures/typescript/tsx/type-arguments/options.json @@ -1,3 +1,3 @@ { "BABEL_8_BREAKING": true -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/typescript/tsx/type-arguments/output.json b/packages/babel-parser/test/fixtures/typescript/tsx/type-arguments/output.json index 888ef3f142bd..676470d40e33 100644 --- a/packages/babel-parser/test/fixtures/typescript/tsx/type-arguments/output.json +++ b/packages/babel-parser/test/fixtures/typescript/tsx/type-arguments/output.json @@ -19,7 +19,7 @@ "name": "f" }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":1,"end":4,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":4,"index":4}}, "params": [ @@ -47,7 +47,7 @@ "start":12,"end":13,"loc":{"start":{"line":2,"column":4,"index":12},"end":{"line":2,"column":5,"index":13},"identifierName":"C"}, "name": "C" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":13,"end":16,"loc":{"start":{"line":2,"column":5,"index":13},"end":{"line":2,"column":8,"index":16}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression-babel-7/input.ts new file mode 100644 index 000000000000..94b8ba09b57d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression-babel-7/input.ts @@ -0,0 +1 @@ +f<(v: T) => void>(); diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression-babel-7/output.json new file mode 100644 index 000000000000..4f5b33023ac6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression-babel-7/output.json @@ -0,0 +1,76 @@ +{ + "type": "File", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":23,"index":23}}, + "program": { + "type": "Program", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":23,"index":23}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":23,"index":23}}, + "expression": { + "type": "CallExpression", + "start":0,"end":22,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":22,"index":22}}, + "callee": { + "type": "Identifier", + "start":0,"end":1,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":1,"index":1},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":1,"end":20,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":20,"index":20}}, + "params": [ + { + "type": "TSFunctionType", + "start":2,"end":19,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":19,"index":19}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":2,"end":5,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":5,"index":5}}, + "params": [ + { + "type": "TSTypeParameter", + "start":3,"end":4,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":4,"index":4}}, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start":6,"end":10,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":10,"index":10},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":10,"index":10}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":9,"end":10,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":10,"index":10}}, + "typeName": { + "type": "Identifier", + "start":9,"end":10,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":10,"index":10},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":12,"end":19,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":19,"index":19}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":15,"end":19,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":19,"index":19}} + } + } + } + ] + } + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression/output.json index d0ebc6754ba4..49535a32fd32 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression/output.json @@ -19,7 +19,7 @@ "name": "f" }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":1,"end":20,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":20,"index":20}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression-babel-7/input.ts new file mode 100644 index 000000000000..7316ad25571d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression-babel-7/input.ts @@ -0,0 +1 @@ +(@f<(v: T) => void>() class {}); diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression-babel-7/options.json new file mode 100644 index 000000000000..651f71890d63 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression-babel-7/options.json @@ -0,0 +1,12 @@ +{ + "plugins": [ + [ + "decorators", + { + "decoratorsBeforeExport": true + } + ], + "typescript" + ], + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression-babel-7/output.json new file mode 100644 index 000000000000..8b90f0090c9a --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression-babel-7/output.json @@ -0,0 +1,97 @@ +{ + "type": "File", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":35,"index":35}}, + "program": { + "type": "Program", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":35,"index":35}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":35,"index":35}}, + "expression": { + "type": "ClassExpression", + "start":1,"end":33,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":33,"index":33}}, + "decorators": [ + { + "type": "Decorator", + "start":1,"end":24,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":24,"index":24}}, + "expression": { + "type": "CallExpression", + "start":2,"end":24,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":24,"index":24}}, + "callee": { + "type": "Identifier", + "start":2,"end":3,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":3,"index":3},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":3,"end":22,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":22,"index":22}}, + "params": [ + { + "type": "TSFunctionType", + "start":4,"end":21,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":21,"index":21}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":4,"end":7,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":7,"index":7}}, + "params": [ + { + "type": "TSTypeParameter", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6}}, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start":8,"end":12,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":12,"index":12},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":12,"index":12}}, + "typeName": { + "type": "Identifier", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":12,"index":12},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":14,"end":21,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":21,"index":21}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":17,"end":21,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":21,"index":21}} + } + } + } + ] + } + } + } + ], + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start":31,"end":33,"loc":{"start":{"line":1,"column":31,"index":31},"end":{"line":1,"column":33,"index":33}}, + "body": [] + }, + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/options.json index 5b5e513c9b60..176c947856df 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/options.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/options.json @@ -1,3 +1,12 @@ { - "plugins": [["decorators", { "decoratorsBeforeExport": true }], "typescript"] + "plugins": [ + [ + "decorators", + { + "decoratorsBeforeExport": true + } + ], + "typescript" + ], + "BABEL_8_BREAKING": true } diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/output.json index 5490d349b489..fec9fc491b74 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/output.json @@ -26,7 +26,7 @@ "name": "f" }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":3,"end":22,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":22,"index":22}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression-babel-7/input.ts new file mode 100644 index 000000000000..7316ad25571d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression-babel-7/input.ts @@ -0,0 +1 @@ +(@f<(v: T) => void>() class {}); diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression-babel-7/options.json new file mode 100644 index 000000000000..f7169d415b18 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression-babel-7/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "decorators-legacy", + "typescript" + ], + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression-babel-7/output.json new file mode 100644 index 000000000000..8b90f0090c9a --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression-babel-7/output.json @@ -0,0 +1,97 @@ +{ + "type": "File", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":35,"index":35}}, + "program": { + "type": "Program", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":35,"index":35}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":35,"index":35}}, + "expression": { + "type": "ClassExpression", + "start":1,"end":33,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":33,"index":33}}, + "decorators": [ + { + "type": "Decorator", + "start":1,"end":24,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":24,"index":24}}, + "expression": { + "type": "CallExpression", + "start":2,"end":24,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":24,"index":24}}, + "callee": { + "type": "Identifier", + "start":2,"end":3,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":3,"index":3},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":3,"end":22,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":22,"index":22}}, + "params": [ + { + "type": "TSFunctionType", + "start":4,"end":21,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":21,"index":21}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":4,"end":7,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":7,"index":7}}, + "params": [ + { + "type": "TSTypeParameter", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6}}, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start":8,"end":12,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":12,"index":12},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":12,"index":12}}, + "typeName": { + "type": "Identifier", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":12,"index":12},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":14,"end":21,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":21,"index":21}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":17,"end":21,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":21,"index":21}} + } + } + } + ] + } + } + } + ], + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start":31,"end":33,"loc":{"start":{"line":1,"column":31,"index":31},"end":{"line":1,"column":33,"index":33}}, + "body": [] + }, + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/options.json index 8a18ae919565..710d99a666e2 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/options.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/options.json @@ -1,3 +1,7 @@ { - "plugins": ["decorators-legacy", "typescript"] + "plugins": [ + "decorators-legacy", + "typescript" + ], + "BABEL_8_BREAKING": true } diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/output.json index 5490d349b489..fec9fc491b74 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/output.json @@ -26,7 +26,7 @@ "name": "f" }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":3,"end":22,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":22,"index":22}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element-babel-7/input.tsx b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element-babel-7/input.tsx new file mode 100644 index 000000000000..5ad697cb46a8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element-babel-7/input.tsx @@ -0,0 +1 @@ +(v: T) => void> /> diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element-babel-7/options.json new file mode 100644 index 000000000000..940686c94219 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element-babel-7/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "jsx", + "typescript" + ], + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element-babel-7/output.json new file mode 100644 index 000000000000..ee0607c83bca --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element-babel-7/output.json @@ -0,0 +1,83 @@ +{ + "type": "File", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":32,"index":32}}, + "program": { + "type": "Program", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":32,"index":32}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":32,"index":32}}, + "expression": { + "type": "JSXElement", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":32,"index":32}}, + "openingElement": { + "type": "JSXOpeningElement", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":32,"index":32}}, + "name": { + "type": "JSXIdentifier", + "start":1,"end":10,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":10,"index":10}}, + "name": "Component" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":10,"end":29,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":29,"index":29}}, + "params": [ + { + "type": "TSFunctionType", + "start":11,"end":28,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":28,"index":28}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":11,"end":14,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":14,"index":14}}, + "params": [ + { + "type": "TSTypeParameter", + "start":12,"end":13,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":13,"index":13}}, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start":15,"end":19,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":19,"index":19},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":16,"end":19,"loc":{"start":{"line":1,"column":16,"index":16},"end":{"line":1,"column":19,"index":19}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":19,"index":19}}, + "typeName": { + "type": "Identifier", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":19,"index":19},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":21,"end":28,"loc":{"start":{"line":1,"column":21,"index":21},"end":{"line":1,"column":28,"index":28}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":24,"end":28,"loc":{"start":{"line":1,"column":24,"index":24},"end":{"line":1,"column":28,"index":28}} + } + } + } + ] + }, + "attributes": [], + "selfClosing": true + }, + "closingElement": null, + "children": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/options.json index aa8780ac5180..dfd2ba75d098 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/options.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/options.json @@ -1,3 +1,7 @@ { - "plugins": ["jsx", "typescript"] + "plugins": [ + "jsx", + "typescript" + ], + "BABEL_8_BREAKING": true } diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/output.json index 293ee3ac48ae..2106d8cd9618 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/output.json @@ -21,7 +21,7 @@ "start":1,"end":10,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":10,"index":10}}, "name": "Component" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":10,"end":29,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":29,"index":29}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression-babel-7/input.ts new file mode 100644 index 000000000000..7991a4bbd640 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression-babel-7/input.ts @@ -0,0 +1 @@ +new f<(v: T) => void>(); diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression-babel-7/output.json new file mode 100644 index 000000000000..846d6bdc6154 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression-babel-7/output.json @@ -0,0 +1,76 @@ +{ + "type": "File", + "start":0,"end":27,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":27,"index":27}}, + "program": { + "type": "Program", + "start":0,"end":27,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":27,"index":27}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":27,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":27,"index":27}}, + "expression": { + "type": "NewExpression", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":26,"index":26}}, + "callee": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"f"}, + "name": "f" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":5,"end":24,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":24,"index":24}}, + "params": [ + { + "type": "TSFunctionType", + "start":6,"end":23,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":23,"index":23}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":9,"index":9}}, + "params": [ + { + "type": "TSTypeParameter", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":8,"index":8}}, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start":10,"end":14,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":14,"index":14},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":11,"end":14,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":14,"index":14}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13,"index":13},"end":{"line":1,"column":14,"index":14}}, + "typeName": { + "type": "Identifier", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13,"index":13},"end":{"line":1,"column":14,"index":14},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":16,"end":23,"loc":{"start":{"line":1,"column":16,"index":16},"end":{"line":1,"column":23,"index":23}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":19,"end":23,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":1,"column":23,"index":23}} + } + } + } + ] + }, + "arguments": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression/output.json index 677acf14ac6f..b3e84e879845 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression/output.json @@ -18,7 +18,7 @@ "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"f"}, "name": "f" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":5,"end":24,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":24,"index":24}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-babel-7/input.ts new file mode 100644 index 000000000000..3a4d08a538e9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-babel-7/input.ts @@ -0,0 +1,2 @@ +f(); +f(); diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-babel-7/output.json new file mode 100644 index 000000000000..153c011a9ca4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-babel-7/output.json @@ -0,0 +1,83 @@ +{ + "type": "File", + "start":0,"end":18,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":10,"index":18}}, + "program": { + "type": "Program", + "start":0,"end":18,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":10,"index":18}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":7,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":7,"index":7}}, + "expression": { + "type": "CallExpression", + "start":0,"end":6,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":6,"index":6}}, + "callee": { + "type": "Identifier", + "start":0,"end":1,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":1,"index":1},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":1,"end":4,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":4,"index":4}}, + "params": [ + { + "type": "TSTypeReference", + "start":2,"end":3,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":3,"index":3}}, + "typeName": { + "type": "Identifier", + "start":2,"end":3,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":3,"index":3},"identifierName":"T"}, + "name": "T" + } + } + ] + } + } + }, + { + "type": "ExpressionStatement", + "start":8,"end":18,"loc":{"start":{"line":2,"column":0,"index":8},"end":{"line":2,"column":10,"index":18}}, + "expression": { + "type": "CallExpression", + "start":8,"end":17,"loc":{"start":{"line":2,"column":0,"index":8},"end":{"line":2,"column":9,"index":17}}, + "callee": { + "type": "Identifier", + "start":8,"end":9,"loc":{"start":{"line":2,"column":0,"index":8},"end":{"line":2,"column":1,"index":9},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":9,"end":15,"loc":{"start":{"line":2,"column":1,"index":9},"end":{"line":2,"column":7,"index":15}}, + "params": [ + { + "type": "TSTypeReference", + "start":10,"end":11,"loc":{"start":{"line":2,"column":2,"index":10},"end":{"line":2,"column":3,"index":11}}, + "typeName": { + "type": "Identifier", + "start":10,"end":11,"loc":{"start":{"line":2,"column":2,"index":10},"end":{"line":2,"column":3,"index":11},"identifierName":"T"}, + "name": "T" + } + }, + { + "type": "TSTypeReference", + "start":13,"end":14,"loc":{"start":{"line":2,"column":5,"index":13},"end":{"line":2,"column":6,"index":14}}, + "typeName": { + "type": "Identifier", + "start":13,"end":14,"loc":{"start":{"line":2,"column":5,"index":13},"end":{"line":2,"column":6,"index":14},"identifierName":"U"}, + "name": "U" + } + } + ] + } + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline-babel-7/input.ts new file mode 100644 index 000000000000..cfa4f2eea630 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline-babel-7/input.ts @@ -0,0 +1,2 @@ +makeBox +(a) diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline-babel-7/output.json new file mode 100644 index 000000000000..bd74647ee70b --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline-babel-7/output.json @@ -0,0 +1,46 @@ +{ + "type": "File", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":3,"index":19}}, + "program": { + "type": "Program", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":3,"index":19}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":3,"index":19}}, + "expression": { + "type": "CallExpression", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":3,"index":19}}, + "callee": { + "type": "Identifier", + "start":0,"end":7,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":7,"index":7},"identifierName":"makeBox"}, + "name": "makeBox" + }, + "arguments": [ + { + "type": "Identifier", + "start":17,"end":18,"loc":{"start":{"line":2,"column":1,"index":17},"end":{"line":2,"column":2,"index":18},"identifierName":"a"}, + "name": "a" + } + ], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":7,"end":15,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":15,"index":15}}, + "params": [ + { + "type": "TSNumberKeyword", + "start":8,"end":14,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":14,"index":14}} + } + ] + } + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline/output.json index bd74647ee70b..f376019f9fd2 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-newline/output.json @@ -25,7 +25,7 @@ "name": "a" } ], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":7,"end":15,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":15,"index":15}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain-babel-7/input.ts new file mode 100644 index 000000000000..1f2bdf0dc5c0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain-babel-7/input.ts @@ -0,0 +1,4 @@ +f?.(); +f?.(); +f +?.(); diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain-babel-7/output.json new file mode 100644 index 000000000000..c02732e57c63 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain-babel-7/output.json @@ -0,0 +1,115 @@ +{ + "type": "File", + "start":0,"end":33,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":8,"index":33}}, + "program": { + "type": "Program", + "start":0,"end":33,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":8,"index":33}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":9,"index":9}}, + "expression": { + "type": "OptionalCallExpression", + "start":0,"end":8,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":8,"index":8}}, + "callee": { + "type": "Identifier", + "start":0,"end":1,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":1,"index":1},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":3,"end":6,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":6,"index":6}}, + "params": [ + { + "type": "TSTypeReference", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5}}, + "typeName": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"Q"}, + "name": "Q" + } + } + ] + }, + "optional": true + } + }, + { + "type": "ExpressionStatement", + "start":10,"end":22,"loc":{"start":{"line":2,"column":0,"index":10},"end":{"line":2,"column":12,"index":22}}, + "expression": { + "type": "OptionalCallExpression", + "start":10,"end":21,"loc":{"start":{"line":2,"column":0,"index":10},"end":{"line":2,"column":11,"index":21}}, + "callee": { + "type": "Identifier", + "start":10,"end":11,"loc":{"start":{"line":2,"column":0,"index":10},"end":{"line":2,"column":1,"index":11},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":13,"end":19,"loc":{"start":{"line":2,"column":3,"index":13},"end":{"line":2,"column":9,"index":19}}, + "params": [ + { + "type": "TSTypeReference", + "start":14,"end":15,"loc":{"start":{"line":2,"column":4,"index":14},"end":{"line":2,"column":5,"index":15}}, + "typeName": { + "type": "Identifier", + "start":14,"end":15,"loc":{"start":{"line":2,"column":4,"index":14},"end":{"line":2,"column":5,"index":15},"identifierName":"Q"}, + "name": "Q" + } + }, + { + "type": "TSTypeReference", + "start":17,"end":18,"loc":{"start":{"line":2,"column":7,"index":17},"end":{"line":2,"column":8,"index":18}}, + "typeName": { + "type": "Identifier", + "start":17,"end":18,"loc":{"start":{"line":2,"column":7,"index":17},"end":{"line":2,"column":8,"index":18},"identifierName":"W"}, + "name": "W" + } + } + ] + }, + "optional": true + } + }, + { + "type": "ExpressionStatement", + "start":23,"end":33,"loc":{"start":{"line":3,"column":0,"index":23},"end":{"line":4,"column":8,"index":33}}, + "expression": { + "type": "OptionalCallExpression", + "start":23,"end":32,"loc":{"start":{"line":3,"column":0,"index":23},"end":{"line":4,"column":7,"index":32}}, + "callee": { + "type": "Identifier", + "start":23,"end":24,"loc":{"start":{"line":3,"column":0,"index":23},"end":{"line":3,"column":1,"index":24},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":27,"end":30,"loc":{"start":{"line":4,"column":2,"index":27},"end":{"line":4,"column":5,"index":30}}, + "params": [ + { + "type": "TSTypeReference", + "start":28,"end":29,"loc":{"start":{"line":4,"column":3,"index":28},"end":{"line":4,"column":4,"index":29}}, + "typeName": { + "type": "Identifier", + "start":28,"end":29,"loc":{"start":{"line":4,"column":3,"index":28},"end":{"line":4,"column":4,"index":29},"identifierName":"Q"}, + "name": "Q" + } + } + ] + }, + "optional": true + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain/output.json index c02732e57c63..8b8390d734e1 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain/output.json @@ -19,7 +19,7 @@ "name": "f" }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":3,"end":6,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":6,"index":6}}, "params": [ @@ -49,7 +49,7 @@ "name": "f" }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":13,"end":19,"loc":{"start":{"line":2,"column":3,"index":13},"end":{"line":2,"column":9,"index":19}}, "params": [ @@ -88,7 +88,7 @@ "name": "f" }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":27,"end":30,"loc":{"start":{"line":4,"column":2,"index":27},"end":{"line":4,"column":5,"index":30}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/call/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/call/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/call/output.json index 153c011a9ca4..5c5d9db50613 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/call/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/call/output.json @@ -19,7 +19,7 @@ "name": "f" }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":1,"end":4,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":4,"index":4}}, "params": [ @@ -48,7 +48,7 @@ "name": "f" }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":9,"end":15,"loc":{"start":{"line":2,"column":1,"index":9},"end":{"line":2,"column":7,"index":15}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function-babel-7/input.ts new file mode 100644 index 000000000000..63cf8bbeecd8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function-babel-7/input.ts @@ -0,0 +1 @@ +foo<>() diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function-babel-7/output.json new file mode 100644 index 000000000000..06f544ef4497 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function-babel-7/output.json @@ -0,0 +1,38 @@ +{ + "type": "File", + "start":0,"end":7,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":7,"index":7}}, + "errors": [ + "SyntaxError: Type argument list cannot be empty. (1:3)" + ], + "program": { + "type": "Program", + "start":0,"end":7,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":7,"index":7}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":7,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":7,"index":7}}, + "expression": { + "type": "CallExpression", + "start":0,"end":7,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":7,"index":7}}, + "callee": { + "type": "Identifier", + "start":0,"end":3,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":3,"index":3},"identifierName":"foo"}, + "name": "foo" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":3,"end":5,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":5,"index":5}}, + "params": [] + } + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function/output.json index 06f544ef4497..663fb1330e0d 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function/output.json @@ -22,7 +22,7 @@ "name": "foo" }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":3,"end":5,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":5,"index":5}}, "params": [] diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new-babel-7/input.ts new file mode 100644 index 000000000000..1345a5663c84 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new-babel-7/input.ts @@ -0,0 +1 @@ +new A<>(); diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new-babel-7/output.json new file mode 100644 index 000000000000..9b893ba7f8da --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new-babel-7/output.json @@ -0,0 +1,38 @@ +{ + "type": "File", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":10,"index":10}}, + "errors": [ + "SyntaxError: Type argument list cannot be empty. (1:5)" + ], + "program": { + "type": "Program", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":10,"index":10}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":10,"index":10}}, + "expression": { + "type": "NewExpression", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":9,"index":9}}, + "callee": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"A"}, + "name": "A" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":5,"end":7,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":7,"index":7}}, + "params": [] + }, + "arguments": [] + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new/output.json index 9b893ba7f8da..a9fd33ca62b2 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-new/output.json @@ -21,7 +21,7 @@ "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"A"}, "name": "A" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":5,"end":7,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":7,"index":7}}, "params": [] diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx-babel-7/input.ts new file mode 100644 index 000000000000..f9b2825158f7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx-babel-7/input.ts @@ -0,0 +1 @@ +var a = > diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx-babel-7/options.json new file mode 100644 index 000000000000..940686c94219 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx-babel-7/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "jsx", + "typescript" + ], + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx-babel-7/output.json new file mode 100644 index 000000000000..302dedbf147d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx-babel-7/output.json @@ -0,0 +1,65 @@ +{ + "type": "File", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":23,"index":23}}, + "errors": [ + "SyntaxError: Type argument list cannot be empty. (1:13)" + ], + "program": { + "type": "Program", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":23,"index":23}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":23,"index":23}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":4,"end":23,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":23,"index":23}}, + "id": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"a"}, + "name": "a" + }, + "init": { + "type": "JSXElement", + "start":8,"end":23,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":23,"index":23}}, + "openingElement": { + "type": "JSXOpeningElement", + "start":8,"end":16,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":16,"index":16}}, + "name": { + "type": "JSXIdentifier", + "start":9,"end":13,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":13,"index":13}}, + "name": "Comp" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":13,"end":15,"loc":{"start":{"line":1,"column":13,"index":13},"end":{"line":1,"column":15,"index":15}}, + "params": [] + }, + "attributes": [], + "selfClosing": false + }, + "closingElement": { + "type": "JSXClosingElement", + "start":16,"end":23,"loc":{"start":{"line":1,"column":16,"index":16},"end":{"line":1,"column":23,"index":23}}, + "name": { + "type": "JSXIdentifier", + "start":18,"end":22,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":22,"index":22}}, + "name": "Comp" + } + }, + "children": [] + } + } + ], + "kind": "var" + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx/options.json index aa8780ac5180..dfd2ba75d098 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx/options.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx/options.json @@ -1,3 +1,7 @@ { - "plugins": ["jsx", "typescript"] + "plugins": [ + "jsx", + "typescript" + ], + "BABEL_8_BREAKING": true } diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx/output.json index 302dedbf147d..d247785a4aa0 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-tsx/output.json @@ -33,7 +33,7 @@ "start":9,"end":13,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":13,"index":13}}, "name": "Comp" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":13,"end":15,"loc":{"start":{"line":1,"column":13,"index":13},"end":{"line":1,"column":15,"index":15}}, "params": [] diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi-babel-7/input.ts new file mode 100644 index 000000000000..12900113db37 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi-babel-7/input.ts @@ -0,0 +1,40 @@ +const x5 = f +let yy = 0; + +const x6 = f +interface I {} + +let x10 = f +this.bar() + +let x11 = f +function bar() {} + +let x12 = f +class C {} + +let x13 = f +bar() + +let x14 = f +void bar() + +class C1 { + static specialFoo = f + static bar = 123 +} + +class C2 { + public specialFoo = f + public bar = 123 +} + +class C3 { + private specialFoo = f + private bar = 123 +} + +class C4 { + protected specialFoo = f + protected bar = 123 +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi-babel-7/output.json new file mode 100644 index 000000000000..3b45fde3d882 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi-babel-7/output.json @@ -0,0 +1,695 @@ +{ + "type": "File", + "start":0,"end":501,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":40,"column":1,"index":501}}, + "program": { + "type": "Program", + "start":0,"end":501,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":40,"column":1,"index":501}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":18,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":18,"index":18}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":6,"end":18,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":18,"index":18}}, + "id": { + "type": "Identifier", + "start":6,"end":8,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":8,"index":8},"identifierName":"x5"}, + "name": "x5" + }, + "init": { + "type": "TSInstantiationExpression", + "start":11,"end":18,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":18,"index":18}}, + "expression": { + "type": "Identifier", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":12,"index":12},"identifierName":"f"}, + "name": "f" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":12,"end":18,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":18,"index":18}}, + "params": [ + { + "type": "TSLiteralType", + "start":13,"end":17,"loc":{"start":{"line":1,"column":13,"index":13},"end":{"line":1,"column":17,"index":17}}, + "literal": { + "type": "BooleanLiteral", + "start":13,"end":17,"loc":{"start":{"line":1,"column":13,"index":13},"end":{"line":1,"column":17,"index":17}}, + "value": true + } + } + ] + } + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start":19,"end":30,"loc":{"start":{"line":2,"column":0,"index":19},"end":{"line":2,"column":11,"index":30}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":23,"end":29,"loc":{"start":{"line":2,"column":4,"index":23},"end":{"line":2,"column":10,"index":29}}, + "id": { + "type": "Identifier", + "start":23,"end":25,"loc":{"start":{"line":2,"column":4,"index":23},"end":{"line":2,"column":6,"index":25},"identifierName":"yy"}, + "name": "yy" + }, + "init": { + "type": "NumericLiteral", + "start":28,"end":29,"loc":{"start":{"line":2,"column":9,"index":28},"end":{"line":2,"column":10,"index":29}}, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ], + "kind": "let" + }, + { + "type": "VariableDeclaration", + "start":32,"end":50,"loc":{"start":{"line":4,"column":0,"index":32},"end":{"line":4,"column":18,"index":50}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":38,"end":50,"loc":{"start":{"line":4,"column":6,"index":38},"end":{"line":4,"column":18,"index":50}}, + "id": { + "type": "Identifier", + "start":38,"end":40,"loc":{"start":{"line":4,"column":6,"index":38},"end":{"line":4,"column":8,"index":40},"identifierName":"x6"}, + "name": "x6" + }, + "init": { + "type": "TSInstantiationExpression", + "start":43,"end":50,"loc":{"start":{"line":4,"column":11,"index":43},"end":{"line":4,"column":18,"index":50}}, + "expression": { + "type": "Identifier", + "start":43,"end":44,"loc":{"start":{"line":4,"column":11,"index":43},"end":{"line":4,"column":12,"index":44},"identifierName":"f"}, + "name": "f" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":44,"end":50,"loc":{"start":{"line":4,"column":12,"index":44},"end":{"line":4,"column":18,"index":50}}, + "params": [ + { + "type": "TSLiteralType", + "start":45,"end":49,"loc":{"start":{"line":4,"column":13,"index":45},"end":{"line":4,"column":17,"index":49}}, + "literal": { + "type": "BooleanLiteral", + "start":45,"end":49,"loc":{"start":{"line":4,"column":13,"index":45},"end":{"line":4,"column":17,"index":49}}, + "value": true + } + } + ] + } + } + } + ], + "kind": "const" + }, + { + "type": "TSInterfaceDeclaration", + "start":51,"end":65,"loc":{"start":{"line":5,"column":0,"index":51},"end":{"line":5,"column":14,"index":65}}, + "id": { + "type": "Identifier", + "start":61,"end":62,"loc":{"start":{"line":5,"column":10,"index":61},"end":{"line":5,"column":11,"index":62},"identifierName":"I"}, + "name": "I" + }, + "body": { + "type": "TSInterfaceBody", + "start":63,"end":65,"loc":{"start":{"line":5,"column":12,"index":63},"end":{"line":5,"column":14,"index":65}}, + "body": [] + } + }, + { + "type": "VariableDeclaration", + "start":67,"end":84,"loc":{"start":{"line":7,"column":0,"index":67},"end":{"line":7,"column":17,"index":84}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":71,"end":84,"loc":{"start":{"line":7,"column":4,"index":71},"end":{"line":7,"column":17,"index":84}}, + "id": { + "type": "Identifier", + "start":71,"end":74,"loc":{"start":{"line":7,"column":4,"index":71},"end":{"line":7,"column":7,"index":74},"identifierName":"x10"}, + "name": "x10" + }, + "init": { + "type": "TSInstantiationExpression", + "start":77,"end":84,"loc":{"start":{"line":7,"column":10,"index":77},"end":{"line":7,"column":17,"index":84}}, + "expression": { + "type": "Identifier", + "start":77,"end":78,"loc":{"start":{"line":7,"column":10,"index":77},"end":{"line":7,"column":11,"index":78},"identifierName":"f"}, + "name": "f" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":78,"end":84,"loc":{"start":{"line":7,"column":11,"index":78},"end":{"line":7,"column":17,"index":84}}, + "params": [ + { + "type": "TSLiteralType", + "start":79,"end":83,"loc":{"start":{"line":7,"column":12,"index":79},"end":{"line":7,"column":16,"index":83}}, + "literal": { + "type": "BooleanLiteral", + "start":79,"end":83,"loc":{"start":{"line":7,"column":12,"index":79},"end":{"line":7,"column":16,"index":83}}, + "value": true + } + } + ] + } + } + } + ], + "kind": "let" + }, + { + "type": "ExpressionStatement", + "start":85,"end":95,"loc":{"start":{"line":8,"column":0,"index":85},"end":{"line":8,"column":10,"index":95}}, + "expression": { + "type": "CallExpression", + "start":85,"end":95,"loc":{"start":{"line":8,"column":0,"index":85},"end":{"line":8,"column":10,"index":95}}, + "callee": { + "type": "MemberExpression", + "start":85,"end":93,"loc":{"start":{"line":8,"column":0,"index":85},"end":{"line":8,"column":8,"index":93}}, + "object": { + "type": "ThisExpression", + "start":85,"end":89,"loc":{"start":{"line":8,"column":0,"index":85},"end":{"line":8,"column":4,"index":89}} + }, + "computed": false, + "property": { + "type": "Identifier", + "start":90,"end":93,"loc":{"start":{"line":8,"column":5,"index":90},"end":{"line":8,"column":8,"index":93},"identifierName":"bar"}, + "name": "bar" + } + }, + "arguments": [] + } + }, + { + "type": "VariableDeclaration", + "start":97,"end":114,"loc":{"start":{"line":10,"column":0,"index":97},"end":{"line":10,"column":17,"index":114}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":101,"end":114,"loc":{"start":{"line":10,"column":4,"index":101},"end":{"line":10,"column":17,"index":114}}, + "id": { + "type": "Identifier", + "start":101,"end":104,"loc":{"start":{"line":10,"column":4,"index":101},"end":{"line":10,"column":7,"index":104},"identifierName":"x11"}, + "name": "x11" + }, + "init": { + "type": "TSInstantiationExpression", + "start":107,"end":114,"loc":{"start":{"line":10,"column":10,"index":107},"end":{"line":10,"column":17,"index":114}}, + "expression": { + "type": "Identifier", + "start":107,"end":108,"loc":{"start":{"line":10,"column":10,"index":107},"end":{"line":10,"column":11,"index":108},"identifierName":"f"}, + "name": "f" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":108,"end":114,"loc":{"start":{"line":10,"column":11,"index":108},"end":{"line":10,"column":17,"index":114}}, + "params": [ + { + "type": "TSLiteralType", + "start":109,"end":113,"loc":{"start":{"line":10,"column":12,"index":109},"end":{"line":10,"column":16,"index":113}}, + "literal": { + "type": "BooleanLiteral", + "start":109,"end":113,"loc":{"start":{"line":10,"column":12,"index":109},"end":{"line":10,"column":16,"index":113}}, + "value": true + } + } + ] + } + } + } + ], + "kind": "let" + }, + { + "type": "FunctionDeclaration", + "start":115,"end":132,"loc":{"start":{"line":11,"column":0,"index":115},"end":{"line":11,"column":17,"index":132}}, + "id": { + "type": "Identifier", + "start":124,"end":127,"loc":{"start":{"line":11,"column":9,"index":124},"end":{"line":11,"column":12,"index":127},"identifierName":"bar"}, + "name": "bar" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":130,"end":132,"loc":{"start":{"line":11,"column":15,"index":130},"end":{"line":11,"column":17,"index":132}}, + "body": [], + "directives": [] + } + }, + { + "type": "VariableDeclaration", + "start":134,"end":151,"loc":{"start":{"line":13,"column":0,"index":134},"end":{"line":13,"column":17,"index":151}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":138,"end":151,"loc":{"start":{"line":13,"column":4,"index":138},"end":{"line":13,"column":17,"index":151}}, + "id": { + "type": "Identifier", + "start":138,"end":141,"loc":{"start":{"line":13,"column":4,"index":138},"end":{"line":13,"column":7,"index":141},"identifierName":"x12"}, + "name": "x12" + }, + "init": { + "type": "TSInstantiationExpression", + "start":144,"end":151,"loc":{"start":{"line":13,"column":10,"index":144},"end":{"line":13,"column":17,"index":151}}, + "expression": { + "type": "Identifier", + "start":144,"end":145,"loc":{"start":{"line":13,"column":10,"index":144},"end":{"line":13,"column":11,"index":145},"identifierName":"f"}, + "name": "f" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":145,"end":151,"loc":{"start":{"line":13,"column":11,"index":145},"end":{"line":13,"column":17,"index":151}}, + "params": [ + { + "type": "TSLiteralType", + "start":146,"end":150,"loc":{"start":{"line":13,"column":12,"index":146},"end":{"line":13,"column":16,"index":150}}, + "literal": { + "type": "BooleanLiteral", + "start":146,"end":150,"loc":{"start":{"line":13,"column":12,"index":146},"end":{"line":13,"column":16,"index":150}}, + "value": true + } + } + ] + } + } + } + ], + "kind": "let" + }, + { + "type": "ClassDeclaration", + "start":152,"end":162,"loc":{"start":{"line":14,"column":0,"index":152},"end":{"line":14,"column":10,"index":162}}, + "id": { + "type": "Identifier", + "start":158,"end":159,"loc":{"start":{"line":14,"column":6,"index":158},"end":{"line":14,"column":7,"index":159},"identifierName":"C"}, + "name": "C" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":160,"end":162,"loc":{"start":{"line":14,"column":8,"index":160},"end":{"line":14,"column":10,"index":162}}, + "body": [] + } + }, + { + "type": "VariableDeclaration", + "start":164,"end":181,"loc":{"start":{"line":16,"column":0,"index":164},"end":{"line":16,"column":17,"index":181}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":168,"end":181,"loc":{"start":{"line":16,"column":4,"index":168},"end":{"line":16,"column":17,"index":181}}, + "id": { + "type": "Identifier", + "start":168,"end":171,"loc":{"start":{"line":16,"column":4,"index":168},"end":{"line":16,"column":7,"index":171},"identifierName":"x13"}, + "name": "x13" + }, + "init": { + "type": "TSInstantiationExpression", + "start":174,"end":181,"loc":{"start":{"line":16,"column":10,"index":174},"end":{"line":16,"column":17,"index":181}}, + "expression": { + "type": "Identifier", + "start":174,"end":175,"loc":{"start":{"line":16,"column":10,"index":174},"end":{"line":16,"column":11,"index":175},"identifierName":"f"}, + "name": "f" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":175,"end":181,"loc":{"start":{"line":16,"column":11,"index":175},"end":{"line":16,"column":17,"index":181}}, + "params": [ + { + "type": "TSLiteralType", + "start":176,"end":180,"loc":{"start":{"line":16,"column":12,"index":176},"end":{"line":16,"column":16,"index":180}}, + "literal": { + "type": "BooleanLiteral", + "start":176,"end":180,"loc":{"start":{"line":16,"column":12,"index":176},"end":{"line":16,"column":16,"index":180}}, + "value": true + } + } + ] + } + } + } + ], + "kind": "let" + }, + { + "type": "ExpressionStatement", + "start":182,"end":187,"loc":{"start":{"line":17,"column":0,"index":182},"end":{"line":17,"column":5,"index":187}}, + "expression": { + "type": "CallExpression", + "start":182,"end":187,"loc":{"start":{"line":17,"column":0,"index":182},"end":{"line":17,"column":5,"index":187}}, + "callee": { + "type": "Identifier", + "start":182,"end":185,"loc":{"start":{"line":17,"column":0,"index":182},"end":{"line":17,"column":3,"index":185},"identifierName":"bar"}, + "name": "bar" + }, + "arguments": [] + } + }, + { + "type": "VariableDeclaration", + "start":189,"end":206,"loc":{"start":{"line":19,"column":0,"index":189},"end":{"line":19,"column":17,"index":206}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":193,"end":206,"loc":{"start":{"line":19,"column":4,"index":193},"end":{"line":19,"column":17,"index":206}}, + "id": { + "type": "Identifier", + "start":193,"end":196,"loc":{"start":{"line":19,"column":4,"index":193},"end":{"line":19,"column":7,"index":196},"identifierName":"x14"}, + "name": "x14" + }, + "init": { + "type": "TSInstantiationExpression", + "start":199,"end":206,"loc":{"start":{"line":19,"column":10,"index":199},"end":{"line":19,"column":17,"index":206}}, + "expression": { + "type": "Identifier", + "start":199,"end":200,"loc":{"start":{"line":19,"column":10,"index":199},"end":{"line":19,"column":11,"index":200},"identifierName":"f"}, + "name": "f" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":200,"end":206,"loc":{"start":{"line":19,"column":11,"index":200},"end":{"line":19,"column":17,"index":206}}, + "params": [ + { + "type": "TSLiteralType", + "start":201,"end":205,"loc":{"start":{"line":19,"column":12,"index":201},"end":{"line":19,"column":16,"index":205}}, + "literal": { + "type": "BooleanLiteral", + "start":201,"end":205,"loc":{"start":{"line":19,"column":12,"index":201},"end":{"line":19,"column":16,"index":205}}, + "value": true + } + } + ] + } + } + } + ], + "kind": "let" + }, + { + "type": "ExpressionStatement", + "start":207,"end":217,"loc":{"start":{"line":20,"column":0,"index":207},"end":{"line":20,"column":10,"index":217}}, + "expression": { + "type": "UnaryExpression", + "start":207,"end":217,"loc":{"start":{"line":20,"column":0,"index":207},"end":{"line":20,"column":10,"index":217}}, + "operator": "void", + "prefix": true, + "argument": { + "type": "CallExpression", + "start":212,"end":217,"loc":{"start":{"line":20,"column":5,"index":212},"end":{"line":20,"column":10,"index":217}}, + "callee": { + "type": "Identifier", + "start":212,"end":215,"loc":{"start":{"line":20,"column":5,"index":212},"end":{"line":20,"column":8,"index":215},"identifierName":"bar"}, + "name": "bar" + }, + "arguments": [] + } + } + }, + { + "type": "ClassDeclaration", + "start":219,"end":286,"loc":{"start":{"line":22,"column":0,"index":219},"end":{"line":25,"column":1,"index":286}}, + "id": { + "type": "Identifier", + "start":225,"end":227,"loc":{"start":{"line":22,"column":6,"index":225},"end":{"line":22,"column":8,"index":227},"identifierName":"C1"}, + "name": "C1" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":228,"end":286,"loc":{"start":{"line":22,"column":9,"index":228},"end":{"line":25,"column":1,"index":286}}, + "body": [ + { + "type": "ClassProperty", + "start":234,"end":263,"loc":{"start":{"line":23,"column":4,"index":234},"end":{"line":23,"column":33,"index":263}}, + "static": true, + "key": { + "type": "Identifier", + "start":241,"end":251,"loc":{"start":{"line":23,"column":11,"index":241},"end":{"line":23,"column":21,"index":251},"identifierName":"specialFoo"}, + "name": "specialFoo" + }, + "computed": false, + "value": { + "type": "TSInstantiationExpression", + "start":254,"end":263,"loc":{"start":{"line":23,"column":24,"index":254},"end":{"line":23,"column":33,"index":263}}, + "expression": { + "type": "Identifier", + "start":254,"end":255,"loc":{"start":{"line":23,"column":24,"index":254},"end":{"line":23,"column":25,"index":255},"identifierName":"f"}, + "name": "f" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":255,"end":263,"loc":{"start":{"line":23,"column":25,"index":255},"end":{"line":23,"column":33,"index":263}}, + "params": [ + { + "type": "TSStringKeyword", + "start":256,"end":262,"loc":{"start":{"line":23,"column":26,"index":256},"end":{"line":23,"column":32,"index":262}} + } + ] + } + } + }, + { + "type": "ClassProperty", + "start":268,"end":284,"loc":{"start":{"line":24,"column":4,"index":268},"end":{"line":24,"column":20,"index":284}}, + "static": true, + "key": { + "type": "Identifier", + "start":275,"end":278,"loc":{"start":{"line":24,"column":11,"index":275},"end":{"line":24,"column":14,"index":278},"identifierName":"bar"}, + "name": "bar" + }, + "computed": false, + "value": { + "type": "NumericLiteral", + "start":281,"end":284,"loc":{"start":{"line":24,"column":17,"index":281},"end":{"line":24,"column":20,"index":284}}, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + } + } + ] + } + }, + { + "type": "ClassDeclaration", + "start":288,"end":355,"loc":{"start":{"line":27,"column":0,"index":288},"end":{"line":30,"column":1,"index":355}}, + "id": { + "type": "Identifier", + "start":294,"end":296,"loc":{"start":{"line":27,"column":6,"index":294},"end":{"line":27,"column":8,"index":296},"identifierName":"C2"}, + "name": "C2" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":297,"end":355,"loc":{"start":{"line":27,"column":9,"index":297},"end":{"line":30,"column":1,"index":355}}, + "body": [ + { + "type": "ClassProperty", + "start":303,"end":332,"loc":{"start":{"line":28,"column":4,"index":303},"end":{"line":28,"column":33,"index":332}}, + "accessibility": "public", + "static": false, + "key": { + "type": "Identifier", + "start":310,"end":320,"loc":{"start":{"line":28,"column":11,"index":310},"end":{"line":28,"column":21,"index":320},"identifierName":"specialFoo"}, + "name": "specialFoo" + }, + "computed": false, + "value": { + "type": "TSInstantiationExpression", + "start":323,"end":332,"loc":{"start":{"line":28,"column":24,"index":323},"end":{"line":28,"column":33,"index":332}}, + "expression": { + "type": "Identifier", + "start":323,"end":324,"loc":{"start":{"line":28,"column":24,"index":323},"end":{"line":28,"column":25,"index":324},"identifierName":"f"}, + "name": "f" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":324,"end":332,"loc":{"start":{"line":28,"column":25,"index":324},"end":{"line":28,"column":33,"index":332}}, + "params": [ + { + "type": "TSStringKeyword", + "start":325,"end":331,"loc":{"start":{"line":28,"column":26,"index":325},"end":{"line":28,"column":32,"index":331}} + } + ] + } + } + }, + { + "type": "ClassProperty", + "start":337,"end":353,"loc":{"start":{"line":29,"column":4,"index":337},"end":{"line":29,"column":20,"index":353}}, + "accessibility": "public", + "static": false, + "key": { + "type": "Identifier", + "start":344,"end":347,"loc":{"start":{"line":29,"column":11,"index":344},"end":{"line":29,"column":14,"index":347},"identifierName":"bar"}, + "name": "bar" + }, + "computed": false, + "value": { + "type": "NumericLiteral", + "start":350,"end":353,"loc":{"start":{"line":29,"column":17,"index":350},"end":{"line":29,"column":20,"index":353}}, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + } + } + ] + } + }, + { + "type": "ClassDeclaration", + "start":357,"end":426,"loc":{"start":{"line":32,"column":0,"index":357},"end":{"line":35,"column":1,"index":426}}, + "id": { + "type": "Identifier", + "start":363,"end":365,"loc":{"start":{"line":32,"column":6,"index":363},"end":{"line":32,"column":8,"index":365},"identifierName":"C3"}, + "name": "C3" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":366,"end":426,"loc":{"start":{"line":32,"column":9,"index":366},"end":{"line":35,"column":1,"index":426}}, + "body": [ + { + "type": "ClassProperty", + "start":372,"end":402,"loc":{"start":{"line":33,"column":4,"index":372},"end":{"line":33,"column":34,"index":402}}, + "accessibility": "private", + "static": false, + "key": { + "type": "Identifier", + "start":380,"end":390,"loc":{"start":{"line":33,"column":12,"index":380},"end":{"line":33,"column":22,"index":390},"identifierName":"specialFoo"}, + "name": "specialFoo" + }, + "computed": false, + "value": { + "type": "TSInstantiationExpression", + "start":393,"end":402,"loc":{"start":{"line":33,"column":25,"index":393},"end":{"line":33,"column":34,"index":402}}, + "expression": { + "type": "Identifier", + "start":393,"end":394,"loc":{"start":{"line":33,"column":25,"index":393},"end":{"line":33,"column":26,"index":394},"identifierName":"f"}, + "name": "f" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":394,"end":402,"loc":{"start":{"line":33,"column":26,"index":394},"end":{"line":33,"column":34,"index":402}}, + "params": [ + { + "type": "TSStringKeyword", + "start":395,"end":401,"loc":{"start":{"line":33,"column":27,"index":395},"end":{"line":33,"column":33,"index":401}} + } + ] + } + } + }, + { + "type": "ClassProperty", + "start":407,"end":424,"loc":{"start":{"line":34,"column":4,"index":407},"end":{"line":34,"column":21,"index":424}}, + "accessibility": "private", + "static": false, + "key": { + "type": "Identifier", + "start":415,"end":418,"loc":{"start":{"line":34,"column":12,"index":415},"end":{"line":34,"column":15,"index":418},"identifierName":"bar"}, + "name": "bar" + }, + "computed": false, + "value": { + "type": "NumericLiteral", + "start":421,"end":424,"loc":{"start":{"line":34,"column":18,"index":421},"end":{"line":34,"column":21,"index":424}}, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + } + } + ] + } + }, + { + "type": "ClassDeclaration", + "start":428,"end":501,"loc":{"start":{"line":37,"column":0,"index":428},"end":{"line":40,"column":1,"index":501}}, + "id": { + "type": "Identifier", + "start":434,"end":436,"loc":{"start":{"line":37,"column":6,"index":434},"end":{"line":37,"column":8,"index":436},"identifierName":"C4"}, + "name": "C4" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":437,"end":501,"loc":{"start":{"line":37,"column":9,"index":437},"end":{"line":40,"column":1,"index":501}}, + "body": [ + { + "type": "ClassProperty", + "start":443,"end":475,"loc":{"start":{"line":38,"column":4,"index":443},"end":{"line":38,"column":36,"index":475}}, + "accessibility": "protected", + "static": false, + "key": { + "type": "Identifier", + "start":453,"end":463,"loc":{"start":{"line":38,"column":14,"index":453},"end":{"line":38,"column":24,"index":463},"identifierName":"specialFoo"}, + "name": "specialFoo" + }, + "computed": false, + "value": { + "type": "TSInstantiationExpression", + "start":466,"end":475,"loc":{"start":{"line":38,"column":27,"index":466},"end":{"line":38,"column":36,"index":475}}, + "expression": { + "type": "Identifier", + "start":466,"end":467,"loc":{"start":{"line":38,"column":27,"index":466},"end":{"line":38,"column":28,"index":467},"identifierName":"f"}, + "name": "f" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":467,"end":475,"loc":{"start":{"line":38,"column":28,"index":467},"end":{"line":38,"column":36,"index":475}}, + "params": [ + { + "type": "TSStringKeyword", + "start":468,"end":474,"loc":{"start":{"line":38,"column":29,"index":468},"end":{"line":38,"column":35,"index":474}} + } + ] + } + } + }, + { + "type": "ClassProperty", + "start":480,"end":499,"loc":{"start":{"line":39,"column":4,"index":480},"end":{"line":39,"column":23,"index":499}}, + "accessibility": "protected", + "static": false, + "key": { + "type": "Identifier", + "start":490,"end":493,"loc":{"start":{"line":39,"column":14,"index":490},"end":{"line":39,"column":17,"index":493},"identifierName":"bar"}, + "name": "bar" + }, + "computed": false, + "value": { + "type": "NumericLiteral", + "start":496,"end":499,"loc":{"start":{"line":39,"column":20,"index":496},"end":{"line":39,"column":23,"index":499}}, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + } + } + ] + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi/output.json index 3b45fde3d882..8cbeefa6081f 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi/output.json @@ -27,7 +27,7 @@ "start":11,"end":12,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":12,"index":12},"identifierName":"f"}, "name": "f" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":12,"end":18,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":18,"index":18}}, "params": [ @@ -92,7 +92,7 @@ "start":43,"end":44,"loc":{"start":{"line":4,"column":11,"index":43},"end":{"line":4,"column":12,"index":44},"identifierName":"f"}, "name": "f" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":44,"end":50,"loc":{"start":{"line":4,"column":12,"index":44},"end":{"line":4,"column":18,"index":50}}, "params": [ @@ -146,7 +146,7 @@ "start":77,"end":78,"loc":{"start":{"line":7,"column":10,"index":77},"end":{"line":7,"column":11,"index":78},"identifierName":"f"}, "name": "f" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":78,"end":84,"loc":{"start":{"line":7,"column":11,"index":78},"end":{"line":7,"column":17,"index":84}}, "params": [ @@ -209,7 +209,7 @@ "start":107,"end":108,"loc":{"start":{"line":10,"column":10,"index":107},"end":{"line":10,"column":11,"index":108},"identifierName":"f"}, "name": "f" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":108,"end":114,"loc":{"start":{"line":10,"column":11,"index":108},"end":{"line":10,"column":17,"index":114}}, "params": [ @@ -267,7 +267,7 @@ "start":144,"end":145,"loc":{"start":{"line":13,"column":10,"index":144},"end":{"line":13,"column":11,"index":145},"identifierName":"f"}, "name": "f" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":145,"end":151,"loc":{"start":{"line":13,"column":11,"index":145},"end":{"line":13,"column":17,"index":151}}, "params": [ @@ -322,7 +322,7 @@ "start":174,"end":175,"loc":{"start":{"line":16,"column":10,"index":174},"end":{"line":16,"column":11,"index":175},"identifierName":"f"}, "name": "f" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":175,"end":181,"loc":{"start":{"line":16,"column":11,"index":175},"end":{"line":16,"column":17,"index":181}}, "params": [ @@ -376,7 +376,7 @@ "start":199,"end":200,"loc":{"start":{"line":19,"column":10,"index":199},"end":{"line":19,"column":11,"index":200},"identifierName":"f"}, "name": "f" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":200,"end":206,"loc":{"start":{"line":19,"column":11,"index":200},"end":{"line":19,"column":17,"index":206}}, "params": [ @@ -447,7 +447,7 @@ "start":254,"end":255,"loc":{"start":{"line":23,"column":24,"index":254},"end":{"line":23,"column":25,"index":255},"identifierName":"f"}, "name": "f" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":255,"end":263,"loc":{"start":{"line":23,"column":25,"index":255},"end":{"line":23,"column":33,"index":263}}, "params": [ @@ -514,7 +514,7 @@ "start":323,"end":324,"loc":{"start":{"line":28,"column":24,"index":323},"end":{"line":28,"column":25,"index":324},"identifierName":"f"}, "name": "f" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":324,"end":332,"loc":{"start":{"line":28,"column":25,"index":324},"end":{"line":28,"column":33,"index":332}}, "params": [ @@ -582,7 +582,7 @@ "start":393,"end":394,"loc":{"start":{"line":33,"column":25,"index":393},"end":{"line":33,"column":26,"index":394},"identifierName":"f"}, "name": "f" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":394,"end":402,"loc":{"start":{"line":33,"column":26,"index":394},"end":{"line":33,"column":34,"index":402}}, "params": [ @@ -650,7 +650,7 @@ "start":466,"end":467,"loc":{"start":{"line":38,"column":27,"index":466},"end":{"line":38,"column":28,"index":467},"identifierName":"f"}, "name": "f" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":467,"end":475,"loc":{"start":{"line":38,"column":28,"index":467},"end":{"line":38,"column":36,"index":475}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-babel-7/input.ts new file mode 100644 index 000000000000..4c0bb8b26bb0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-babel-7/input.ts @@ -0,0 +1 @@ +makeBox \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-babel-7/output.json new file mode 100644 index 000000000000..d720bf866134 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-babel-7/output.json @@ -0,0 +1,39 @@ +{ + "type": "File", + "start":0,"end":15,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":15,"index":15}}, + "program": { + "type": "Program", + "start":0,"end":15,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":15,"index":15}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":15,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":15,"index":15}}, + "expression": { + "type": "TSInstantiationExpression", + "start":0,"end":15,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":15,"index":15}}, + "expression": { + "type": "Identifier", + "start":0,"end":7,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":7,"index":7},"identifierName":"makeBox"}, + "name": "makeBox" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":7,"end":15,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":15,"index":15}}, + "params": [ + { + "type": "TSNumberKeyword", + "start":8,"end":14,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":14,"index":14}} + } + ] + } + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator-babel-7/input.ts new file mode 100644 index 000000000000..e0e610b16ce3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator-babel-7/input.ts @@ -0,0 +1 @@ +a ?? c; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator-babel-7/output.json new file mode 100644 index 000000000000..d4c4be9e2caa --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator-babel-7/output.json @@ -0,0 +1,54 @@ +{ + "type": "File", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":10,"index":10}}, + "program": { + "type": "Program", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":10,"index":10}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":10,"index":10}}, + "expression": { + "type": "LogicalExpression", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":9,"index":9}}, + "left": { + "type": "TSInstantiationExpression", + "start":0,"end":4,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":4,"index":4}}, + "expression": { + "type": "Identifier", + "start":0,"end":1,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":1,"index":1},"identifierName":"a"}, + "name": "a" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":1,"end":4,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":4,"index":4}}, + "params": [ + { + "type": "TSTypeReference", + "start":2,"end":3,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":3,"index":3}}, + "typeName": { + "type": "Identifier", + "start":2,"end":3,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":3,"index":3},"identifierName":"b"}, + "name": "b" + } + } + ] + } + }, + "operator": "??", + "right": { + "type": "Identifier", + "start":8,"end":9,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":9,"index":9},"identifierName":"c"}, + "name": "c" + } + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator/output.json index d4c4be9e2caa..b646563d9d5e 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-binary-operator/output.json @@ -21,7 +21,7 @@ "start":0,"end":1,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":1,"index":1},"identifierName":"a"}, "name": "a" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":1,"end":4,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":4,"index":4}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain-babel-7/input.ts new file mode 100644 index 000000000000..33daac08b743 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain-babel-7/input.ts @@ -0,0 +1,2 @@ +a?.b; +a?.b(); diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain-babel-7/output.json new file mode 100644 index 000000000000..056ba0c8d6ea --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain-babel-7/output.json @@ -0,0 +1,96 @@ +{ + "type": "File", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":10,"index":19}}, + "program": { + "type": "Program", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":10,"index":19}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":8,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":8,"index":8}}, + "expression": { + "type": "TSInstantiationExpression", + "start":0,"end":7,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":7,"index":7}}, + "expression": { + "type": "OptionalMemberExpression", + "start":0,"end":4,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":4,"index":4}}, + "object": { + "type": "Identifier", + "start":0,"end":1,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":1,"index":1},"identifierName":"a"}, + "name": "a" + }, + "computed": false, + "property": { + "type": "Identifier", + "start":3,"end":4,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":4,"index":4},"identifierName":"b"}, + "name": "b" + }, + "optional": true + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":4,"end":7,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":7,"index":7}}, + "params": [ + { + "type": "TSTypeReference", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6}}, + "typeName": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6},"identifierName":"c"}, + "name": "c" + } + } + ] + } + } + }, + { + "type": "ExpressionStatement", + "start":9,"end":19,"loc":{"start":{"line":2,"column":0,"index":9},"end":{"line":2,"column":10,"index":19}}, + "expression": { + "type": "OptionalCallExpression", + "start":9,"end":18,"loc":{"start":{"line":2,"column":0,"index":9},"end":{"line":2,"column":9,"index":18}}, + "callee": { + "type": "OptionalMemberExpression", + "start":9,"end":13,"loc":{"start":{"line":2,"column":0,"index":9},"end":{"line":2,"column":4,"index":13}}, + "object": { + "type": "Identifier", + "start":9,"end":10,"loc":{"start":{"line":2,"column":0,"index":9},"end":{"line":2,"column":1,"index":10},"identifierName":"a"}, + "name": "a" + }, + "computed": false, + "property": { + "type": "Identifier", + "start":12,"end":13,"loc":{"start":{"line":2,"column":3,"index":12},"end":{"line":2,"column":4,"index":13},"identifierName":"b"}, + "name": "b" + }, + "optional": true + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":13,"end":16,"loc":{"start":{"line":2,"column":4,"index":13},"end":{"line":2,"column":7,"index":16}}, + "params": [ + { + "type": "TSTypeReference", + "start":14,"end":15,"loc":{"start":{"line":2,"column":5,"index":14},"end":{"line":2,"column":6,"index":15}}, + "typeName": { + "type": "Identifier", + "start":14,"end":15,"loc":{"start":{"line":2,"column":5,"index":14},"end":{"line":2,"column":6,"index":15},"identifierName":"c"}, + "name": "c" + } + } + ] + }, + "optional": false + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain/output.json index 056ba0c8d6ea..32e5880aa8ef 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-optional-chain/output.json @@ -29,7 +29,7 @@ }, "optional": true }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":4,"end":7,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":7,"index":7}}, "params": [ @@ -69,7 +69,7 @@ "optional": true }, "arguments": [], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":13,"end":16,"loc":{"start":{"line":2,"column":4,"index":13},"end":{"line":2,"column":7,"index":16}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access-babel-7/input.ts new file mode 100644 index 000000000000..610e565c36d5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access-babel-7/input.ts @@ -0,0 +1,13 @@ +// invalid +a.c; +a?.c; +a?.[c]; + +// valid +a?.(c); +(a).c; +(a)?.c; +(a)?.[c]; + +// longer, invalid +a?.b.d diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access-babel-7/output.json new file mode 100644 index 000000000000..6d5d7bd37547 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access-babel-7/output.json @@ -0,0 +1,408 @@ +{ + "type": "File", + "start":0,"end":123,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":13,"column":9,"index":123}}, + "errors": [ + "SyntaxError: Invalid property access after an instantiation expression. You can either wrap the instantiation expression in parentheses, or delete the type arguments. (2:4)", + "SyntaxError: Invalid property access after an instantiation expression. You can either wrap the instantiation expression in parentheses, or delete the type arguments. (3:4)", + "SyntaxError: Invalid property access after an instantiation expression. You can either wrap the instantiation expression in parentheses, or delete the type arguments. (4:4)", + "SyntaxError: Invalid property access after an instantiation expression. You can either wrap the instantiation expression in parentheses, or delete the type arguments. (13:7)" + ], + "program": { + "type": "Program", + "start":0,"end":123,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":13,"column":9,"index":123}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":11,"end":18,"loc":{"start":{"line":2,"column":0,"index":11},"end":{"line":2,"column":7,"index":18}}, + "expression": { + "type": "MemberExpression", + "start":11,"end":17,"loc":{"start":{"line":2,"column":0,"index":11},"end":{"line":2,"column":6,"index":17}}, + "object": { + "type": "TSInstantiationExpression", + "start":11,"end":15,"loc":{"start":{"line":2,"column":0,"index":11},"end":{"line":2,"column":4,"index":15}}, + "expression": { + "type": "Identifier", + "start":11,"end":12,"loc":{"start":{"line":2,"column":0,"index":11},"end":{"line":2,"column":1,"index":12},"identifierName":"a"}, + "name": "a" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":12,"end":15,"loc":{"start":{"line":2,"column":1,"index":12},"end":{"line":2,"column":4,"index":15}}, + "params": [ + { + "type": "TSTypeReference", + "start":13,"end":14,"loc":{"start":{"line":2,"column":2,"index":13},"end":{"line":2,"column":3,"index":14}}, + "typeName": { + "type": "Identifier", + "start":13,"end":14,"loc":{"start":{"line":2,"column":2,"index":13},"end":{"line":2,"column":3,"index":14},"identifierName":"b"}, + "name": "b" + } + } + ] + } + }, + "computed": false, + "property": { + "type": "Identifier", + "start":16,"end":17,"loc":{"start":{"line":2,"column":5,"index":16},"end":{"line":2,"column":6,"index":17},"identifierName":"c"}, + "name": "c" + } + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " invalid", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":10,"index":10}} + } + ] + }, + { + "type": "ExpressionStatement", + "start":19,"end":27,"loc":{"start":{"line":3,"column":0,"index":19},"end":{"line":3,"column":8,"index":27}}, + "expression": { + "type": "OptionalMemberExpression", + "start":19,"end":26,"loc":{"start":{"line":3,"column":0,"index":19},"end":{"line":3,"column":7,"index":26}}, + "object": { + "type": "TSInstantiationExpression", + "start":19,"end":23,"loc":{"start":{"line":3,"column":0,"index":19},"end":{"line":3,"column":4,"index":23}}, + "expression": { + "type": "Identifier", + "start":19,"end":20,"loc":{"start":{"line":3,"column":0,"index":19},"end":{"line":3,"column":1,"index":20},"identifierName":"a"}, + "name": "a" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":20,"end":23,"loc":{"start":{"line":3,"column":1,"index":20},"end":{"line":3,"column":4,"index":23}}, + "params": [ + { + "type": "TSTypeReference", + "start":21,"end":22,"loc":{"start":{"line":3,"column":2,"index":21},"end":{"line":3,"column":3,"index":22}}, + "typeName": { + "type": "Identifier", + "start":21,"end":22,"loc":{"start":{"line":3,"column":2,"index":21},"end":{"line":3,"column":3,"index":22},"identifierName":"b"}, + "name": "b" + } + } + ] + } + }, + "computed": false, + "property": { + "type": "Identifier", + "start":25,"end":26,"loc":{"start":{"line":3,"column":6,"index":25},"end":{"line":3,"column":7,"index":26},"identifierName":"c"}, + "name": "c" + }, + "optional": true + } + }, + { + "type": "ExpressionStatement", + "start":28,"end":38,"loc":{"start":{"line":4,"column":0,"index":28},"end":{"line":4,"column":10,"index":38}}, + "expression": { + "type": "OptionalMemberExpression", + "start":28,"end":37,"loc":{"start":{"line":4,"column":0,"index":28},"end":{"line":4,"column":9,"index":37}}, + "object": { + "type": "TSInstantiationExpression", + "start":28,"end":32,"loc":{"start":{"line":4,"column":0,"index":28},"end":{"line":4,"column":4,"index":32}}, + "expression": { + "type": "Identifier", + "start":28,"end":29,"loc":{"start":{"line":4,"column":0,"index":28},"end":{"line":4,"column":1,"index":29},"identifierName":"a"}, + "name": "a" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":29,"end":32,"loc":{"start":{"line":4,"column":1,"index":29},"end":{"line":4,"column":4,"index":32}}, + "params": [ + { + "type": "TSTypeReference", + "start":30,"end":31,"loc":{"start":{"line":4,"column":2,"index":30},"end":{"line":4,"column":3,"index":31}}, + "typeName": { + "type": "Identifier", + "start":30,"end":31,"loc":{"start":{"line":4,"column":2,"index":30},"end":{"line":4,"column":3,"index":31},"identifierName":"b"}, + "name": "b" + } + } + ] + } + }, + "computed": true, + "property": { + "type": "Identifier", + "start":35,"end":36,"loc":{"start":{"line":4,"column":7,"index":35},"end":{"line":4,"column":8,"index":36},"identifierName":"c"}, + "name": "c" + }, + "optional": true + }, + "trailingComments": [ + { + "type": "CommentLine", + "value": " valid", + "start":40,"end":48,"loc":{"start":{"line":6,"column":0,"index":40},"end":{"line":6,"column":8,"index":48}} + } + ] + }, + { + "type": "ExpressionStatement", + "start":49,"end":59,"loc":{"start":{"line":7,"column":0,"index":49},"end":{"line":7,"column":10,"index":59}}, + "expression": { + "type": "OptionalCallExpression", + "start":49,"end":58,"loc":{"start":{"line":7,"column":0,"index":49},"end":{"line":7,"column":9,"index":58}}, + "callee": { + "type": "TSInstantiationExpression", + "start":49,"end":53,"loc":{"start":{"line":7,"column":0,"index":49},"end":{"line":7,"column":4,"index":53}}, + "expression": { + "type": "Identifier", + "start":49,"end":50,"loc":{"start":{"line":7,"column":0,"index":49},"end":{"line":7,"column":1,"index":50},"identifierName":"a"}, + "name": "a" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":50,"end":53,"loc":{"start":{"line":7,"column":1,"index":50},"end":{"line":7,"column":4,"index":53}}, + "params": [ + { + "type": "TSTypeReference", + "start":51,"end":52,"loc":{"start":{"line":7,"column":2,"index":51},"end":{"line":7,"column":3,"index":52}}, + "typeName": { + "type": "Identifier", + "start":51,"end":52,"loc":{"start":{"line":7,"column":2,"index":51},"end":{"line":7,"column":3,"index":52},"identifierName":"b"}, + "name": "b" + } + } + ] + } + }, + "optional": true, + "arguments": [ + { + "type": "Identifier", + "start":56,"end":57,"loc":{"start":{"line":7,"column":7,"index":56},"end":{"line":7,"column":8,"index":57},"identifierName":"c"}, + "name": "c" + } + ] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " valid", + "start":40,"end":48,"loc":{"start":{"line":6,"column":0,"index":40},"end":{"line":6,"column":8,"index":48}} + } + ] + }, + { + "type": "ExpressionStatement", + "start":60,"end":69,"loc":{"start":{"line":8,"column":0,"index":60},"end":{"line":8,"column":9,"index":69}}, + "expression": { + "type": "MemberExpression", + "start":60,"end":68,"loc":{"start":{"line":8,"column":0,"index":60},"end":{"line":8,"column":8,"index":68}}, + "object": { + "type": "TSInstantiationExpression", + "start":61,"end":65,"loc":{"start":{"line":8,"column":1,"index":61},"end":{"line":8,"column":5,"index":65}}, + "expression": { + "type": "Identifier", + "start":61,"end":62,"loc":{"start":{"line":8,"column":1,"index":61},"end":{"line":8,"column":2,"index":62},"identifierName":"a"}, + "name": "a" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":62,"end":65,"loc":{"start":{"line":8,"column":2,"index":62},"end":{"line":8,"column":5,"index":65}}, + "params": [ + { + "type": "TSTypeReference", + "start":63,"end":64,"loc":{"start":{"line":8,"column":3,"index":63},"end":{"line":8,"column":4,"index":64}}, + "typeName": { + "type": "Identifier", + "start":63,"end":64,"loc":{"start":{"line":8,"column":3,"index":63},"end":{"line":8,"column":4,"index":64},"identifierName":"b"}, + "name": "b" + } + } + ] + }, + "extra": { + "parenthesized": true, + "parenStart": 60 + } + }, + "computed": false, + "property": { + "type": "Identifier", + "start":67,"end":68,"loc":{"start":{"line":8,"column":7,"index":67},"end":{"line":8,"column":8,"index":68},"identifierName":"c"}, + "name": "c" + } + } + }, + { + "type": "ExpressionStatement", + "start":70,"end":80,"loc":{"start":{"line":9,"column":0,"index":70},"end":{"line":9,"column":10,"index":80}}, + "expression": { + "type": "OptionalMemberExpression", + "start":70,"end":79,"loc":{"start":{"line":9,"column":0,"index":70},"end":{"line":9,"column":9,"index":79}}, + "object": { + "type": "TSInstantiationExpression", + "start":71,"end":75,"loc":{"start":{"line":9,"column":1,"index":71},"end":{"line":9,"column":5,"index":75}}, + "expression": { + "type": "Identifier", + "start":71,"end":72,"loc":{"start":{"line":9,"column":1,"index":71},"end":{"line":9,"column":2,"index":72},"identifierName":"a"}, + "name": "a" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":72,"end":75,"loc":{"start":{"line":9,"column":2,"index":72},"end":{"line":9,"column":5,"index":75}}, + "params": [ + { + "type": "TSTypeReference", + "start":73,"end":74,"loc":{"start":{"line":9,"column":3,"index":73},"end":{"line":9,"column":4,"index":74}}, + "typeName": { + "type": "Identifier", + "start":73,"end":74,"loc":{"start":{"line":9,"column":3,"index":73},"end":{"line":9,"column":4,"index":74},"identifierName":"b"}, + "name": "b" + } + } + ] + }, + "extra": { + "parenthesized": true, + "parenStart": 70 + } + }, + "computed": false, + "property": { + "type": "Identifier", + "start":78,"end":79,"loc":{"start":{"line":9,"column":8,"index":78},"end":{"line":9,"column":9,"index":79},"identifierName":"c"}, + "name": "c" + }, + "optional": true + } + }, + { + "type": "ExpressionStatement", + "start":81,"end":93,"loc":{"start":{"line":10,"column":0,"index":81},"end":{"line":10,"column":12,"index":93}}, + "expression": { + "type": "OptionalMemberExpression", + "start":81,"end":92,"loc":{"start":{"line":10,"column":0,"index":81},"end":{"line":10,"column":11,"index":92}}, + "object": { + "type": "TSInstantiationExpression", + "start":82,"end":86,"loc":{"start":{"line":10,"column":1,"index":82},"end":{"line":10,"column":5,"index":86}}, + "expression": { + "type": "Identifier", + "start":82,"end":83,"loc":{"start":{"line":10,"column":1,"index":82},"end":{"line":10,"column":2,"index":83},"identifierName":"a"}, + "name": "a" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":83,"end":86,"loc":{"start":{"line":10,"column":2,"index":83},"end":{"line":10,"column":5,"index":86}}, + "params": [ + { + "type": "TSTypeReference", + "start":84,"end":85,"loc":{"start":{"line":10,"column":3,"index":84},"end":{"line":10,"column":4,"index":85}}, + "typeName": { + "type": "Identifier", + "start":84,"end":85,"loc":{"start":{"line":10,"column":3,"index":84},"end":{"line":10,"column":4,"index":85},"identifierName":"b"}, + "name": "b" + } + } + ] + }, + "extra": { + "parenthesized": true, + "parenStart": 81 + } + }, + "computed": true, + "property": { + "type": "Identifier", + "start":90,"end":91,"loc":{"start":{"line":10,"column":9,"index":90},"end":{"line":10,"column":10,"index":91},"identifierName":"c"}, + "name": "c" + }, + "optional": true + }, + "trailingComments": [ + { + "type": "CommentLine", + "value": " longer, invalid", + "start":95,"end":113,"loc":{"start":{"line":12,"column":0,"index":95},"end":{"line":12,"column":18,"index":113}} + } + ] + }, + { + "type": "ExpressionStatement", + "start":114,"end":123,"loc":{"start":{"line":13,"column":0,"index":114},"end":{"line":13,"column":9,"index":123}}, + "expression": { + "type": "OptionalMemberExpression", + "start":114,"end":123,"loc":{"start":{"line":13,"column":0,"index":114},"end":{"line":13,"column":9,"index":123}}, + "object": { + "type": "TSInstantiationExpression", + "start":114,"end":121,"loc":{"start":{"line":13,"column":0,"index":114},"end":{"line":13,"column":7,"index":121}}, + "expression": { + "type": "OptionalMemberExpression", + "start":114,"end":118,"loc":{"start":{"line":13,"column":0,"index":114},"end":{"line":13,"column":4,"index":118}}, + "object": { + "type": "Identifier", + "start":114,"end":115,"loc":{"start":{"line":13,"column":0,"index":114},"end":{"line":13,"column":1,"index":115},"identifierName":"a"}, + "name": "a" + }, + "computed": false, + "property": { + "type": "Identifier", + "start":117,"end":118,"loc":{"start":{"line":13,"column":3,"index":117},"end":{"line":13,"column":4,"index":118},"identifierName":"b"}, + "name": "b" + }, + "optional": true + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":118,"end":121,"loc":{"start":{"line":13,"column":4,"index":118},"end":{"line":13,"column":7,"index":121}}, + "params": [ + { + "type": "TSTypeReference", + "start":119,"end":120,"loc":{"start":{"line":13,"column":5,"index":119},"end":{"line":13,"column":6,"index":120}}, + "typeName": { + "type": "Identifier", + "start":119,"end":120,"loc":{"start":{"line":13,"column":5,"index":119},"end":{"line":13,"column":6,"index":120},"identifierName":"c"}, + "name": "c" + } + } + ] + } + }, + "computed": false, + "property": { + "type": "Identifier", + "start":122,"end":123,"loc":{"start":{"line":13,"column":8,"index":122},"end":{"line":13,"column":9,"index":123},"identifierName":"d"}, + "name": "d" + }, + "optional": false + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " longer, invalid", + "start":95,"end":113,"loc":{"start":{"line":12,"column":0,"index":95},"end":{"line":12,"column":18,"index":113}} + } + ] + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + }, + "comments": [ + { + "type": "CommentLine", + "value": " invalid", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":10,"index":10}} + }, + { + "type": "CommentLine", + "value": " valid", + "start":40,"end":48,"loc":{"start":{"line":6,"column":0,"index":40},"end":{"line":6,"column":8,"index":48}} + }, + { + "type": "CommentLine", + "value": " longer, invalid", + "start":95,"end":113,"loc":{"start":{"line":12,"column":0,"index":95},"end":{"line":12,"column":18,"index":113}} + } + ] +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access/output.json index 6d5d7bd37547..1f85003f097b 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-property-access/output.json @@ -27,7 +27,7 @@ "start":11,"end":12,"loc":{"start":{"line":2,"column":0,"index":11},"end":{"line":2,"column":1,"index":12},"identifierName":"a"}, "name": "a" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":12,"end":15,"loc":{"start":{"line":2,"column":1,"index":12},"end":{"line":2,"column":4,"index":15}}, "params": [ @@ -72,7 +72,7 @@ "start":19,"end":20,"loc":{"start":{"line":3,"column":0,"index":19},"end":{"line":3,"column":1,"index":20},"identifierName":"a"}, "name": "a" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":20,"end":23,"loc":{"start":{"line":3,"column":1,"index":20},"end":{"line":3,"column":4,"index":23}}, "params": [ @@ -111,7 +111,7 @@ "start":28,"end":29,"loc":{"start":{"line":4,"column":0,"index":28},"end":{"line":4,"column":1,"index":29},"identifierName":"a"}, "name": "a" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":29,"end":32,"loc":{"start":{"line":4,"column":1,"index":29},"end":{"line":4,"column":4,"index":32}}, "params": [ @@ -157,7 +157,7 @@ "start":49,"end":50,"loc":{"start":{"line":7,"column":0,"index":49},"end":{"line":7,"column":1,"index":50},"identifierName":"a"}, "name": "a" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":50,"end":53,"loc":{"start":{"line":7,"column":1,"index":50},"end":{"line":7,"column":4,"index":53}}, "params": [ @@ -204,7 +204,7 @@ "start":61,"end":62,"loc":{"start":{"line":8,"column":1,"index":61},"end":{"line":8,"column":2,"index":62},"identifierName":"a"}, "name": "a" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":62,"end":65,"loc":{"start":{"line":8,"column":2,"index":62},"end":{"line":8,"column":5,"index":65}}, "params": [ @@ -246,7 +246,7 @@ "start":71,"end":72,"loc":{"start":{"line":9,"column":1,"index":71},"end":{"line":9,"column":2,"index":72},"identifierName":"a"}, "name": "a" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":72,"end":75,"loc":{"start":{"line":9,"column":2,"index":72},"end":{"line":9,"column":5,"index":75}}, "params": [ @@ -289,7 +289,7 @@ "start":82,"end":83,"loc":{"start":{"line":10,"column":1,"index":82},"end":{"line":10,"column":2,"index":83},"identifierName":"a"}, "name": "a" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":83,"end":86,"loc":{"start":{"line":10,"column":2,"index":83},"end":{"line":10,"column":5,"index":86}}, "params": [ @@ -350,7 +350,7 @@ }, "optional": true }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":118,"end":121,"loc":{"start":{"line":13,"column":4,"index":118},"end":{"line":13,"column":7,"index":121}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression/output.json index d720bf866134..32f6475688b5 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression/output.json @@ -18,7 +18,7 @@ "start":0,"end":7,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":7,"index":7},"identifierName":"makeBox"}, "name": "makeBox" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":7,"end":15,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":15,"index":15}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-babel-7/input.ts new file mode 100644 index 000000000000..d474bb65c31d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-babel-7/input.ts @@ -0,0 +1,2 @@ +new C(); +new C(); diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-babel-7/output.json new file mode 100644 index 000000000000..ea9b9b14db60 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-babel-7/output.json @@ -0,0 +1,83 @@ +{ + "type": "File", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":14,"index":26}}, + "program": { + "type": "Program", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":14,"index":26}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":11,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":11,"index":11}}, + "expression": { + "type": "NewExpression", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":10,"index":10}}, + "callee": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"C"}, + "name": "C" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":5,"end":8,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":8,"index":8}}, + "params": [ + { + "type": "TSTypeReference", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7}}, + "typeName": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "arguments": [] + } + }, + { + "type": "ExpressionStatement", + "start":12,"end":26,"loc":{"start":{"line":2,"column":0,"index":12},"end":{"line":2,"column":14,"index":26}}, + "expression": { + "type": "NewExpression", + "start":12,"end":25,"loc":{"start":{"line":2,"column":0,"index":12},"end":{"line":2,"column":13,"index":25}}, + "callee": { + "type": "Identifier", + "start":16,"end":17,"loc":{"start":{"line":2,"column":4,"index":16},"end":{"line":2,"column":5,"index":17},"identifierName":"C"}, + "name": "C" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":17,"end":23,"loc":{"start":{"line":2,"column":5,"index":17},"end":{"line":2,"column":11,"index":23}}, + "params": [ + { + "type": "TSTypeReference", + "start":18,"end":19,"loc":{"start":{"line":2,"column":6,"index":18},"end":{"line":2,"column":7,"index":19}}, + "typeName": { + "type": "Identifier", + "start":18,"end":19,"loc":{"start":{"line":2,"column":6,"index":18},"end":{"line":2,"column":7,"index":19},"identifierName":"T"}, + "name": "T" + } + }, + { + "type": "TSTypeReference", + "start":21,"end":22,"loc":{"start":{"line":2,"column":9,"index":21},"end":{"line":2,"column":10,"index":22}}, + "typeName": { + "type": "Identifier", + "start":21,"end":22,"loc":{"start":{"line":2,"column":9,"index":21},"end":{"line":2,"column":10,"index":22},"identifierName":"U"}, + "name": "U" + } + } + ] + }, + "arguments": [] + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3-babel-7/input.ts new file mode 100644 index 000000000000..68ec919a9742 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3-babel-7/input.ts @@ -0,0 +1,2 @@ +new A < B > +C diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3-babel-7/output.json new file mode 100644 index 000000000000..864c9593bd06 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3-babel-7/output.json @@ -0,0 +1,54 @@ +{ + "type": "File", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":1,"index":13}}, + "program": { + "type": "Program", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":1,"index":13}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":11,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":11,"index":11}}, + "expression": { + "type": "NewExpression", + "start":0,"end":11,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":11,"index":11}}, + "callee": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"A"}, + "name": "A" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":6,"end":11,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":11,"index":11}}, + "params": [ + { + "type": "TSTypeReference", + "start":8,"end":9,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":9,"index":9}}, + "typeName": { + "type": "Identifier", + "start":8,"end":9,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":9,"index":9},"identifierName":"B"}, + "name": "B" + } + } + ] + }, + "arguments": [] + } + }, + { + "type": "ExpressionStatement", + "start":12,"end":13,"loc":{"start":{"line":2,"column":0,"index":12},"end":{"line":2,"column":1,"index":13}}, + "expression": { + "type": "Identifier", + "start":12,"end":13,"loc":{"start":{"line":2,"column":0,"index":12},"end":{"line":2,"column":1,"index":13},"identifierName":"C"}, + "name": "C" + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3/output.json index 864c9593bd06..05e68aa27930 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-false-positive-3/output.json @@ -18,7 +18,7 @@ "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"A"}, "name": "A" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":6,"end":11,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":11,"index":11}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi-babel-7/input.ts new file mode 100644 index 000000000000..bb91b556bbe4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi-babel-7/input.ts @@ -0,0 +1,3 @@ +new A + +if (0); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi-babel-7/output.json new file mode 100644 index 000000000000..ee0a50c5539d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi-babel-7/output.json @@ -0,0 +1,63 @@ +{ + "type": "File", + "start":0,"end":17,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":7,"index":17}}, + "program": { + "type": "Program", + "start":0,"end":17,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":7,"index":17}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":8,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":8,"index":8}}, + "expression": { + "type": "NewExpression", + "start":0,"end":8,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":8,"index":8}}, + "callee": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"A"}, + "name": "A" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":5,"end":8,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":8,"index":8}}, + "params": [ + { + "type": "TSTypeReference", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7}}, + "typeName": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "arguments": [] + } + }, + { + "type": "IfStatement", + "start":10,"end":17,"loc":{"start":{"line":3,"column":0,"index":10},"end":{"line":3,"column":7,"index":17}}, + "test": { + "type": "NumericLiteral", + "start":14,"end":15,"loc":{"start":{"line":3,"column":4,"index":14},"end":{"line":3,"column":5,"index":15}}, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + }, + "consequent": { + "type": "EmptyStatement", + "start":16,"end":17,"loc":{"start":{"line":3,"column":6,"index":16},"end":{"line":3,"column":7,"index":17}} + }, + "alternate": null + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi/output.json index ee0a50c5539d..1be9b9ba663f 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-asi/output.json @@ -18,7 +18,7 @@ "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"A"}, "name": "A" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":5,"end":8,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":8,"index":8}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-babel-7/input.ts new file mode 100644 index 000000000000..458a4296606e --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-babel-7/input.ts @@ -0,0 +1 @@ +new A; diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-babel-7/output.json new file mode 100644 index 000000000000..0c706f8374c9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-babel-7/output.json @@ -0,0 +1,45 @@ +{ + "type": "File", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":9,"index":9}}, + "program": { + "type": "Program", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":9,"index":9}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":9,"index":9}}, + "expression": { + "type": "NewExpression", + "start":0,"end":8,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":8,"index":8}}, + "callee": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"A"}, + "name": "A" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":5,"end":8,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":8,"index":8}}, + "params": [ + { + "type": "TSTypeReference", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7}}, + "typeName": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "arguments": [] + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon-babel-7/input.ts new file mode 100644 index 000000000000..dba5a427bfa0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon-babel-7/input.ts @@ -0,0 +1 @@ +new A if (0); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon-babel-7/output.json new file mode 100644 index 000000000000..0f892d439c19 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon-babel-7/output.json @@ -0,0 +1,66 @@ +{ + "type": "File", + "start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}}, + "errors": [ + "SyntaxError: Missing semicolon. (1:8)" + ], + "program": { + "type": "Program", + "start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":8,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":8,"index":8}}, + "expression": { + "type": "NewExpression", + "start":0,"end":8,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":8,"index":8}}, + "callee": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"A"}, + "name": "A" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":5,"end":8,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":8,"index":8}}, + "params": [ + { + "type": "TSTypeReference", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7}}, + "typeName": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "arguments": [] + } + }, + { + "type": "IfStatement", + "start":9,"end":16,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":16,"index":16}}, + "test": { + "type": "NumericLiteral", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13,"index":13},"end":{"line":1,"column":14,"index":14}}, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + }, + "consequent": { + "type": "EmptyStatement", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16}} + }, + "alternate": null + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon/output.json index 0f892d439c19..240c57769084 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments-missing-semicolon/output.json @@ -21,7 +21,7 @@ "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"A"}, "name": "A" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":5,"end":8,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":8,"index":8}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments/output.json index 0c706f8374c9..e446865825ee 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new-without-arguments/output.json @@ -18,7 +18,7 @@ "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"A"}, "name": "A" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":5,"end":8,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":8,"index":8}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/new/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/new/output.json index ea9b9b14db60..92c7fdcbe208 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/new/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/new/output.json @@ -18,7 +18,7 @@ "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"C"}, "name": "C" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":5,"end":8,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":8,"index":8}}, "params": [ @@ -47,7 +47,7 @@ "start":16,"end":17,"loc":{"start":{"line":2,"column":4,"index":16},"end":{"line":2,"column":5,"index":17},"identifierName":"C"}, "name": "C" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":17,"end":23,"loc":{"start":{"line":2,"column":5,"index":17},"end":{"line":2,"column":11,"index":23}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-babel-7/input.ts new file mode 100644 index 000000000000..53bbc3e3edbe --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-babel-7/input.ts @@ -0,0 +1 @@ +f``; diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-babel-7/output.json new file mode 100644 index 000000000000..64ab2570ed86 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-babel-7/output.json @@ -0,0 +1,60 @@ +{ + "type": "File", + "start":0,"end":7,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":7,"index":7}}, + "program": { + "type": "Program", + "start":0,"end":7,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":7,"index":7}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":7,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":7,"index":7}}, + "expression": { + "type": "TaggedTemplateExpression", + "start":0,"end":6,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":6,"index":6}}, + "tag": { + "type": "Identifier", + "start":0,"end":1,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":1,"index":1},"identifierName":"f"}, + "name": "f" + }, + "quasi": { + "type": "TemplateLiteral", + "start":4,"end":6,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":6,"index":6}}, + "expressions": [], + "quasis": [ + { + "type": "TemplateElement", + "start":5,"end":5,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":5,"index":5}}, + "value": { + "raw": "", + "cooked": "" + }, + "tail": true + } + ] + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":1,"end":4,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":4,"index":4}}, + "params": [ + { + "type": "TSTypeReference", + "start":2,"end":3,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":3,"index":3}}, + "typeName": { + "type": "Identifier", + "start":2,"end":3,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":3,"index":3},"identifierName":"T"}, + "name": "T" + } + } + ] + } + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi-babel-7/input.ts new file mode 100644 index 000000000000..b540adf24f6e --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi-babel-7/input.ts @@ -0,0 +1,2 @@ +new C +`` diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi-babel-7/output.json new file mode 100644 index 000000000000..c3b1ece28fe3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi-babel-7/output.json @@ -0,0 +1,65 @@ +{ + "type": "File", + "start":0,"end":11,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":2,"index":11}}, + "program": { + "type": "Program", + "start":0,"end":11,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":2,"index":11}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":11,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":2,"index":11}}, + "expression": { + "type": "NewExpression", + "start":0,"end":11,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":2,"index":11}}, + "callee": { + "type": "TaggedTemplateExpression", + "start":4,"end":11,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":2,"column":2,"index":11}}, + "tag": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":5,"index":5},"identifierName":"C"}, + "name": "C" + }, + "quasi": { + "type": "TemplateLiteral", + "start":9,"end":11,"loc":{"start":{"line":2,"column":0,"index":9},"end":{"line":2,"column":2,"index":11}}, + "expressions": [], + "quasis": [ + { + "type": "TemplateElement", + "start":10,"end":10,"loc":{"start":{"line":2,"column":1,"index":10},"end":{"line":2,"column":1,"index":10}}, + "value": { + "raw": "", + "cooked": "" + }, + "tail": true + } + ] + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":5,"end":8,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":8,"index":8}}, + "params": [ + { + "type": "TSTypeReference", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7}}, + "typeName": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7},"identifierName":"T"}, + "name": "T" + } + } + ] + } + }, + "arguments": [] + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi/output.json index c3b1ece28fe3..0274bfa2abd2 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template-no-asi/output.json @@ -37,7 +37,7 @@ } ] }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":5,"end":8,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":8,"index":8}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template/output.json index 64ab2570ed86..96caba696d69 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tagged-template/output.json @@ -34,7 +34,7 @@ } ] }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":1,"end":4,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":4,"index":4}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx-babel-7/input.ts new file mode 100644 index 000000000000..520e35ee9097 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx-babel-7/input.ts @@ -0,0 +1,2 @@ +>; +/>; diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx-babel-7/options.json new file mode 100644 index 000000000000..940686c94219 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx-babel-7/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "jsx", + "typescript" + ], + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx-babel-7/output.json new file mode 100644 index 000000000000..d8b3757a2d21 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx-babel-7/output.json @@ -0,0 +1,86 @@ +{ + "type": "File", + "start":0,"end":30,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":13,"index":30}}, + "program": { + "type": "Program", + "start":0,"end":30,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":13,"index":30}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}}, + "expression": { + "type": "JSXElement", + "start":0,"end":15,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":15,"index":15}}, + "openingElement": { + "type": "JSXOpeningElement", + "start":0,"end":11,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":11,"index":11}}, + "name": { + "type": "JSXIdentifier", + "start":1,"end":2,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":2,"index":2}}, + "name": "C" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":2,"end":10,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":10,"index":10}}, + "params": [ + { + "type": "TSNumberKeyword", + "start":3,"end":9,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":9,"index":9}} + } + ] + }, + "attributes": [], + "selfClosing": false + }, + "closingElement": { + "type": "JSXClosingElement", + "start":11,"end":15,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":15,"index":15}}, + "name": { + "type": "JSXIdentifier", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13,"index":13},"end":{"line":1,"column":14,"index":14}}, + "name": "C" + } + }, + "children": [] + } + }, + { + "type": "ExpressionStatement", + "start":17,"end":30,"loc":{"start":{"line":2,"column":0,"index":17},"end":{"line":2,"column":13,"index":30}}, + "expression": { + "type": "JSXElement", + "start":17,"end":29,"loc":{"start":{"line":2,"column":0,"index":17},"end":{"line":2,"column":12,"index":29}}, + "openingElement": { + "type": "JSXOpeningElement", + "start":17,"end":29,"loc":{"start":{"line":2,"column":0,"index":17},"end":{"line":2,"column":12,"index":29}}, + "name": { + "type": "JSXIdentifier", + "start":18,"end":19,"loc":{"start":{"line":2,"column":1,"index":18},"end":{"line":2,"column":2,"index":19}}, + "name": "C" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":19,"end":27,"loc":{"start":{"line":2,"column":2,"index":19},"end":{"line":2,"column":10,"index":27}}, + "params": [ + { + "type": "TSNumberKeyword", + "start":20,"end":26,"loc":{"start":{"line":2,"column":3,"index":20},"end":{"line":2,"column":9,"index":26}} + } + ] + }, + "attributes": [], + "selfClosing": true + }, + "closingElement": null, + "children": [] + } + } + ], + "directives": [], + "extra": { + "topLevelAwait": false + } + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx/options.json index aa8780ac5180..dfd2ba75d098 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx/options.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx/options.json @@ -1,3 +1,7 @@ { - "plugins": ["jsx", "typescript"] + "plugins": [ + "jsx", + "typescript" + ], + "BABEL_8_BREAKING": true } diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx/output.json index d8b3757a2d21..b9268c2ddec7 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments/tsx/output.json @@ -21,7 +21,7 @@ "start":1,"end":2,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":2,"index":2}}, "name": "C" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":2,"end":10,"loc":{"start":{"line":1,"column":2,"index":2},"end":{"line":1,"column":10,"index":10}}, "params": [ @@ -60,7 +60,7 @@ "start":18,"end":19,"loc":{"start":{"line":2,"column":1,"index":18},"end":{"line":2,"column":2,"index":19}}, "name": "C" }, - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":19,"end":27,"loc":{"start":{"line":2,"column":2,"index":19},"end":{"line":2,"column":10,"index":27}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/types/variance-annotations-with-jsx/output.json b/packages/babel-parser/test/fixtures/typescript/types/variance-annotations-with-jsx/output.json index 59259e57376b..94d84dffb72f 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/variance-annotations-with-jsx/output.json +++ b/packages/babel-parser/test/fixtures/typescript/types/variance-annotations-with-jsx/output.json @@ -3928,7 +3928,7 @@ "name": "qq" } ], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":3278,"end":3331,"loc":{"start":{"line":163,"column":13,"index":3278},"end":{"line":163,"column":66,"index":3331}}, "params": [ diff --git a/packages/babel-parser/test/fixtures/typescript/types/variance-annotations/output.json b/packages/babel-parser/test/fixtures/typescript/types/variance-annotations/output.json index 8f3e2c7e93b9..67578788fa1a 100644 --- a/packages/babel-parser/test/fixtures/typescript/types/variance-annotations/output.json +++ b/packages/babel-parser/test/fixtures/typescript/types/variance-annotations/output.json @@ -3862,7 +3862,7 @@ "name": "qq" } ], - "typeParameters": { + "typeArguments": { "type": "TSTypeParameterInstantiation", "start":3243,"end":3296,"loc":{"start":{"line":160,"column":13,"index":3243},"end":{"line":160,"column":66,"index":3296}}, "params": [ diff --git a/packages/babel-plugin-transform-typescript/src/index.ts b/packages/babel-plugin-transform-typescript/src/index.ts index 574c85c84539..36072e900c21 100644 --- a/packages/babel-plugin-transform-typescript/src/index.ts +++ b/packages/babel-plugin-transform-typescript/src/index.ts @@ -694,23 +694,50 @@ export default declare((api, opts: Options) => { }, CallExpression(path) { - path.node.typeParameters = null; + if (process.env.BABEL_8_BREAKING) { + path.node.typeArguments = null; + } else { + // @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8 + path.node.typeParameters = null; + } }, OptionalCallExpression(path) { - path.node.typeParameters = null; + if (process.env.BABEL_8_BREAKING) { + path.node.typeArguments = null; + } else { + // @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8 + path.node.typeParameters = null; + } }, NewExpression(path) { - path.node.typeParameters = null; + if (process.env.BABEL_8_BREAKING) { + path.node.typeArguments = null; + } else { + // @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8 + path.node.typeParameters = null; + } }, JSXOpeningElement(path) { - path.node.typeParameters = null; + if (process.env.BABEL_8_BREAKING) { + //@ts-ignore(Babel 7 vs Babel 8) Babel 8 AST + path.node.typeArguments = null; + } else { + // @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8 + path.node.typeParameters = null; + } }, TaggedTemplateExpression(path) { - path.node.typeParameters = null; + if (process.env.BABEL_8_BREAKING) { + // @ts-ignore(Babel 7 vs Babel 8) Babel 8 AST + path.node.typeArguments = null; + } else { + // @ts-ignore(Babel 7 vs Babel 8) Removed in Babel 8 + path.node.typeParameters = null; + } }, }, }; diff --git a/packages/babel-types/src/definitions/core.ts b/packages/babel-types/src/definitions/core.ts index f9c39ad160ff..0fcb72e52e65 100644 --- a/packages/babel-types/src/definitions/core.ts +++ b/packages/babel-types/src/definitions/core.ts @@ -176,7 +176,9 @@ defineType("BreakStatement", { }); defineType("CallExpression", { - visitor: ["callee", "arguments", "typeParameters", "typeArguments"], + visitor: process.env.BABEL_8_BREAKING + ? ["callee", "arguments", "typeArguments"] + : ["callee", "arguments", "typeParameters", "typeArguments"], builder: ["callee", "arguments"], aliases: ["Expression"], fields: { @@ -188,22 +190,35 @@ defineType("CallExpression", { "SpreadElement", "ArgumentPlaceholder", ), - ...(!process.env.BABEL_8_BREAKING && !process.env.BABEL_TYPES_8_BREAKING - ? { + typeArguments: { + validate: process.env.BABEL_8_BREAKING + ? assertNodeType( + "TypeParameterInstantiation", + "TSTypeParameterInstantiation", + ) + : assertNodeType("TypeParameterInstantiation"), + optional: true, + }, + ...(process.env.BABEL_8_BREAKING + ? {} + : { optional: { validate: assertValueType("boolean"), optional: true, }, - } - : {}), - typeArguments: { - validate: assertNodeType("TypeParameterInstantiation"), - optional: true, - }, - typeParameters: { - validate: assertNodeType("TSTypeParameterInstantiation"), - optional: true, - }, + typeParameters: { + validate: assertNodeType("TSTypeParameterInstantiation"), + optional: true, + }, + }), + ...(process.env.BABEL_TYPES_8_BREAKING + ? {} + : { + optional: { + validate: assertValueType("boolean"), + optional: true, + }, + }), }, }); @@ -1982,7 +1997,9 @@ defineType( ); defineType("TaggedTemplateExpression", { - visitor: ["tag", "typeParameters", "quasi"], + visitor: process.env.BABEL_8_BREAKING + ? ["tag", "typeArguments", "quasi"] + : ["tag", "typeParameters", "quasi"], builder: ["tag", "quasi"], aliases: ["Expression"], fields: { @@ -1992,7 +2009,7 @@ defineType("TaggedTemplateExpression", { quasi: { validate: assertNodeType("TemplateLiteral"), }, - typeParameters: { + [process.env.BABEL_8_BREAKING ? "typeArguments" : "typeParameters"]: { validate: assertNodeType( "TypeParameterInstantiation", "TSTypeParameterInstantiation", @@ -2192,7 +2209,9 @@ defineType("OptionalMemberExpression", { }); defineType("OptionalCallExpression", { - visitor: ["callee", "arguments", "typeParameters", "typeArguments"], + visitor: process.env.BABEL_8_BREAKING + ? ["callee", "arguments", "typeArguments"] + : ["callee", "arguments", "typeParameters", "typeArguments"], builder: ["callee", "arguments", "optional"], aliases: ["Expression"], fields: { @@ -2211,13 +2230,22 @@ defineType("OptionalCallExpression", { : chain(assertValueType("boolean"), assertOptionalChainStart()), }, typeArguments: { - validate: assertNodeType("TypeParameterInstantiation"), - optional: true, - }, - typeParameters: { - validate: assertNodeType("TSTypeParameterInstantiation"), + validate: process.env.BABEL_8_BREAKING + ? assertNodeType( + "TypeParameterInstantiation", + "TSTypeParameterInstantiation", + ) + : assertNodeType("TypeParameterInstantiation"), optional: true, }, + ...(process.env.BABEL_8_BREAKING + ? {} + : { + typeParameters: { + validate: assertNodeType("TSTypeParameterInstantiation"), + optional: true, + }, + }), }, }); diff --git a/packages/babel-types/src/definitions/jsx.ts b/packages/babel-types/src/definitions/jsx.ts index eb70302d689e..13a0170baf5b 100644 --- a/packages/babel-types/src/definitions/jsx.ts +++ b/packages/babel-types/src/definitions/jsx.ts @@ -129,7 +129,9 @@ defineType("JSXNamespacedName", { defineType("JSXOpeningElement", { builder: ["name", "attributes", "selfClosing"], - visitor: ["name", "typeParameters", "attributes"], + visitor: process.env.BABEL_8_BREAKING + ? ["name", "typeArguments", "attributes"] + : ["name", "typeParameters", "attributes"], aliases: ["Immutable"], fields: { name: { @@ -143,7 +145,7 @@ defineType("JSXOpeningElement", { default: false, }, attributes: validateArrayOfType("JSXAttribute", "JSXSpreadAttribute"), - typeParameters: { + [process.env.BABEL_8_BREAKING ? "typeArguments" : "typeParameters"]: { validate: assertNodeType( "TypeParameterInstantiation", "TSTypeParameterInstantiation", diff --git a/packages/babel-types/src/definitions/typescript.ts b/packages/babel-types/src/definitions/typescript.ts index 4822195ff799..51035533e2f3 100644 --- a/packages/babel-types/src/definitions/typescript.ts +++ b/packages/babel-types/src/definitions/typescript.ts @@ -499,10 +499,13 @@ defineType("TSTypeAliasDeclaration", { defineType("TSInstantiationExpression", { aliases: ["Expression"], - visitor: ["expression", "typeParameters"], + visitor: process.env.BABEL_8_BREAKING + ? ["expression", "typeArguments"] + : ["expression", "typeParameters"], fields: { expression: validateType("Expression"), - typeParameters: validateOptionalType("TSTypeParameterInstantiation"), + [process.env.BABEL_8_BREAKING ? "typeArguments" : "typeParameters"]: + validateOptionalType("TSTypeParameterInstantiation"), }, });