Skip to content

Commit

Permalink
[ts]Add optional property to OptionalCallExpression node that has typ…
Browse files Browse the repository at this point in the history
…e arguments (#12562)
  • Loading branch information
sosukesuzuki committed Jan 6, 2021
1 parent 584518d commit c1473e3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -1889,6 +1889,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
this.tsCheckForInvalidTypeCasts(node.arguments);

node.typeParameters = typeArguments;
if (state.optionalChainMember) {
// $FlowIgnore
node.optional = false;
}
return this.finishCallExpression(node, state.optionalChainMember);
} else if (this.match(tt.backQuote)) {
const result = this.parseTaggedTemplateExpression(
Expand Down
@@ -0,0 +1 @@
foo?.foo<T>();
@@ -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
}
}
}
]
}
}
Expand Up @@ -24,19 +24,19 @@
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7},"identifierName":"example"},
"name": "example"
},
"computed": false,
"property": {
"type": "Identifier",
"start":8,"end":13,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":13},"identifierName":"inner"},
"name": "inner"
},
"computed": false
}
},
"computed": false,
"property": {
"type": "Identifier",
"start":15,"end":20,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":20},"identifierName":"greet"},
"name": "greet"
},
"computed": false,
"optional": true
},
"arguments": [],
Expand All @@ -49,7 +49,8 @@
"start":21,"end":27,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":27}}
}
]
}
},
"optional": false
}
}
],
Expand Down

0 comments on commit c1473e3

Please sign in to comment.