@@ -7764,16 +7764,17 @@ namespace ts {
7764
7764
}
7765
7765
7766
7766
function isMatchingReference(source: Node, target: Node): boolean {
7767
- if (source.kind === target.kind) {
7768
- switch (source.kind) {
7769
- case SyntaxKind.Identifier:
7770
- return getResolvedSymbol(<Identifier>source) === getResolvedSymbol(<Identifier>target);
7771
- case SyntaxKind.ThisKeyword:
7772
- return true;
7773
- case SyntaxKind.PropertyAccessExpression:
7774
- return (<PropertyAccessExpression>source).name.text === (<PropertyAccessExpression>target).name.text &&
7775
- isMatchingReference((<PropertyAccessExpression>source).expression, (<PropertyAccessExpression>target).expression);
7776
- }
7767
+ switch (source.kind) {
7768
+ case SyntaxKind.Identifier:
7769
+ return target.kind === SyntaxKind.Identifier && getResolvedSymbol(<Identifier>source) === getResolvedSymbol(<Identifier>target) ||
7770
+ (target.kind === SyntaxKind.VariableDeclaration || target.kind === SyntaxKind.BindingElement) &&
7771
+ getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(<Identifier>source)) === getSymbolOfNode(target);
7772
+ case SyntaxKind.ThisKeyword:
7773
+ return target.kind === SyntaxKind.ThisKeyword;
7774
+ case SyntaxKind.PropertyAccessExpression:
7775
+ return target.kind === SyntaxKind.PropertyAccessExpression &&
7776
+ (<PropertyAccessExpression>source).name.text === (<PropertyAccessExpression>target).name.text &&
7777
+ isMatchingReference((<PropertyAccessExpression>source).expression, (<PropertyAccessExpression>target).expression);
7777
7778
}
7778
7779
return false;
7779
7780
}
@@ -8031,6 +8032,12 @@ namespace ts {
8031
8032
getInitialTypeOfBindingElement(<BindingElement>node);
8032
8033
}
8033
8034
8035
+ function getInitialOrAssignedType(node: VariableDeclaration | BindingElement | Expression) {
8036
+ return node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement ?
8037
+ getInitialType(<VariableDeclaration | BindingElement>node) :
8038
+ getAssignedType(<Expression>node);
8039
+ }
8040
+
8034
8041
function getReferenceCandidate(node: Expression): Expression {
8035
8042
switch (node.kind) {
8036
8043
case SyntaxKind.ParenthesizedExpression:
@@ -8153,19 +8160,9 @@ namespace ts {
8153
8160
const node = flow.node;
8154
8161
// Assignments only narrow the computed type if the declared type is a union type. Thus, we
8155
8162
// only need to evaluate the assigned type if the declared type is a union type.
8156
- if ((node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) &&
8157
- reference.kind === SyntaxKind.Identifier &&
8158
- getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(<Identifier>reference)) === getSymbolOfNode(node)) {
8159
- return declaredType.flags & TypeFlags.Union ?
8160
- getAssignmentReducedType(<UnionType>declaredType, getInitialType(<VariableDeclaration | BindingElement>node)) :
8161
- declaredType;
8162
- }
8163
- // If the node is not a variable declaration or binding element, it is an identifier
8164
- // or a dotted name that is the target of an assignment. If we have a match, reduce
8165
- // the declared type by the assigned type.
8166
8163
if (isMatchingReference(reference, node)) {
8167
8164
return declaredType.flags & TypeFlags.Union ?
8168
- getAssignmentReducedType(<UnionType>declaredType, getAssignedType(<Expression> node)) :
8165
+ getAssignmentReducedType(<UnionType>declaredType, getInitialOrAssignedType( node)) :
8169
8166
declaredType;
8170
8167
}
8171
8168
// We didn't have a direct match. However, if the reference is a dotted name, this
0 commit comments