Skip to content

Commit 4980fa4

Browse files
author
Kanchalai Tanglertsampan
committed
Update resolveEntityName to check for non entity name in property access expression
1 parent 1c90ef5 commit 4980fa4

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/compiler/checker.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,9 +1493,23 @@ namespace ts {
14931493
}
14941494
}
14951495
else if (name.kind === SyntaxKind.QualifiedName || name.kind === SyntaxKind.PropertyAccessExpression) {
1496-
const left = name.kind === SyntaxKind.QualifiedName ? (<QualifiedName>name).left : (<PropertyAccessEntityNameExpression>name).expression;
1497-
const right = name.kind === SyntaxKind.QualifiedName ? (<QualifiedName>name).right : (<PropertyAccessExpression>name).name;
1496+
let left: EntityNameOrEntityNameExpression;
14981497

1498+
if (name.kind === SyntaxKind.QualifiedName) {
1499+
left = (<QualifiedName>name).left;
1500+
}
1501+
else if (name.kind === SyntaxKind.PropertyAccessExpression &&
1502+
(name.expression.kind === SyntaxKind.ParenthesizedExpression || isEntityNameExpression(name.expression))) {
1503+
left = name.expression;
1504+
}
1505+
else {
1506+
// If the expression in property-access expression is not entity-name or parenthsizedExpression (e.g. it is a call expression), it won't be able to successfully resolve the name.
1507+
// This is the case when we are trying to do any language service operation in heritage clauses. By return undefined, the getSymbolOfEntityNameOrPropertyAccessExpression
1508+
// will attempt to checkPropertyAccessExpression to resolve symbol.
1509+
// i.e class C extends foo()./*do language service operation here*/B {}
1510+
return undefined;
1511+
}
1512+
const right = name.kind === SyntaxKind.QualifiedName ? name.right : name.name;
14991513
const namespace = resolveEntityName(left, SymbolFlags.Namespace, ignoreErrors, /*dontResolveAlias*/ false, location);
15001514
if (!namespace || nodeIsMissing(right)) {
15011515
return undefined;
@@ -1512,7 +1526,13 @@ namespace ts {
15121526
}
15131527
}
15141528
else if (name.kind === SyntaxKind.ParenthesizedExpression) {
1515-
return getSymbolOfNode(name.expression);
1529+
// If the expression in parenthsizedExpression is not an entity-name (e.g. it is a call expression), it won't be able to successfully resolve the name.
1530+
// This is the case when we are trying to do any language service operation in heritage clauses. By return undefined, the getSymbolOfEntityNameOrPropertyAccessExpression
1531+
// will attempt to checkPropertyAccessExpression to resolve symbol.
1532+
// i.e class C extends foo()./*do language service operation here*/B {}
1533+
return isEntityNameExpression(name.expression) ?
1534+
resolveEntityName(name.expression as EntityNameOrEntityNameExpression, meaning, ignoreErrors, dontResolveAlias, location) :
1535+
undefined;
15161536
}
15171537
else {
15181538
Debug.fail("Unknown entity name kind.");
@@ -21091,7 +21111,7 @@ namespace ts {
2109121111
return entityNameSymbol;
2109221112
}
2109321113
}
21094-
21114+
2109521115
if (isPartOfExpression(entityName)) {
2109621116
if (nodeIsMissing(entityName)) {
2109721117
// Missing entity name.

0 commit comments

Comments
 (0)