Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EntityNameExpression doesn't need to include ParenthesizedExpression #21588

Merged
1 commit merged into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1975,8 +1975,7 @@ namespace ts {
if (name.kind === SyntaxKind.QualifiedName) {
left = (<QualifiedName>name).left;
}
else if (name.kind === SyntaxKind.PropertyAccessExpression &&
(name.expression.kind === SyntaxKind.ParenthesizedExpression || isEntityNameExpression(name.expression))) {
else if (name.kind === SyntaxKind.PropertyAccessExpression) {
left = name.expression;
}
else {
Expand Down Expand Up @@ -2005,15 +2004,6 @@ namespace ts {
return undefined;
}
}
else if (name.kind === SyntaxKind.ParenthesizedExpression) {
// If the expression in parenthesizedExpression 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.assertNever(name, "Unknown entity name kind.");
}
Expand Down Expand Up @@ -24203,8 +24193,8 @@ namespace ts {
}
}

if (entityName.parent.kind === SyntaxKind.ExportAssignment && isEntityNameExpression(<Identifier | PropertyAccessExpression>entityName)) {
return resolveEntityName(<EntityNameExpression>entityName,
if (entityName.parent.kind === SyntaxKind.ExportAssignment && isEntityNameExpression(entityName)) {
return resolveEntityName(entityName,
/*all meanings*/ SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
}

Expand All @@ -24219,7 +24209,7 @@ namespace ts {
entityName = <QualifiedName | PropertyAccessEntityNameExpression>entityName.parent;
}

if (isHeritageClauseElementIdentifier(<EntityName>entityName)) {
if (isHeritageClauseElementIdentifier(entityName)) {
let meaning = SymbolFlags.None;
// In an interface or class, we're definitely interested in a type.
if (entityName.parent.kind === SyntaxKind.ExpressionWithTypeArguments) {
Expand All @@ -24235,7 +24225,7 @@ namespace ts {
}

meaning |= SymbolFlags.Alias;
const entityNameSymbol = resolveEntityName(<EntityName>entityName, meaning);
const entityNameSymbol = isEntityNameExpression(entityName) ? resolveEntityName(entityName, meaning) : undefined;
if (entityNameSymbol) {
return entityNameSymbol;
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ namespace ts {
multiLine?: boolean;
}

export type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression | ParenthesizedExpression;
export type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression;
export type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression;

export interface PropertyAccessExpression extends MemberExpression, NamedDeclaration {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3286,7 +3286,7 @@ namespace ts {
&& isClassLike(node.parent.parent);
}

export function isEntityNameExpression(node: Expression): node is EntityNameExpression {
export function isEntityNameExpression(node: Node): node is EntityNameExpression {
return node.kind === SyntaxKind.Identifier ||
node.kind === SyntaxKind.PropertyAccessExpression && isEntityNameExpression((<PropertyAccessExpression>node).expression);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ declare namespace ts {
interface ObjectLiteralExpression extends ObjectLiteralExpressionBase<ObjectLiteralElementLike> {
kind: SyntaxKind.ObjectLiteralExpression;
}
type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression | ParenthesizedExpression;
type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression;
type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression;
interface PropertyAccessExpression extends MemberExpression, NamedDeclaration {
kind: SyntaxKind.PropertyAccessExpression;
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ declare namespace ts {
interface ObjectLiteralExpression extends ObjectLiteralExpressionBase<ObjectLiteralElementLike> {
kind: SyntaxKind.ObjectLiteralExpression;
}
type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression | ParenthesizedExpression;
type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression;
type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression;
interface PropertyAccessExpression extends MemberExpression, NamedDeclaration {
kind: SyntaxKind.PropertyAccessExpression;
Expand Down