Skip parens and non-null assertions when looking for this-context (#23097)

* Skip parens and ! for getting this-context of call

* Add test and improve code a bit

* Use skipOuterExpressions instead
This commit is contained in:
Nathan Shively-Sanders
2018-04-03 06:23:59 -07:00
committed by GitHub
parent a2c11bb7a0
commit 11eabc0946
6 changed files with 165 additions and 7 deletions

View File

@@ -17269,12 +17269,9 @@ namespace ts {
*/
function getThisArgumentOfCall(node: CallLikeExpression): LeftHandSideExpression {
if (node.kind === SyntaxKind.CallExpression) {
const callee = node.expression;
if (callee.kind === SyntaxKind.PropertyAccessExpression) {
return (callee as PropertyAccessExpression).expression;
}
else if (callee.kind === SyntaxKind.ElementAccessExpression) {
return (callee as ElementAccessExpression).expression;
const callee = skipOuterExpressions(node.expression);
if (callee.kind === SyntaxKind.PropertyAccessExpression || callee.kind === SyntaxKind.ElementAccessExpression) {
return (callee as PropertyAccessExpression | ElementAccessExpression).expression;
}
}
}

View File

@@ -2022,7 +2022,7 @@ namespace ts {
export function skipParentheses(node: Node): Node;
export function skipParentheses(node: Node): Node {
while (node.kind === SyntaxKind.ParenthesizedExpression) {
node = (<ParenthesizedExpression>node).expression;
node = (node as ParenthesizedExpression).expression;
}
return node;