[ts]Add optional property to OptionalCallExpression node that has type arguments (#12562)
This commit is contained in:
parent
584518d04c
commit
c1473e30b2
@ -1889,6 +1889,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
this.tsCheckForInvalidTypeCasts(node.arguments);
|
this.tsCheckForInvalidTypeCasts(node.arguments);
|
||||||
|
|
||||||
node.typeParameters = typeArguments;
|
node.typeParameters = typeArguments;
|
||||||
|
if (state.optionalChainMember) {
|
||||||
|
// $FlowIgnore
|
||||||
|
node.optional = false;
|
||||||
|
}
|
||||||
return this.finishCallExpression(node, state.optionalChainMember);
|
return this.finishCallExpression(node, state.optionalChainMember);
|
||||||
} else if (this.match(tt.backQuote)) {
|
} else if (this.match(tt.backQuote)) {
|
||||||
const result = this.parseTaggedTemplateExpression(
|
const result = this.parseTaggedTemplateExpression(
|
||||||
|
|||||||
1
packages/babel-parser/test/fixtures/estree/typescript/optional-chaining/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/estree/typescript/optional-chaining/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
foo?.foo<T>();
|
||||||
57
packages/babel-parser/test/fixtures/estree/typescript/optional-chaining/output.json
vendored
Normal file
57
packages/babel-parser/test/fixtures/estree/typescript/optional-chaining/output.json
vendored
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
|
||||||
|
"sourceType": "script",
|
||||||
|
"interpreter": null,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
|
||||||
|
"expression": {
|
||||||
|
"type": "ChainExpression",
|
||||||
|
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
|
||||||
|
"expression": {
|
||||||
|
"type": "CallExpression",
|
||||||
|
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
|
||||||
|
"callee": {
|
||||||
|
"type": "MemberExpression",
|
||||||
|
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}},
|
||||||
|
"object": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3},"identifierName":"foo"},
|
||||||
|
"name": "foo"
|
||||||
|
},
|
||||||
|
"computed": false,
|
||||||
|
"property": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":5,"end":8,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":8},"identifierName":"foo"},
|
||||||
|
"name": "foo"
|
||||||
|
},
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"arguments": [],
|
||||||
|
"typeParameters": {
|
||||||
|
"type": "TSTypeParameterInstantiation",
|
||||||
|
"start":8,"end":11,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":11}},
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "TSTypeReference",
|
||||||
|
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10}},
|
||||||
|
"typeName": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10},"identifierName":"T"},
|
||||||
|
"name": "T"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"optional": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -24,19 +24,19 @@
|
|||||||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7},"identifierName":"example"},
|
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7},"identifierName":"example"},
|
||||||
"name": "example"
|
"name": "example"
|
||||||
},
|
},
|
||||||
|
"computed": false,
|
||||||
"property": {
|
"property": {
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start":8,"end":13,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":13},"identifierName":"inner"},
|
"start":8,"end":13,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":13},"identifierName":"inner"},
|
||||||
"name": "inner"
|
"name": "inner"
|
||||||
},
|
}
|
||||||
"computed": false
|
|
||||||
},
|
},
|
||||||
|
"computed": false,
|
||||||
"property": {
|
"property": {
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start":15,"end":20,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":20},"identifierName":"greet"},
|
"start":15,"end":20,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":20},"identifierName":"greet"},
|
||||||
"name": "greet"
|
"name": "greet"
|
||||||
},
|
},
|
||||||
"computed": false,
|
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"arguments": [],
|
"arguments": [],
|
||||||
@ -49,7 +49,8 @@
|
|||||||
"start":21,"end":27,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":27}}
|
"start":21,"end":27,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":27}}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"optional": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user