From 5861002b338815fdbc0f31c5dda477240f188e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Sun, 23 Jan 2022 23:47:06 -0500 Subject: [PATCH] Reinterpret << when parsing TS type arguments (#14145) * refactor: split bitShift to bitShiftL and bitShiftR * fix: reinterpret bitShiftL to lt when parsing type arguments * test: update typescript allowlist * add Babel 8 test cases * test: simplify testcase * add more testcases --- .../src/plugins/typescript/index.js | 48 ++++++--- packages/babel-parser/src/tokenizer/index.js | 4 +- packages/babel-parser/src/tokenizer/types.js | 2 + .../after-bit-shift/input.ts | 1 + .../after-bit-shift/output.json | 49 +++++++++ .../call-expression/input.ts | 1 + .../call-expression/output.json | 76 +++++++++++++ .../class-heritage/input.ts | 1 + .../class-heritage/output.json | 85 +++++++++++++++ .../decorator-call-expression/input.ts | 1 + .../decorator-call-expression/options.json | 3 + .../decorator-call-expression/output.json | 97 +++++++++++++++++ .../decorator-legacy-call-expression/input.ts | 1 + .../options.json | 3 + .../output.json | 97 +++++++++++++++++ .../jsx-opening-element/input.tsx | 1 + .../jsx-opening-element/options.json | 3 + .../jsx-opening-element/output.json | 83 ++++++++++++++ .../new-expression/input.ts | 1 + .../new-expression/output.json | 76 +++++++++++++ .../options.json | 4 + .../type-arguments-like/input.ts | 1 + .../type-arguments-like/output.json | 64 +++++++++++ .../after-bit-shift/input.ts | 1 + .../after-bit-shift/output.json | 49 +++++++++ .../call-expression/input.ts | 1 + .../call-expression/output.json | 80 ++++++++++++++ .../class-heritage/input.ts | 1 + .../class-heritage/output.json | 89 +++++++++++++++ .../decorator-call-expression/input.ts | 1 + .../decorator-call-expression/options.json | 3 + .../decorator-call-expression/output.json | 101 ++++++++++++++++++ .../decorator-legacy-call-expression/input.ts | 1 + .../options.json | 3 + .../output.json | 101 ++++++++++++++++++ .../jsx-opening-element/input.tsx | 1 + .../jsx-opening-element/options.json | 3 + .../jsx-opening-element/output.json | 87 +++++++++++++++ .../new-expression/input.ts | 1 + .../new-expression/output.json | 80 ++++++++++++++ .../options.json | 4 + .../type-arguments-like/input.ts | 1 + .../type-arguments-like/output.json | 64 +++++++++++ scripts/parser-tests/typescript/allowlist.txt | 1 - 44 files changed, 1360 insertions(+), 15 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/after-bit-shift/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/after-bit-shift/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/call-expression/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/call-expression/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/class-heritage/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/class-heritage/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-call-expression/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-call-expression/options.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-call-expression/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-legacy-call-expression/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-legacy-call-expression/options.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-legacy-call-expression/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/jsx-opening-element/input.tsx create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/jsx-opening-element/options.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/jsx-opening-element/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/new-expression/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/new-expression/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/options.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/type-arguments-like/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/type-arguments-like/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/after-bit-shift/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/after-bit-shift/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/class-heritage/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/class-heritage/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/options.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/options.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/input.tsx create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/options.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression/output.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/options.json create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/type-arguments-like/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/type-arguments-like/output.json diff --git a/packages/babel-parser/src/plugins/typescript/index.js b/packages/babel-parser/src/plugins/typescript/index.js index e869bcf3d75d..e02e64da28ea 100644 --- a/packages/babel-parser/src/plugins/typescript/index.js +++ b/packages/babel-parser/src/plugins/typescript/index.js @@ -1974,6 +1974,15 @@ export default (superClass: Class): Class => ); } + // Used when parsing type arguments from ES productions, where the first token + // has been created without state.inType. Thus we need to rescan the lt token. + tsParseTypeArgumentsInExpression(): N.TsTypeParameterInstantiation | void { + if (this.reScan_lt() !== tt.lt) { + return undefined; + } + return this.tsParseTypeArguments(); + } + tsParseTypeArguments(): N.TsTypeParameterInstantiation { const node = this.startNode(); node.params = this.tsInType(() => @@ -2172,7 +2181,8 @@ export default (superClass: Class): Class => this.next(); } - if (this.match(tt.lt)) { + // handles 'f<' + if (this.match(tt.lt) || this.match(tt.bitShiftL)) { let missingParenErrorLoc; // tsTryParseAndCatch is expensive, so avoid if not necessary. // There are number of things we are going to "maybe" parse, like type arguments on @@ -2193,7 +2203,7 @@ export default (superClass: Class): Class => const node: N.CallExpression = this.startNodeAt(startPos, startLoc); node.callee = base; - const typeArguments = this.tsParseTypeArguments(); + const typeArguments = this.tsParseTypeArgumentsInExpression(); if (typeArguments) { if (isOptionalCall && !this.match(tt.parenL)) { @@ -2245,11 +2255,12 @@ export default (superClass: Class): Class => } parseNewArguments(node: N.NewExpression): void { - if (this.match(tt.lt)) { - // tsTryParseAndCatch is expensive, so avoid if not necessary. - // 99% certain this is `new C();`. But may be `new C < T;`, which is also legal. + // tsTryParseAndCatch is expensive, so avoid if not necessary. + // 99% certain this is `new C();`. But may be `new C < T;`, which is also legal. + // Also handles `new C<` + if (this.match(tt.lt) || this.match(tt.bitShiftL)) { const typeParameters = this.tsTryParseAndCatch(() => { - const args = this.tsParseTypeArguments(); + const args = this.tsParseTypeArgumentsInExpression(); if (!this.match(tt.parenL)) this.unexpected(); return args; }); @@ -2832,8 +2843,9 @@ export default (superClass: Class): Class => parseClassSuper(node: N.Class): void { super.parseClassSuper(node); - if (node.superClass && this.match(tt.lt)) { - node.superTypeParameters = this.tsParseTypeArguments(); + // handle `extends f< + if (node.superClass && (this.match(tt.lt) || this.match(tt.bitShiftL))) { + node.superTypeParameters = this.tsParseTypeArgumentsInExpression(); } if (this.eatContextual(tt._implements)) { node.implements = this.tsParseHeritageClause("implements"); @@ -3146,8 +3158,9 @@ export default (superClass: Class): Class => } parseMaybeDecoratorArguments(expr: N.Expression): N.Expression { - if (this.match(tt.lt)) { - const typeArguments = this.tsParseTypeArguments(); + // handles `@f<` + if (this.match(tt.lt) || this.match(tt.bitShiftL)) { + const typeArguments = this.tsParseTypeArgumentsInExpression(); if (this.match(tt.parenL)) { const call = super.parseMaybeDecoratorArguments(expr); @@ -3230,6 +3243,16 @@ export default (superClass: Class): Class => } } + reScan_lt() { + const { type } = this.state; + if (type === tt.bitShiftL) { + this.state.pos -= 2; + this.finishOp(tt.lt, 1); + return tt.lt; + } + return type; + } + toAssignableList(exprList: N.Expression[]): $ReadOnlyArray { for (let i = 0; i < exprList.length; i++) { const expr = exprList[i]; @@ -3280,9 +3303,10 @@ export default (superClass: Class): Class => jsxParseOpeningElementAfterName( node: N.JSXOpeningElement, ): N.JSXOpeningElement { - if (this.match(tt.lt)) { + // handles `` + if (this.match(tt.lt) || this.match(tt.bitShiftL)) { const typeArguments = this.tsTryParseAndCatch(() => - this.tsParseTypeArguments(), + this.tsParseTypeArgumentsInExpression(), ); if (typeArguments) node.typeParameters = typeArguments; } diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index f9597200fe74..8a11cbd29ef6 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -755,7 +755,7 @@ export default class Tokenizer extends ParserErrors { this.finishOp(tt.assign, 3); return; } - this.finishOp(tt.bitShift, 2); + this.finishOp(tt.bitShiftL, 2); return; } @@ -780,7 +780,7 @@ export default class Tokenizer extends ParserErrors { this.finishOp(tt.assign, size + 1); return; } - this.finishOp(tt.bitShift, size); + this.finishOp(tt.bitShiftR, size); return; } diff --git a/packages/babel-parser/src/tokenizer/types.js b/packages/babel-parser/src/tokenizer/types.js index 7e3744f0da87..62b612af36be 100644 --- a/packages/babel-parser/src/tokenizer/types.js +++ b/packages/babel-parser/src/tokenizer/types.js @@ -208,6 +208,8 @@ export const tt: { [name: string]: TokenType } = { gt: createBinop("/<=/>=", 7), relational: createBinop("/<=/>=", 7), bitShift: createBinop("<>/>>>", 8), + bitShiftL: createBinop("<>/>>>", 8), + bitShiftR: createBinop("<>/>>>", 8), plusMin: createToken("+/-", { beforeExpr, binop: 9, prefix, startsExpr }), // startsExpr: required by v8intrinsic plugin modulo: createToken("%", { binop: 10, startsExpr }), diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/after-bit-shift/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/after-bit-shift/input.ts new file mode 100644 index 000000000000..22101bcfd01d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/after-bit-shift/input.ts @@ -0,0 +1 @@ +f<<(x) diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/after-bit-shift/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/after-bit-shift/output.json new file mode 100644 index 000000000000..140ef3375bdd --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/after-bit-shift/output.json @@ -0,0 +1,49 @@ +{ + "type": "File", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9}}, + "program": { + "type": "Program", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9}}, + "expression": { + "type": "BinaryExpression", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9}}, + "left": { + "type": "Identifier", + "start":0,"end":1,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":1},"identifierName":"f"}, + "name": "f" + }, + "operator": "<<", + "right": { + "type": "TSTypeAssertion", + "start":3,"end":9,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":9}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}, + "typeName": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"T"}, + "name": "T" + } + }, + "expression": { + "type": "Identifier", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"x"}, + "name": "x", + "extra": { + "parenthesized": true, + "parenStart": 6 + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/call-expression/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/call-expression/input.ts new file mode 100644 index 000000000000..94b8ba09b57d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/call-expression/input.ts @@ -0,0 +1 @@ +f<(v: T) => void>(); diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/call-expression/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/call-expression/output.json new file mode 100644 index 000000000000..70636b633c3d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/call-expression/output.json @@ -0,0 +1,76 @@ +{ + "type": "File", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}}, + "program": { + "type": "Program", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}}, + "expression": { + "type": "CallExpression", + "start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}}, + "callee": { + "type": "Identifier", + "start":0,"end":1,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":1},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":1,"end":20,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":20}}, + "params": [ + { + "type": "TSFunctionType", + "start":2,"end":19,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":19}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":2,"end":5,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":5}}, + "params": [ + { + "type": "TSTypeParameter", + "start":3,"end":4,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start":6,"end":10,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":10},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}}, + "typeAnnotation": { + "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" + } + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":12,"end":19,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":19}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":15,"end":19,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":19}} + } + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/class-heritage/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/class-heritage/input.ts new file mode 100644 index 000000000000..8db082343420 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/class-heritage/input.ts @@ -0,0 +1 @@ +(class extends f<(v: T) => void> {}); diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/class-heritage/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/class-heritage/output.json new file mode 100644 index 000000000000..dc7c5bda7de6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/class-heritage/output.json @@ -0,0 +1,85 @@ +{ + "type": "File", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}}, + "program": { + "type": "Program", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}}, + "expression": { + "type": "ClassExpression", + "start":1,"end":38,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":38}}, + "id": null, + "superClass": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":16},"identifierName":"f"}, + "name": "f" + }, + "superTypeParameters": { + "type": "TSTypeParameterInstantiation", + "start":16,"end":35,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":35}}, + "params": [ + { + "type": "TSFunctionType", + "start":17,"end":34,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":34}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":17,"end":20,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":20}}, + "params": [ + { + "type": "TSTypeParameter", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19}}, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start":21,"end":25,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":25},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":22,"end":25,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":25}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":24,"end":25,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":25}}, + "typeName": { + "type": "Identifier", + "start":24,"end":25,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":25},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":27,"end":34,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":34}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":30,"end":34,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":34}} + } + } + } + ] + }, + "body": { + "type": "ClassBody", + "start":36,"end":38,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":38}}, + "body": [] + }, + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-call-expression/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-call-expression/input.ts new file mode 100644 index 000000000000..7316ad25571d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-call-expression/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-babel-7/decorator-call-expression/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-call-expression/options.json new file mode 100644 index 000000000000..5b5e513c9b60 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-call-expression/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["decorators", { "decoratorsBeforeExport": true }], "typescript"] +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-call-expression/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-call-expression/output.json new file mode 100644 index 000000000000..329e3404728f --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-call-expression/output.json @@ -0,0 +1,97 @@ +{ + "type": "File", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "program": { + "type": "Program", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "expression": { + "type": "ClassExpression", + "start":1,"end":33,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":33}}, + "decorators": [ + { + "type": "Decorator", + "start":1,"end":24,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":24}}, + "expression": { + "type": "CallExpression", + "start":2,"end":24,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":24}}, + "callee": { + "type": "Identifier", + "start":2,"end":3,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":3,"end":22,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":22}}, + "params": [ + { + "type": "TSFunctionType", + "start":4,"end":21,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":21}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":4,"end":7,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":7}}, + "params": [ + { + "type": "TSTypeParameter", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6}}, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start":8,"end":12,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":12},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12}}, + "typeName": { + "type": "Identifier", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":14,"end":21,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":21}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":17,"end":21,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":21}} + } + } + } + ] + } + } + } + ], + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start":31,"end":33,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":33}}, + "body": [] + }, + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-legacy-call-expression/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-legacy-call-expression/input.ts new file mode 100644 index 000000000000..7316ad25571d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-legacy-call-expression/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-babel-7/decorator-legacy-call-expression/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-legacy-call-expression/options.json new file mode 100644 index 000000000000..8a18ae919565 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-legacy-call-expression/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["decorators-legacy", "typescript"] +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-legacy-call-expression/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-legacy-call-expression/output.json new file mode 100644 index 000000000000..329e3404728f --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/decorator-legacy-call-expression/output.json @@ -0,0 +1,97 @@ +{ + "type": "File", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "program": { + "type": "Program", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "expression": { + "type": "ClassExpression", + "start":1,"end":33,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":33}}, + "decorators": [ + { + "type": "Decorator", + "start":1,"end":24,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":24}}, + "expression": { + "type": "CallExpression", + "start":2,"end":24,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":24}}, + "callee": { + "type": "Identifier", + "start":2,"end":3,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":3,"end":22,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":22}}, + "params": [ + { + "type": "TSFunctionType", + "start":4,"end":21,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":21}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":4,"end":7,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":7}}, + "params": [ + { + "type": "TSTypeParameter", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6}}, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start":8,"end":12,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":12},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12}}, + "typeName": { + "type": "Identifier", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":14,"end":21,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":21}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":17,"end":21,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":21}} + } + } + } + ] + } + } + } + ], + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start":31,"end":33,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":33}}, + "body": [] + }, + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/jsx-opening-element/input.tsx b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/jsx-opening-element/input.tsx new file mode 100644 index 000000000000..5ad697cb46a8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/jsx-opening-element/input.tsx @@ -0,0 +1 @@ +(v: T) => void> /> diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/jsx-opening-element/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/jsx-opening-element/options.json new file mode 100644 index 000000000000..aa8780ac5180 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/jsx-opening-element/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["jsx", "typescript"] +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/jsx-opening-element/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/jsx-opening-element/output.json new file mode 100644 index 000000000000..14a2802c4112 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/jsx-opening-element/output.json @@ -0,0 +1,83 @@ +{ + "type": "File", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}}, + "program": { + "type": "Program", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}}, + "expression": { + "type": "JSXElement", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}}, + "openingElement": { + "type": "JSXOpeningElement", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}}, + "name": { + "type": "JSXIdentifier", + "start":1,"end":10,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":10}}, + "name": "Component" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":10,"end":29,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":29}}, + "params": [ + { + "type": "TSFunctionType", + "start":11,"end":28,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":28}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":11,"end":14,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":14}}, + "params": [ + { + "type": "TSTypeParameter", + "start":12,"end":13,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":13}}, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start":15,"end":19,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":19},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":16,"end":19,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":19}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19}}, + "typeName": { + "type": "Identifier", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":21,"end":28,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":28}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":24,"end":28,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":28}} + } + } + } + ] + }, + "attributes": [], + "selfClosing": true + }, + "closingElement": null, + "children": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/new-expression/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/new-expression/input.ts new file mode 100644 index 000000000000..7991a4bbd640 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/new-expression/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-babel-7/new-expression/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/new-expression/output.json new file mode 100644 index 000000000000..15e75851b4c5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/new-expression/output.json @@ -0,0 +1,76 @@ +{ + "type": "File", + "start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, + "program": { + "type": "Program", + "start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, + "expression": { + "type": "NewExpression", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, + "callee": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"f"}, + "name": "f" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":5,"end":24,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":24}}, + "params": [ + { + "type": "TSFunctionType", + "start":6,"end":23,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":23}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9}}, + "params": [ + { + "type": "TSTypeParameter", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}}, + "name": "T" + } + ] + }, + "parameters": [ + { + "type": "Identifier", + "start":10,"end":14,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":14},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":11,"end":14,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":14}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14}}, + "typeName": { + "type": "Identifier", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":16,"end":23,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":23}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":19,"end":23,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":23}} + } + } + } + ] + }, + "arguments": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/options.json new file mode 100644 index 000000000000..088fb893488a --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/options.json @@ -0,0 +1,4 @@ +{ + "BABEL_8_BREAKING": false, + "plugins": ["typescript"] +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/type-arguments-like/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/type-arguments-like/input.ts new file mode 100644 index 000000000000..7e2a54ba7ab5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/type-arguments-like/input.ts @@ -0,0 +1 @@ +f<< T > (()=>T) > T diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/type-arguments-like/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/type-arguments-like/output.json new file mode 100644 index 000000000000..127d0690fc75 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like-babel-7/type-arguments-like/output.json @@ -0,0 +1,64 @@ +{ + "type": "File", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, + "program": { + "type": "Program", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, + "expression": { + "type": "BinaryExpression", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, + "left": { + "type": "BinaryExpression", + "start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}}, + "left": { + "type": "BinaryExpression", + "start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}, + "left": { + "type": "Identifier", + "start":0,"end":1,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":1},"identifierName":"f"}, + "name": "f" + }, + "operator": "<<", + "right": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"T"}, + "name": "T" + } + }, + "operator": ">", + "right": { + "type": "ArrowFunctionExpression", + "start":9,"end":14,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":14}}, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "Identifier", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14},"identifierName":"T"}, + "name": "T" + }, + "extra": { + "parenthesized": true, + "parenStart": 8 + } + } + }, + "operator": ">", + "right": { + "type": "Identifier", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19},"identifierName":"T"}, + "name": "T" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/after-bit-shift/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/after-bit-shift/input.ts new file mode 100644 index 000000000000..22101bcfd01d --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/after-bit-shift/input.ts @@ -0,0 +1 @@ +f<<(x) diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/after-bit-shift/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/after-bit-shift/output.json new file mode 100644 index 000000000000..140ef3375bdd --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/after-bit-shift/output.json @@ -0,0 +1,49 @@ +{ + "type": "File", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9}}, + "program": { + "type": "Program", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9}}, + "expression": { + "type": "BinaryExpression", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9}}, + "left": { + "type": "Identifier", + "start":0,"end":1,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":1},"identifierName":"f"}, + "name": "f" + }, + "operator": "<<", + "right": { + "type": "TSTypeAssertion", + "start":3,"end":9,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":9}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}, + "typeName": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"T"}, + "name": "T" + } + }, + "expression": { + "type": "Identifier", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"x"}, + "name": "x", + "extra": { + "parenthesized": true, + "parenStart": 6 + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression/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/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/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression/output.json new file mode 100644 index 000000000000..707d58158021 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/call-expression/output.json @@ -0,0 +1,80 @@ +{ + "type": "File", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}}, + "program": { + "type": "Program", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}}, + "expression": { + "type": "CallExpression", + "start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}}, + "callee": { + "type": "Identifier", + "start":0,"end":1,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":1},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":1,"end":20,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":20}}, + "params": [ + { + "type": "TSFunctionType", + "start":2,"end":19,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":19}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":2,"end":5,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":5}}, + "params": [ + { + "type": "TSTypeParameter", + "start":3,"end":4,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4}}, + "name": { + "type": "Identifier", + "start":3,"end":4,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "params": [ + { + "type": "Identifier", + "start":6,"end":10,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":10},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}}, + "typeAnnotation": { + "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" + } + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "start":12,"end":19,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":19}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":15,"end":19,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":19}} + } + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/class-heritage/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/class-heritage/input.ts new file mode 100644 index 000000000000..8db082343420 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/class-heritage/input.ts @@ -0,0 +1 @@ +(class extends f<(v: T) => void> {}); diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/class-heritage/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/class-heritage/output.json new file mode 100644 index 000000000000..c440ac7628b8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/class-heritage/output.json @@ -0,0 +1,89 @@ +{ + "type": "File", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}}, + "program": { + "type": "Program", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}}, + "expression": { + "type": "ClassExpression", + "start":1,"end":38,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":38}}, + "id": null, + "superClass": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":16},"identifierName":"f"}, + "name": "f" + }, + "superTypeParameters": { + "type": "TSTypeParameterInstantiation", + "start":16,"end":35,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":35}}, + "params": [ + { + "type": "TSFunctionType", + "start":17,"end":34,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":34}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":17,"end":20,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":20}}, + "params": [ + { + "type": "TSTypeParameter", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19}}, + "name": { + "type": "Identifier", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "params": [ + { + "type": "Identifier", + "start":21,"end":25,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":25},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":22,"end":25,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":25}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":24,"end":25,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":25}}, + "typeName": { + "type": "Identifier", + "start":24,"end":25,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":25},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "start":27,"end":34,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":34}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":30,"end":34,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":34}} + } + } + } + ] + }, + "body": { + "type": "ClassBody", + "start":36,"end":38,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":38}}, + "body": [] + }, + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/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/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/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/options.json new file mode 100644 index 000000000000..5b5e513c9b60 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["decorators", { "decoratorsBeforeExport": true }], "typescript"] +} 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 new file mode 100644 index 000000000000..7073404faaa9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-call-expression/output.json @@ -0,0 +1,101 @@ +{ + "type": "File", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "program": { + "type": "Program", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "expression": { + "type": "ClassExpression", + "start":1,"end":33,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":33}}, + "decorators": [ + { + "type": "Decorator", + "start":1,"end":24,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":24}}, + "expression": { + "type": "CallExpression", + "start":2,"end":24,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":24}}, + "callee": { + "type": "Identifier", + "start":2,"end":3,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":3,"end":22,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":22}}, + "params": [ + { + "type": "TSFunctionType", + "start":4,"end":21,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":21}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":4,"end":7,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":7}}, + "params": [ + { + "type": "TSTypeParameter", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6}}, + "name": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "params": [ + { + "type": "Identifier", + "start":8,"end":12,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":12},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12}}, + "typeName": { + "type": "Identifier", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "start":14,"end":21,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":21}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":17,"end":21,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":21}} + } + } + } + ] + } + } + } + ], + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start":31,"end":33,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":33}}, + "body": [] + }, + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/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/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/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/options.json new file mode 100644 index 000000000000..8a18ae919565 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["decorators-legacy", "typescript"] +} 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 new file mode 100644 index 000000000000..7073404faaa9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/decorator-legacy-call-expression/output.json @@ -0,0 +1,101 @@ +{ + "type": "File", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "program": { + "type": "Program", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, + "expression": { + "type": "ClassExpression", + "start":1,"end":33,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":33}}, + "decorators": [ + { + "type": "Decorator", + "start":1,"end":24,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":24}}, + "expression": { + "type": "CallExpression", + "start":2,"end":24,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":24}}, + "callee": { + "type": "Identifier", + "start":2,"end":3,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3},"identifierName":"f"}, + "name": "f" + }, + "arguments": [], + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":3,"end":22,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":22}}, + "params": [ + { + "type": "TSFunctionType", + "start":4,"end":21,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":21}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":4,"end":7,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":7}}, + "params": [ + { + "type": "TSTypeParameter", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6}}, + "name": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "params": [ + { + "type": "Identifier", + "start":8,"end":12,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":12},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12}}, + "typeName": { + "type": "Identifier", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "start":14,"end":21,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":21}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":17,"end":21,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":21}} + } + } + } + ] + } + } + } + ], + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start":31,"end":33,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":33}}, + "body": [] + }, + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/input.tsx b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/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/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/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/options.json new file mode 100644 index 000000000000..aa8780ac5180 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["jsx", "typescript"] +} 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 new file mode 100644 index 000000000000..3a0da3fab633 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/jsx-opening-element/output.json @@ -0,0 +1,87 @@ +{ + "type": "File", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}}, + "program": { + "type": "Program", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}}, + "expression": { + "type": "JSXElement", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}}, + "openingElement": { + "type": "JSXOpeningElement", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}}, + "name": { + "type": "JSXIdentifier", + "start":1,"end":10,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":10}}, + "name": "Component" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":10,"end":29,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":29}}, + "params": [ + { + "type": "TSFunctionType", + "start":11,"end":28,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":28}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":11,"end":14,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":14}}, + "params": [ + { + "type": "TSTypeParameter", + "start":12,"end":13,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":13}}, + "name": { + "type": "Identifier", + "start":12,"end":13,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":13},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "params": [ + { + "type": "Identifier", + "start":15,"end":19,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":19},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":16,"end":19,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":19}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19}}, + "typeName": { + "type": "Identifier", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "start":21,"end":28,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":28}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":24,"end":28,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":28}} + } + } + } + ] + }, + "attributes": [], + "selfClosing": true + }, + "closingElement": null, + "children": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression/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/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/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression/output.json new file mode 100644 index 000000000000..9c241e292156 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/new-expression/output.json @@ -0,0 +1,80 @@ +{ + "type": "File", + "start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, + "program": { + "type": "Program", + "start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, + "expression": { + "type": "NewExpression", + "start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, + "callee": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"f"}, + "name": "f" + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start":5,"end":24,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":24}}, + "params": [ + { + "type": "TSFunctionType", + "start":6,"end":23,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":23}}, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9}}, + "params": [ + { + "type": "TSTypeParameter", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}}, + "name": { + "type": "Identifier", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "params": [ + { + "type": "Identifier", + "start":10,"end":14,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":14},"identifierName":"v"}, + "name": "v", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":11,"end":14,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":14}}, + "typeAnnotation": { + "type": "TSTypeReference", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14}}, + "typeName": { + "type": "Identifier", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "start":16,"end":23,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":23}}, + "typeAnnotation": { + "type": "TSVoidKeyword", + "start":19,"end":23,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":23}} + } + } + } + ] + }, + "arguments": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/options.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/options.json new file mode 100644 index 000000000000..08d8091d4386 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/options.json @@ -0,0 +1,4 @@ +{ + "BABEL_8_BREAKING": true, + "plugins": ["typescript"] +} diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/type-arguments-like/input.ts b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/type-arguments-like/input.ts new file mode 100644 index 000000000000..7e2a54ba7ab5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/type-arguments-like/input.ts @@ -0,0 +1 @@ +f<< T > (()=>T) > T diff --git a/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/type-arguments-like/output.json b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/type-arguments-like/output.json new file mode 100644 index 000000000000..127d0690fc75 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/type-arguments-bit-shift-left-like/type-arguments-like/output.json @@ -0,0 +1,64 @@ +{ + "type": "File", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, + "program": { + "type": "Program", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, + "expression": { + "type": "BinaryExpression", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, + "left": { + "type": "BinaryExpression", + "start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}}, + "left": { + "type": "BinaryExpression", + "start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}, + "left": { + "type": "Identifier", + "start":0,"end":1,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":1},"identifierName":"f"}, + "name": "f" + }, + "operator": "<<", + "right": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"T"}, + "name": "T" + } + }, + "operator": ">", + "right": { + "type": "ArrowFunctionExpression", + "start":9,"end":14,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":14}}, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "Identifier", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14},"identifierName":"T"}, + "name": "T" + }, + "extra": { + "parenthesized": true, + "parenStart": 8 + } + } + }, + "operator": ">", + "right": { + "type": "Identifier", + "start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19},"identifierName":"T"}, + "name": "T" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/scripts/parser-tests/typescript/allowlist.txt b/scripts/parser-tests/typescript/allowlist.txt index ca79a7e86a8f..0cfd7cca8167 100644 --- a/scripts/parser-tests/typescript/allowlist.txt +++ b/scripts/parser-tests/typescript/allowlist.txt @@ -387,7 +387,6 @@ outModuleConcatUmd.ts outModuleTripleSlashRefs.ts parameterInitializerBeforeDestructuringEmit.ts parameterPropertyOutsideConstructor.ts -parseGenericArrowRatherThanLeftShift.ts parserConstructorDeclaration12.ts pathMappingBasedModuleResolution3_classic.ts pathMappingBasedModuleResolution3_node.ts