From 4980fa4d5d7145499f3ebe95b3c06cfe61f451cc Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 16 Mar 2017 13:39:17 -0700 Subject: [PATCH] Update resolveEntityName to check for non entity name in property access expression --- src/compiler/checker.ts | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ab35f15b604..e90560f9ce8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1493,9 +1493,23 @@ namespace ts { } } else if (name.kind === SyntaxKind.QualifiedName || name.kind === SyntaxKind.PropertyAccessExpression) { - const left = name.kind === SyntaxKind.QualifiedName ? (name).left : (name).expression; - const right = name.kind === SyntaxKind.QualifiedName ? (name).right : (name).name; + let left: EntityNameOrEntityNameExpression; + if (name.kind === SyntaxKind.QualifiedName) { + left = (name).left; + } + else if (name.kind === SyntaxKind.PropertyAccessExpression && + (name.expression.kind === SyntaxKind.ParenthesizedExpression || isEntityNameExpression(name.expression))) { + left = name.expression; + } + else { + // 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. + // This is the case when we are trying to do any language service operation in heritage clauses. By return undefined, the getSymbolOfEntityNameOrPropertyAccessExpression + // will attempt to checkPropertyAccessExpression to resolve symbol. + // i.e class C extends foo()./*do language service operation here*/B {} + return undefined; + } + const right = name.kind === SyntaxKind.QualifiedName ? name.right : name.name; const namespace = resolveEntityName(left, SymbolFlags.Namespace, ignoreErrors, /*dontResolveAlias*/ false, location); if (!namespace || nodeIsMissing(right)) { return undefined; @@ -1512,7 +1526,13 @@ namespace ts { } } else if (name.kind === SyntaxKind.ParenthesizedExpression) { - return getSymbolOfNode(name.expression); + // 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. + // This is the case when we are trying to do any language service operation in heritage clauses. By return undefined, the getSymbolOfEntityNameOrPropertyAccessExpression + // will attempt to checkPropertyAccessExpression to resolve symbol. + // i.e class C extends foo()./*do language service operation here*/B {} + return isEntityNameExpression(name.expression) ? + resolveEntityName(name.expression as EntityNameOrEntityNameExpression, meaning, ignoreErrors, dontResolveAlias, location) : + undefined; } else { Debug.fail("Unknown entity name kind."); @@ -21091,7 +21111,7 @@ namespace ts { return entityNameSymbol; } } - + if (isPartOfExpression(entityName)) { if (nodeIsMissing(entityName)) { // Missing entity name.