Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow unknown/any in TS catch clause param
- Loading branch information
1 parent
cfaa70d
commit b2e31c1
Showing
6 changed files
with
186 additions
and
4 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
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
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/typescript/catch-clause/invalid-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 @@ | ||
try {} catch (ex: string) {} |
42 changes: 42 additions & 0 deletions
42
packages/babel-parser/test/fixtures/typescript/catch-clause/invalid-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,42 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, | ||
"errors": [ | ||
"SyntaxError: Catch clause variables can only be typed 'any' or 'unknown' (1:18)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TryStatement", | ||
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, | ||
"block": { | ||
"type": "BlockStatement", | ||
"start":4,"end":6,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":6}}, | ||
"body": [], | ||
"directives": [] | ||
}, | ||
"handler": { | ||
"type": "CatchClause", | ||
"start":7,"end":28,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":28}}, | ||
"param": { | ||
"type": "Identifier", | ||
"start":14,"end":16,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":16},"identifierName":"ex"}, | ||
"name": "ex" | ||
}, | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":26,"end":28,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":28}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
}, | ||
"finalizer": null | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/catch-clause/unknown/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,3 @@ | ||
try {} catch (ex) {} | ||
try {} catch (ex: unknown) {} | ||
try {} catch (ex: any) {} |
105 changes: 105 additions & 0 deletions
105
packages/babel-parser/test/fixtures/typescript/catch-clause/unknown/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,105 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":25}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":25}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TryStatement", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, | ||
"block": { | ||
"type": "BlockStatement", | ||
"start":4,"end":6,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":6}}, | ||
"body": [], | ||
"directives": [] | ||
}, | ||
"handler": { | ||
"type": "CatchClause", | ||
"start":7,"end":20,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":20}}, | ||
"param": { | ||
"type": "Identifier", | ||
"start":14,"end":16,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":16},"identifierName":"ex"}, | ||
"name": "ex" | ||
}, | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":18,"end":20,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":20}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
}, | ||
"finalizer": null | ||
}, | ||
{ | ||
"type": "TryStatement", | ||
"start":21,"end":50,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":29}}, | ||
"block": { | ||
"type": "BlockStatement", | ||
"start":25,"end":27,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":6}}, | ||
"body": [], | ||
"directives": [] | ||
}, | ||
"handler": { | ||
"type": "CatchClause", | ||
"start":28,"end":50,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":29}}, | ||
"param": { | ||
"type": { | ||
"type": "TSTypeAnnotation", | ||
"start":37,"end":46,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":25}}, | ||
"typeAnnotation": { | ||
"type": "TSUnknownKeyword", | ||
"start":39,"end":46,"loc":{"start":{"line":2,"column":18},"end":{"line":2,"column":25}} | ||
} | ||
}, | ||
"start":35,"end":37,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":16},"identifierName":"ex"}, | ||
"name": "ex" | ||
}, | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":48,"end":50,"loc":{"start":{"line":2,"column":27},"end":{"line":2,"column":29}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
}, | ||
"finalizer": null | ||
}, | ||
{ | ||
"type": "TryStatement", | ||
"start":51,"end":76,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":25}}, | ||
"block": { | ||
"type": "BlockStatement", | ||
"start":55,"end":57,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":6}}, | ||
"body": [], | ||
"directives": [] | ||
}, | ||
"handler": { | ||
"type": "CatchClause", | ||
"start":58,"end":76,"loc":{"start":{"line":3,"column":7},"end":{"line":3,"column":25}}, | ||
"param": { | ||
"type": { | ||
"type": "TSTypeAnnotation", | ||
"start":67,"end":72,"loc":{"start":{"line":3,"column":16},"end":{"line":3,"column":21}}, | ||
"typeAnnotation": { | ||
"type": "TSAnyKeyword", | ||
"start":69,"end":72,"loc":{"start":{"line":3,"column":18},"end":{"line":3,"column":21}} | ||
} | ||
}, | ||
"start":65,"end":67,"loc":{"start":{"line":3,"column":14},"end":{"line":3,"column":16},"identifierName":"ex"}, | ||
"name": "ex" | ||
}, | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":74,"end":76,"loc":{"start":{"line":3,"column":23},"end":{"line":3,"column":25}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
}, | ||
"finalizer": null | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |