From 4c36481b178581f0b3297dc9b1eefd35df684d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 23 Mar 2022 10:31:55 -0400 Subject: [PATCH] fix: parse type parameters with inType context --- packages/babel-parser/src/plugins/typescript/index.js | 3 +-- .../typescript/type-alias/generic-babel-7/input.ts | 2 +- .../typescript/type-alias/generic-babel-7/output.json | 10 +++++----- .../fixtures/typescript/type-alias/generic/input.ts | 2 +- .../fixtures/typescript/type-alias/generic/output.json | 10 +++++----- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/babel-parser/src/plugins/typescript/index.js b/packages/babel-parser/src/plugins/typescript/index.js index 5f0edeee0438..daf6ab18a68b 100644 --- a/packages/babel-parser/src/plugins/typescript/index.js +++ b/packages/babel-parser/src/plugins/typescript/index.js @@ -1614,9 +1614,8 @@ export default (superClass: Class): Class => ): N.TsTypeAliasDeclaration { node.id = this.parseIdentifier(); this.checkIdentifier(node.id, BIND_TS_TYPE); - - node.typeParameters = this.tsTryParseTypeParameters(); node.typeAnnotation = this.tsInType(() => { + node.typeParameters = this.tsTryParseTypeParameters(); this.expect(tt.eq); if ( diff --git a/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/input.ts index 0e910abfc66e..48dcc5dd9d3c 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/input.ts +++ b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/input.ts @@ -1 +1 @@ -type T = U; +type T=U; diff --git a/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/output.json index 024ec86ff851..47c963007957 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-alias/generic-babel-7/output.json @@ -1,15 +1,15 @@ { "type": "File", - "start":0,"end":14,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":14,"index":14}}, + "start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, "program": { "type": "Program", - "start":0,"end":14,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":14,"index":14}}, + "start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, "sourceType": "module", "interpreter": null, "body": [ { "type": "TSTypeAliasDeclaration", - "start":0,"end":14,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":14,"index":14}}, + "start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, "id": { "type": "Identifier", "start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6},"identifierName":"T"}, @@ -28,10 +28,10 @@ }, "typeAnnotation": { "type": "TSTypeReference", - "start":12,"end":13,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":13,"index":13}}, + "start":10,"end":11,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":11,"index":11}}, "typeName": { "type": "Identifier", - "start":12,"end":13,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":13,"index":13},"identifierName":"U"}, + "start":10,"end":11,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":11,"index":11},"identifierName":"U"}, "name": "U" } } diff --git a/packages/babel-parser/test/fixtures/typescript/type-alias/generic/input.ts b/packages/babel-parser/test/fixtures/typescript/type-alias/generic/input.ts index 0e910abfc66e..48dcc5dd9d3c 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-alias/generic/input.ts +++ b/packages/babel-parser/test/fixtures/typescript/type-alias/generic/input.ts @@ -1 +1 @@ -type T = U; +type T=U; diff --git a/packages/babel-parser/test/fixtures/typescript/type-alias/generic/output.json b/packages/babel-parser/test/fixtures/typescript/type-alias/generic/output.json index 527a3bad0188..3d7b77bfbeae 100644 --- a/packages/babel-parser/test/fixtures/typescript/type-alias/generic/output.json +++ b/packages/babel-parser/test/fixtures/typescript/type-alias/generic/output.json @@ -1,15 +1,15 @@ { "type": "File", - "start":0,"end":14,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":14,"index":14}}, + "start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, "program": { "type": "Program", - "start":0,"end":14,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":14,"index":14}}, + "start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, "sourceType": "module", "interpreter": null, "body": [ { "type": "TSTypeAliasDeclaration", - "start":0,"end":14,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":14,"index":14}}, + "start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}}, "id": { "type": "Identifier", "start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6},"identifierName":"T"}, @@ -32,10 +32,10 @@ }, "typeAnnotation": { "type": "TSTypeReference", - "start":12,"end":13,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":13,"index":13}}, + "start":10,"end":11,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":11,"index":11}}, "typeName": { "type": "Identifier", - "start":12,"end":13,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":13,"index":13},"identifierName":"U"}, + "start":10,"end":11,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":11,"index":11},"identifierName":"U"}, "name": "U" } }