Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ts] Disallow property access after instantiation expression (#14650)
- Loading branch information
1 parent
d5823f2
commit e4e700e
Showing
5 changed files
with
531 additions
and
1 deletion.
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
2 changes: 2 additions & 0 deletions
2
.../test/fixtures/typescript/type-arguments/instantiation-expression-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,2 @@ | ||
a?.b<c>; | ||
a?.b<c>(); |
93 changes: 93 additions & 0 deletions
93
...st/fixtures/typescript/type-arguments/instantiation-expression-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,93 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":10,"index":19}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":19,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":10,"index":19}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":8,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":8,"index":8}}, | ||
"expression": { | ||
"type": "TSInstantiationExpression", | ||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":7,"index":7}}, | ||
"expression": { | ||
"type": "OptionalMemberExpression", | ||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":4,"index":4}}, | ||
"object": { | ||
"type": "Identifier", | ||
"start":0,"end":1,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":1,"index":1},"identifierName":"a"}, | ||
"name": "a" | ||
}, | ||
"computed": false, | ||
"property": { | ||
"type": "Identifier", | ||
"start":3,"end":4,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":4,"index":4},"identifierName":"b"}, | ||
"name": "b" | ||
}, | ||
"optional": true | ||
}, | ||
"typeParameters": { | ||
"type": "TSTypeParameterInstantiation", | ||
"start":4,"end":7,"loc":{"start":{"line":1,"column":4,"index":4},"end":{"line":1,"column":7,"index":7}}, | ||
"params": [ | ||
{ | ||
"type": "TSTypeReference", | ||
"start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6}}, | ||
"typeName": { | ||
"type": "Identifier", | ||
"start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6},"identifierName":"c"}, | ||
"name": "c" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":9,"end":19,"loc":{"start":{"line":2,"column":0,"index":9},"end":{"line":2,"column":10,"index":19}}, | ||
"expression": { | ||
"type": "OptionalCallExpression", | ||
"start":9,"end":18,"loc":{"start":{"line":2,"column":0,"index":9},"end":{"line":2,"column":9,"index":18}}, | ||
"callee": { | ||
"type": "OptionalMemberExpression", | ||
"start":9,"end":13,"loc":{"start":{"line":2,"column":0,"index":9},"end":{"line":2,"column":4,"index":13}}, | ||
"object": { | ||
"type": "Identifier", | ||
"start":9,"end":10,"loc":{"start":{"line":2,"column":0,"index":9},"end":{"line":2,"column":1,"index":10},"identifierName":"a"}, | ||
"name": "a" | ||
}, | ||
"computed": false, | ||
"property": { | ||
"type": "Identifier", | ||
"start":12,"end":13,"loc":{"start":{"line":2,"column":3,"index":12},"end":{"line":2,"column":4,"index":13},"identifierName":"b"}, | ||
"name": "b" | ||
}, | ||
"optional": true | ||
}, | ||
"arguments": [], | ||
"typeParameters": { | ||
"type": "TSTypeParameterInstantiation", | ||
"start":13,"end":16,"loc":{"start":{"line":2,"column":4,"index":13},"end":{"line":2,"column":7,"index":16}}, | ||
"params": [ | ||
{ | ||
"type": "TSTypeReference", | ||
"start":14,"end":15,"loc":{"start":{"line":2,"column":5,"index":14},"end":{"line":2,"column":6,"index":15}}, | ||
"typeName": { | ||
"type": "Identifier", | ||
"start":14,"end":15,"loc":{"start":{"line":2,"column":5,"index":14},"end":{"line":2,"column":6,"index":15},"identifierName":"c"}, | ||
"name": "c" | ||
} | ||
} | ||
] | ||
}, | ||
"optional": false | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...test/fixtures/typescript/type-arguments/instantiation-expression-property-access/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,13 @@ | ||
// invalid | ||
a<b>.c; | ||
a<b>?.c; | ||
a<b>?.[c]; | ||
|
||
// valid | ||
a<b>?.(c); | ||
(a<b>).c; | ||
(a<b>)?.c; | ||
(a<b>)?.[c]; | ||
|
||
// longer, invalid | ||
a?.b<c>.d |
Oops, something went wrong.