Skip to content

Commit 949bb27

Browse files
committed
Convert Declaration to union, not type hierarchy
1 parent 1bdea39 commit 949bb27

File tree

5 files changed

+191
-88
lines changed

5 files changed

+191
-88
lines changed

src/compiler/binder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ namespace ts {
304304
}
305305

306306
function getDisplayName(node: Declaration): string {
307-
return (node as RealDeclaration).name ? declarationNameToString((node as RealDeclaration).name) : getDeclarationName(node);
307+
return (node as DeclarationBase).name ? declarationNameToString((node as DeclarationBase).name) : getDeclarationName(node);
308308
}
309309

310310
/**
@@ -367,8 +367,8 @@ namespace ts {
367367
symbolTable.set(name, symbol = createSymbol(SymbolFlags.None, name));
368368
}
369369
else {
370-
if ((node as RealDeclaration).name) {
371-
(node as RealDeclaration).name.parent = node;
370+
if ((node as DeclarationBase).name) {
371+
(node as DeclarationBase).name.parent = node;
372372
}
373373

374374
// Report errors every position with duplicate declaration

src/compiler/checker.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3617,7 +3617,7 @@ namespace ts {
36173617
});
36183618
}
36193619

3620-
function isDeclarationVisible(node: Declaration): boolean {
3620+
function isDeclarationVisible(node: Node): boolean {
36213621
if (node) {
36223622
const links = getNodeLinks(node);
36233623
if (links.isVisible === undefined) {
@@ -3631,10 +3631,10 @@ namespace ts {
36313631
function determineIfDeclarationIsVisible() {
36323632
switch (node.kind) {
36333633
case SyntaxKind.BindingElement:
3634-
return isDeclarationVisible(<Declaration>node.parent.parent);
3634+
return isDeclarationVisible(node.parent.parent);
36353635
case SyntaxKind.VariableDeclaration:
3636-
if (isBindingPattern(node.name) &&
3637-
!(<BindingPattern>node.name).elements.length) {
3636+
const declaration = node as VariableDeclaration;
3637+
if (isBindingPattern(declaration.name) && !declaration.name.elements.length) {
36383638
// If the binding pattern is empty, this variable declaration is not visible
36393639
return false;
36403640
}
@@ -3657,7 +3657,7 @@ namespace ts {
36573657
return isGlobalSourceFile(parent);
36583658
}
36593659
// Exported members/ambient module elements (exception import declaration) are visible if parent is visible
3660-
return isDeclarationVisible(<Declaration>parent);
3660+
return isDeclarationVisible(parent);
36613661

36623662
case SyntaxKind.PropertyDeclaration:
36633663
case SyntaxKind.PropertySignature:
@@ -3687,7 +3687,7 @@ namespace ts {
36873687
case SyntaxKind.UnionType:
36883688
case SyntaxKind.IntersectionType:
36893689
case SyntaxKind.ParenthesizedType:
3690-
return isDeclarationVisible(<Declaration>node.parent);
3690+
return isDeclarationVisible(node.parent);
36913691

36923692
// Default binding, import specifier and namespace import is visible
36933693
// only on demand so by default it is not visible
@@ -6235,8 +6235,8 @@ namespace ts {
62356235
case SyntaxKind.MethodDeclaration:
62366236
case SyntaxKind.GetAccessor:
62376237
case SyntaxKind.SetAccessor:
6238-
return (<RealDeclaration>node).name.kind === SyntaxKind.ComputedPropertyName
6239-
&& traverse((<RealDeclaration>node).name);
6238+
return (<DeclarationBase>node).name.kind === SyntaxKind.ComputedPropertyName
6239+
&& traverse((<DeclarationBase>node).name);
62406240

62416241
default:
62426242
return !nodeStartsNewLexicalEnvironment(node) && !isPartOfTypeNode(node) && forEachChild(node, traverse);
@@ -21841,7 +21841,7 @@ namespace ts {
2184121841
function isTypeDeclarationName(name: Node): boolean {
2184221842
return name.kind === SyntaxKind.Identifier &&
2184321843
isTypeDeclaration(name.parent) &&
21844-
(<RealDeclaration>name.parent).name === name;
21844+
(<TypeElement>name.parent).name === name;
2184521845
}
2184621846

2184721847
function isTypeDeclaration(node: Node): boolean {
@@ -22469,7 +22469,7 @@ namespace ts {
2246922469

2247022470
// Return true if the given node is a declaration of a nested block scoped entity with a name that either hides an
2247122471
// existing name or might hide a name when compiled downlevel
22472-
function isDeclarationWithCollidingName(node: Declaration): boolean {
22472+
function isDeclarationWithCollidingName(node: Node): boolean {
2247322473
node = getParseTreeNode(node, isDeclaration);
2247422474
if (node) {
2247522475
const symbol = getSymbolOfNode(node);

src/compiler/transformers/es2015.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3748,7 +3748,7 @@ namespace ts {
37483748
case SyntaxKind.ClassDeclaration:
37493749
case SyntaxKind.EnumDeclaration:
37503750
case SyntaxKind.VariableDeclaration:
3751-
return (<RealDeclaration>parent).name === node
3751+
return (<DeclarationBase>parent).name === node
37523752
&& resolver.isDeclarationWithCollidingName(<Declaration>parent);
37533753
}
37543754

0 commit comments

Comments
 (0)