Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow keywords in TS qualified types (#14362)
- Loading branch information
1 parent
dacaab1
commit 01380a6
Showing
8 changed files
with
270 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/babel-parser/test/fixtures/typescript/regression/keyword-qualified-type-2/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// These are valid TypeScript syntax (the parser doesn't produce any error), | ||
// but they are always type-checking errors. | ||
interface A extends this.B {} | ||
type T = typeof var.bar; |
98 changes: 98 additions & 0 deletions
98
...ges/babel-parser/test/fixtures/typescript/regression/keyword-qualified-type-2/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":176,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":24,"index":176}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":176,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":24,"index":176}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TSInterfaceDeclaration", | ||
"start":122,"end":151,"loc":{"start":{"line":3,"column":0,"index":122},"end":{"line":3,"column":29,"index":151}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":132,"end":133,"loc":{"start":{"line":3,"column":10,"index":132},"end":{"line":3,"column":11,"index":133},"identifierName":"A"}, | ||
"name": "A" | ||
}, | ||
"extends": [ | ||
{ | ||
"type": "TSExpressionWithTypeArguments", | ||
"start":142,"end":148,"loc":{"start":{"line":3,"column":20,"index":142},"end":{"line":3,"column":26,"index":148}}, | ||
"expression": { | ||
"type": "TSQualifiedName", | ||
"start":142,"end":148,"loc":{"start":{"line":3,"column":20,"index":142},"end":{"line":3,"column":26,"index":148}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":142,"end":146,"loc":{"start":{"line":3,"column":20,"index":142},"end":{"line":3,"column":24,"index":146},"identifierName":"this"}, | ||
"name": "this" | ||
}, | ||
"right": { | ||
"type": "Identifier", | ||
"start":147,"end":148,"loc":{"start":{"line":3,"column":25,"index":147},"end":{"line":3,"column":26,"index":148},"identifierName":"B"}, | ||
"name": "B" | ||
} | ||
} | ||
} | ||
], | ||
"body": { | ||
"type": "TSInterfaceBody", | ||
"start":149,"end":151,"loc":{"start":{"line":3,"column":27,"index":149},"end":{"line":3,"column":29,"index":151}}, | ||
"body": [] | ||
}, | ||
"leadingComments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " These are valid TypeScript syntax (the parser doesn't produce any error),", | ||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":76,"index":76}} | ||
}, | ||
{ | ||
"type": "CommentLine", | ||
"value": " but they are always type-checking errors.", | ||
"start":77,"end":121,"loc":{"start":{"line":2,"column":0,"index":77},"end":{"line":2,"column":44,"index":121}} | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "TSTypeAliasDeclaration", | ||
"start":152,"end":176,"loc":{"start":{"line":4,"column":0,"index":152},"end":{"line":4,"column":24,"index":176}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":157,"end":158,"loc":{"start":{"line":4,"column":5,"index":157},"end":{"line":4,"column":6,"index":158},"identifierName":"T"}, | ||
"name": "T" | ||
}, | ||
"typeAnnotation": { | ||
"type": "TSTypeQuery", | ||
"start":161,"end":175,"loc":{"start":{"line":4,"column":9,"index":161},"end":{"line":4,"column":23,"index":175}}, | ||
"exprName": { | ||
"type": "TSQualifiedName", | ||
"start":168,"end":175,"loc":{"start":{"line":4,"column":16,"index":168},"end":{"line":4,"column":23,"index":175}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":168,"end":171,"loc":{"start":{"line":4,"column":16,"index":168},"end":{"line":4,"column":19,"index":171},"identifierName":"var"}, | ||
"name": "var" | ||
}, | ||
"right": { | ||
"type": "Identifier", | ||
"start":172,"end":175,"loc":{"start":{"line":4,"column":20,"index":172},"end":{"line":4,"column":23,"index":175},"identifierName":"bar"}, | ||
"name": "bar" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
}, | ||
"comments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " These are valid TypeScript syntax (the parser doesn't produce any error),", | ||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":76,"index":76}} | ||
}, | ||
{ | ||
"type": "CommentLine", | ||
"value": " but they are always type-checking errors.", | ||
"start":77,"end":121,"loc":{"start":{"line":2,"column":0,"index":77},"end":{"line":2,"column":44,"index":121}} | ||
} | ||
] | ||
} |
2 changes: 2 additions & 0 deletions
2
...bel-parser/test/fixtures/typescript/regression/keyword-qualified-type-disallowed/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import X = Y.if; | ||
import A = this.A; |
67 changes: 67 additions & 0 deletions
67
...-parser/test/fixtures/typescript/regression/keyword-qualified-type-disallowed/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":35,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":18,"index":35}}, | ||
"errors": [ | ||
"SyntaxError: Unexpected keyword 'if'. (1:13)", | ||
"SyntaxError: Unexpected keyword 'this'. (2:11)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":35,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":18,"index":35}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TSImportEqualsDeclaration", | ||
"start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}}, | ||
"importKind": "value", | ||
"isExport": false, | ||
"id": { | ||
"type": "Identifier", | ||
"start":7,"end":8,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":8,"index":8},"identifierName":"X"}, | ||
"name": "X" | ||
}, | ||
"moduleReference": { | ||
"type": "TSQualifiedName", | ||
"start":11,"end":15,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":15,"index":15}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":11,"end":12,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":12,"index":12},"identifierName":"Y"}, | ||
"name": "Y" | ||
}, | ||
"right": { | ||
"type": "Identifier", | ||
"start":13,"end":15,"loc":{"start":{"line":1,"column":13,"index":13},"end":{"line":1,"column":15,"index":15},"identifierName":"if"}, | ||
"name": "if" | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "TSImportEqualsDeclaration", | ||
"start":17,"end":35,"loc":{"start":{"line":2,"column":0,"index":17},"end":{"line":2,"column":18,"index":35}}, | ||
"importKind": "value", | ||
"isExport": false, | ||
"id": { | ||
"type": "Identifier", | ||
"start":24,"end":25,"loc":{"start":{"line":2,"column":7,"index":24},"end":{"line":2,"column":8,"index":25},"identifierName":"A"}, | ||
"name": "A" | ||
}, | ||
"moduleReference": { | ||
"type": "TSQualifiedName", | ||
"start":28,"end":34,"loc":{"start":{"line":2,"column":11,"index":28},"end":{"line":2,"column":17,"index":34}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":28,"end":32,"loc":{"start":{"line":2,"column":11,"index":28},"end":{"line":2,"column":15,"index":32},"identifierName":"this"}, | ||
"name": "this" | ||
}, | ||
"right": { | ||
"type": "Identifier", | ||
"start":33,"end":34,"loc":{"start":{"line":2,"column":16,"index":33},"end":{"line":2,"column":17,"index":34},"identifierName":"A"}, | ||
"name": "A" | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/babel-parser/test/fixtures/typescript/regression/keyword-qualified-type/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
interface A extends T.if {} | ||
type T = typeof this.bar; |
74 changes: 74 additions & 0 deletions
74
packages/babel-parser/test/fixtures/typescript/regression/keyword-qualified-type/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":53,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":25,"index":53}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":53,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":25,"index":53}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TSInterfaceDeclaration", | ||
"start":0,"end":27,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":27,"index":27}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":10,"end":11,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":11,"index":11},"identifierName":"A"}, | ||
"name": "A" | ||
}, | ||
"extends": [ | ||
{ | ||
"type": "TSExpressionWithTypeArguments", | ||
"start":20,"end":24,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":24,"index":24}}, | ||
"expression": { | ||
"type": "TSQualifiedName", | ||
"start":20,"end":24,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":24,"index":24}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":20,"end":21,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":21,"index":21},"identifierName":"T"}, | ||
"name": "T" | ||
}, | ||
"right": { | ||
"type": "Identifier", | ||
"start":22,"end":24,"loc":{"start":{"line":1,"column":22,"index":22},"end":{"line":1,"column":24,"index":24},"identifierName":"if"}, | ||
"name": "if" | ||
} | ||
} | ||
} | ||
], | ||
"body": { | ||
"type": "TSInterfaceBody", | ||
"start":25,"end":27,"loc":{"start":{"line":1,"column":25,"index":25},"end":{"line":1,"column":27,"index":27}}, | ||
"body": [] | ||
} | ||
}, | ||
{ | ||
"type": "TSTypeAliasDeclaration", | ||
"start":28,"end":53,"loc":{"start":{"line":2,"column":0,"index":28},"end":{"line":2,"column":25,"index":53}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":33,"end":34,"loc":{"start":{"line":2,"column":5,"index":33},"end":{"line":2,"column":6,"index":34},"identifierName":"T"}, | ||
"name": "T" | ||
}, | ||
"typeAnnotation": { | ||
"type": "TSTypeQuery", | ||
"start":37,"end":52,"loc":{"start":{"line":2,"column":9,"index":37},"end":{"line":2,"column":24,"index":52}}, | ||
"exprName": { | ||
"type": "TSQualifiedName", | ||
"start":44,"end":52,"loc":{"start":{"line":2,"column":16,"index":44},"end":{"line":2,"column":24,"index":52}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":44,"end":48,"loc":{"start":{"line":2,"column":16,"index":44},"end":{"line":2,"column":20,"index":48},"identifierName":"this"}, | ||
"name": "this" | ||
}, | ||
"right": { | ||
"type": "Identifier", | ||
"start":49,"end":52,"loc":{"start":{"line":2,"column":21,"index":49},"end":{"line":2,"column":24,"index":52},"identifierName":"bar"}, | ||
"name": "bar" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
Oops, something went wrong.