-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ts] support optional chain call with generic (#13513)
* support optional chain call with generic * Add testcase handling new line * allow only call if optional chain type parameter * use exact error message * add transform-typescript optional-chain call test * use exact error message * apply feedbacks * Fix lint error Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
- Loading branch information
1 parent
d5b0d9e
commit 0671afc
Showing
9 changed files
with
203 additions
and
5 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
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/estree/typescript/optional-chaining/input.js
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
foo?.foo<T>(); | ||
foo?.foo?.<T>(); |
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
...babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain-invalid/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 @@ | ||
f?.<string>[1]; |
7 changes: 7 additions & 0 deletions
7
...l-parser/test/fixtures/typescript/type-arguments/call-optional-chain-invalid/options.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,7 @@ | ||
{ | ||
"sourceType": "module", | ||
"plugins": [ | ||
"typescript" | ||
], | ||
"throws": "Unexpected token, expected \"(\" (1:12)" | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain/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 @@ | ||
f?.<Q>(); | ||
f?.<Q, W>(); | ||
f | ||
?.<Q>(); |
112 changes: 112 additions & 0 deletions
112
...ages/babel-parser/test/fixtures/typescript/type-arguments/call-optional-chain/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,112 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":8}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":8}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9}}, | ||
"expression": { | ||
"type": "OptionalCallExpression", | ||
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}}, | ||
"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":3,"end":6,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":6}}, | ||
"params": [ | ||
{ | ||
"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":"Q"}, | ||
"name": "Q" | ||
} | ||
} | ||
] | ||
}, | ||
"optional": true | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":10,"end":22,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":12}}, | ||
"expression": { | ||
"type": "OptionalCallExpression", | ||
"start":10,"end":21,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":11}}, | ||
"callee": { | ||
"type": "Identifier", | ||
"start":10,"end":11,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":1},"identifierName":"f"}, | ||
"name": "f" | ||
}, | ||
"arguments": [], | ||
"typeParameters": { | ||
"type": "TSTypeParameterInstantiation", | ||
"start":13,"end":19,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":9}}, | ||
"params": [ | ||
{ | ||
"type": "TSTypeReference", | ||
"start":14,"end":15,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":5}}, | ||
"typeName": { | ||
"type": "Identifier", | ||
"start":14,"end":15,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":5},"identifierName":"Q"}, | ||
"name": "Q" | ||
} | ||
}, | ||
{ | ||
"type": "TSTypeReference", | ||
"start":17,"end":18,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":8}}, | ||
"typeName": { | ||
"type": "Identifier", | ||
"start":17,"end":18,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":8},"identifierName":"W"}, | ||
"name": "W" | ||
} | ||
} | ||
] | ||
}, | ||
"optional": true | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":23,"end":33,"loc":{"start":{"line":3,"column":0},"end":{"line":4,"column":8}}, | ||
"expression": { | ||
"type": "OptionalCallExpression", | ||
"start":23,"end":32,"loc":{"start":{"line":3,"column":0},"end":{"line":4,"column":7}}, | ||
"callee": { | ||
"type": "Identifier", | ||
"start":23,"end":24,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":1},"identifierName":"f"}, | ||
"name": "f" | ||
}, | ||
"arguments": [], | ||
"typeParameters": { | ||
"type": "TSTypeParameterInstantiation", | ||
"start":27,"end":30,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":5}}, | ||
"params": [ | ||
{ | ||
"type": "TSTypeReference", | ||
"start":28,"end":29,"loc":{"start":{"line":4,"column":3},"end":{"line":4,"column":4}}, | ||
"typeName": { | ||
"type": "Identifier", | ||
"start":28,"end":29,"loc":{"start":{"line":4,"column":3},"end":{"line":4,"column":4},"identifierName":"Q"}, | ||
"name": "Q" | ||
} | ||
} | ||
] | ||
}, | ||
"optional": true | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
...ges/babel-plugin-transform-typescript/test/fixtures/type-arguments/optional-call/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 |
---|---|---|
@@ -1 +1,3 @@ | ||
x?.f<T>(); | ||
x?.f<T>(); | ||
x?.f?.<T>(); | ||
f?.<Q>(); |
4 changes: 3 additions & 1 deletion
4
...es/babel-plugin-transform-typescript/test/fixtures/type-arguments/optional-call/output.js
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
x?.f(); | ||
x?.f(); | ||
x?.f?.(); | ||
f?.(); |