Skip to content

Commit

Permalink
fix: parse type parameters with inType context (#14384)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Mar 23, 2022
1 parent e54bc6b commit 326c420
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
3 changes: 1 addition & 2 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -1614,9 +1614,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
): 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 (
Expand Down
@@ -1 +1 @@
type T<U> = U;
type T<U>=U;
@@ -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"},
Expand All @@ -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"
}
}
Expand Down
@@ -1 +1 @@
type T<U> = U;
type T<U>=U;
@@ -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"},
Expand All @@ -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"
}
}
Expand Down

0 comments on commit 326c420

Please sign in to comment.