diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 379d61850e4..9e2b7a31748 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8424,12 +8424,12 @@ namespace ts { return node; } - function getReferenceParent(node: Node): Node { + function getReferenceRoot(node: Node): Node { const parent = node.parent; return parent.kind === SyntaxKind.ParenthesizedExpression || parent.kind === SyntaxKind.BinaryExpression && (parent).operatorToken.kind === SyntaxKind.EqualsToken && (parent).left === node || parent.kind === SyntaxKind.BinaryExpression && (parent).operatorToken.kind === SyntaxKind.CommaToken && (parent).right === node ? - getReferenceParent(parent) : parent; + getReferenceRoot(parent) : node; } function getTypeOfSwitchClause(clause: CaseClause | DefaultClause) { @@ -8564,7 +8564,7 @@ namespace ts { // Return true if the given node is 'x' in an 'x.push(value)' operation. function isPushCallTarget(node: Node) { - const parent = getReferenceParent(node); + const parent = getReferenceRoot(node).parent; return parent.kind === SyntaxKind.PropertyAccessExpression && (parent).name.text === "push" && parent.parent.kind === SyntaxKind.CallExpression; @@ -8573,9 +8573,10 @@ namespace ts { // Return true if the given node is 'x' in an 'x[n] = value' operation, where 'n' is an // expression of type any, undefined, or a number-like type. function isElementAssignmentTarget(node: Node) { - const parent = getReferenceParent(node); + const root = getReferenceRoot(node); + const parent = root.parent; return parent.kind === SyntaxKind.ElementAccessExpression && - (parent).expression === node && + (parent).expression === root && parent.parent.kind === SyntaxKind.BinaryExpression && (parent.parent).operatorToken.kind === SyntaxKind.EqualsToken && (parent.parent).left === parent &&