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

Get name of declaration uniformly, even for JS-style assignment declarations. #15594

Merged
merged 12 commits into from
May 10, 2017
6 changes: 3 additions & 3 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ namespace ts {
}

function getDisplayName(node: Declaration): string {
return (node as RealDeclaration).name ? declarationNameToString((node as RealDeclaration).name) : getDeclarationName(node);
return (node as DeclarationBase).name ? declarationNameToString((node as DeclarationBase).name) : getDeclarationName(node);
}

/**
Expand Down Expand Up @@ -367,8 +367,8 @@ namespace ts {
symbolTable.set(name, symbol = createSymbol(SymbolFlags.None, name));
}
else {
if ((node as RealDeclaration).name) {
(node as RealDeclaration).name.parent = node;
if ((node as DeclarationBase).name) {
(node as DeclarationBase).name.parent = node;
}

// Report errors every position with duplicate declaration
Expand Down
20 changes: 10 additions & 10 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3621,7 +3621,7 @@ namespace ts {
});
}

function isDeclarationVisible(node: Declaration): boolean {
function isDeclarationVisible(node: Node): boolean {
if (node) {
const links = getNodeLinks(node);
if (links.isVisible === undefined) {
Expand All @@ -3635,10 +3635,10 @@ namespace ts {
function determineIfDeclarationIsVisible() {
switch (node.kind) {
case SyntaxKind.BindingElement:
return isDeclarationVisible(<Declaration>node.parent.parent);
return isDeclarationVisible(node.parent.parent);
case SyntaxKind.VariableDeclaration:
if (isBindingPattern(node.name) &&
!(<BindingPattern>node.name).elements.length) {
const declaration = node as VariableDeclaration;
if (isBindingPattern(declaration.name) && !declaration.name.elements.length) {
// If the binding pattern is empty, this variable declaration is not visible
return false;
}
Expand All @@ -3661,7 +3661,7 @@ namespace ts {
return isGlobalSourceFile(parent);
}
// Exported members/ambient module elements (exception import declaration) are visible if parent is visible
return isDeclarationVisible(<Declaration>parent);
return isDeclarationVisible(parent);

case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
Expand Down Expand Up @@ -3691,7 +3691,7 @@ namespace ts {
case SyntaxKind.UnionType:
case SyntaxKind.IntersectionType:
case SyntaxKind.ParenthesizedType:
return isDeclarationVisible(<Declaration>node.parent);
return isDeclarationVisible(node.parent);

// Default binding, import specifier and namespace import is visible
// only on demand so by default it is not visible
Expand Down Expand Up @@ -6236,8 +6236,8 @@ namespace ts {
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
return (<RealDeclaration>node).name.kind === SyntaxKind.ComputedPropertyName
&& traverse((<RealDeclaration>node).name);
return (<DeclarationBase>node).name.kind === SyntaxKind.ComputedPropertyName
&& traverse((<DeclarationBase>node).name);

default:
return !nodeStartsNewLexicalEnvironment(node) && !isPartOfTypeNode(node) && forEachChild(node, traverse);
Expand Down Expand Up @@ -21917,7 +21917,7 @@ namespace ts {
function isTypeDeclarationName(name: Node): boolean {
return name.kind === SyntaxKind.Identifier &&
isTypeDeclaration(name.parent) &&
(<RealDeclaration>name.parent).name === name;
(<TypeElement>name.parent).name === name;
}

function isTypeDeclaration(node: Node): boolean {
Expand Down Expand Up @@ -22545,7 +22545,7 @@ namespace ts {

// Return true if the given node is a declaration of a nested block scoped entity with a name that either hides an
// existing name or might hide a name when compiled downlevel
function isDeclarationWithCollidingName(node: Declaration): boolean {
function isDeclarationWithCollidingName(node: Node): boolean {
node = getParseTreeNode(node, isDeclaration);
if (node) {
const symbol = getSymbolOfNode(node);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/es2015.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3748,7 +3748,7 @@ namespace ts {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.VariableDeclaration:
return (<RealDeclaration>parent).name === node
return (<DeclarationBase>parent).name === node
&& resolver.isDeclarationWithCollidingName(<Declaration>parent);
}

Expand Down
Loading