Skip to content

Commit 9392342

Browse files
committed
Switch to Declaration/NamedDeclaration hierarchy
1 parent acec74b commit 9392342

File tree

7 files changed

+50
-50
lines changed

7 files changed

+50
-50
lines changed

src/compiler/binder.ts

Lines changed: 6 additions & 6 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 NamedDeclaration).name ? declarationNameToString((node as NamedDeclaration).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 NamedDeclaration).name) {
371+
(node as NamedDeclaration).name.parent = node;
372372
}
373373

374374
// Report errors every position with duplicate declaration
@@ -440,9 +440,9 @@ namespace ts {
440440
// and this case is specially handled. Module augmentations should only be merged with original module definition
441441
// and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed.
442442
const isJSDocTypedefInJSDocNamespace = node.kind === SyntaxKind.JSDocTypedefTag &&
443-
node.name &&
444-
node.name.kind === SyntaxKind.Identifier &&
445-
(<Identifier>node.name).isInJSDocNamespace;
443+
(node as JSDocTypedefTag).name &&
444+
(node as JSDocTypedefTag).name.kind === SyntaxKind.Identifier &&
445+
((node as JSDocTypedefTag).name as Identifier).isInJSDocNamespace;
446446
if ((!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) || isJSDocTypedefInJSDocNamespace) {
447447
const exportKind =
448448
(symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) |

src/compiler/checker.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3637,8 +3637,8 @@ namespace ts {
36373637
case SyntaxKind.BindingElement:
36383638
return isDeclarationVisible(<Declaration>node.parent.parent);
36393639
case SyntaxKind.VariableDeclaration:
3640-
if (isBindingPattern(node.name) &&
3641-
!(<BindingPattern>node.name).elements.length) {
3640+
if (isBindingPattern((node as VariableDeclaration).name) &&
3641+
!((node as VariableDeclaration).name as BindingPattern).elements.length) {
36423642
// If the binding pattern is empty, this variable declaration is not visible
36433643
return false;
36443644
}
@@ -6236,8 +6236,8 @@ namespace ts {
62366236
case SyntaxKind.MethodDeclaration:
62376237
case SyntaxKind.GetAccessor:
62386238
case SyntaxKind.SetAccessor:
6239-
return (<RealDeclaration>node).name.kind === SyntaxKind.ComputedPropertyName
6240-
&& traverse((<RealDeclaration>node).name);
6239+
return (<NamedDeclaration>node).name.kind === SyntaxKind.ComputedPropertyName
6240+
&& traverse((<NamedDeclaration>node).name);
62416241

62426242
default:
62436243
return !nodeStartsNewLexicalEnvironment(node) && !isPartOfTypeNode(node) && forEachChild(node, traverse);
@@ -9925,7 +9925,7 @@ namespace ts {
99259925
case SyntaxKind.SetAccessor:
99269926
case SyntaxKind.FunctionExpression:
99279927
case SyntaxKind.ArrowFunction:
9928-
if (!declaration.name) {
9928+
if (!(declaration as NamedDeclaration).name) {
99299929
error(declaration, Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString);
99309930
return;
99319931
}
@@ -21909,7 +21909,7 @@ namespace ts {
2190921909
function isTypeDeclarationName(name: Node): boolean {
2191021910
return name.kind === SyntaxKind.Identifier &&
2191121911
isTypeDeclaration(name.parent) &&
21912-
(<RealDeclaration>name.parent).name === name;
21912+
(<NamedDeclaration>name.parent).name === name;
2191321913
}
2191421914

2191521915
function isTypeDeclaration(node: Node): boolean {

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 (<NamedDeclaration>parent).name === node
37523752
&& resolver.isDeclarationWithCollidingName(<Declaration>parent);
37533753
}
37543754

src/compiler/types.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -603,15 +603,15 @@ namespace ts {
603603

604604
export type DeclarationName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName | BindingPattern;
605605

606-
export interface RealDeclaration extends Node {
606+
export interface Declaration extends Node {
607607
_declarationBrand: any;
608-
name?: DeclarationName;
609608
}
610609

611-
// Binary expressions can be declarations if they are 'exports.foo = bar' expressions in JS files
612-
export type Declaration = RealDeclaration | BinaryExpression;
610+
export interface NamedDeclaration extends Declaration {
611+
name?: DeclarationName;
612+
}
613613

614-
export interface DeclarationStatement extends RealDeclaration, Statement {
614+
export interface DeclarationStatement extends NamedDeclaration, Statement {
615615
name?: Identifier | StringLiteral | NumericLiteral;
616616
}
617617

@@ -625,7 +625,7 @@ namespace ts {
625625
expression: LeftHandSideExpression;
626626
}
627627

628-
export interface TypeParameterDeclaration extends RealDeclaration {
628+
export interface TypeParameterDeclaration extends NamedDeclaration {
629629
kind: SyntaxKind.TypeParameter;
630630
parent?: DeclarationWithTypeParameters;
631631
name: Identifier;
@@ -636,7 +636,7 @@ namespace ts {
636636
expression?: Expression;
637637
}
638638

639-
export interface SignatureDeclaration extends RealDeclaration {
639+
export interface SignatureDeclaration extends NamedDeclaration {
640640
name?: PropertyName;
641641
typeParameters?: NodeArray<TypeParameterDeclaration>;
642642
parameters: NodeArray<ParameterDeclaration>;
@@ -653,7 +653,7 @@ namespace ts {
653653

654654
export type BindingName = Identifier | BindingPattern;
655655

656-
export interface VariableDeclaration extends RealDeclaration {
656+
export interface VariableDeclaration extends NamedDeclaration {
657657
kind: SyntaxKind.VariableDeclaration;
658658
parent?: VariableDeclarationList | CatchClause;
659659
name: BindingName; // Declared variable name
@@ -667,7 +667,7 @@ namespace ts {
667667
declarations: NodeArray<VariableDeclaration>;
668668
}
669669

670-
export interface ParameterDeclaration extends RealDeclaration {
670+
export interface ParameterDeclaration extends NamedDeclaration {
671671
kind: SyntaxKind.Parameter;
672672
parent?: SignatureDeclaration;
673673
dotDotDotToken?: DotDotDotToken; // Present on rest parameter
@@ -677,7 +677,7 @@ namespace ts {
677677
initializer?: Expression; // Optional initializer
678678
}
679679

680-
export interface BindingElement extends RealDeclaration {
680+
export interface BindingElement extends NamedDeclaration {
681681
kind: SyntaxKind.BindingElement;
682682
parent?: BindingPattern;
683683
propertyName?: PropertyName; // Binding property name (in object binding pattern)
@@ -702,7 +702,7 @@ namespace ts {
702702
initializer?: Expression; // Optional initializer
703703
}
704704

705-
export interface ObjectLiteralElement extends RealDeclaration {
705+
export interface ObjectLiteralElement extends NamedDeclaration {
706706
_objectLiteralBrandBrand: any;
707707
name?: PropertyName;
708708
}
@@ -746,7 +746,7 @@ namespace ts {
746746
// SyntaxKind.ShorthandPropertyAssignment
747747
// SyntaxKind.EnumMember
748748
// SyntaxKind.JSDocPropertyTag
749-
export interface VariableLikeDeclaration extends RealDeclaration {
749+
export interface VariableLikeDeclaration extends NamedDeclaration {
750750
propertyName?: PropertyName;
751751
dotDotDotToken?: DotDotDotToken;
752752
name: DeclarationName;
@@ -755,7 +755,7 @@ namespace ts {
755755
initializer?: Expression;
756756
}
757757

758-
export interface PropertyLikeDeclaration extends RealDeclaration {
758+
export interface PropertyLikeDeclaration extends NamedDeclaration {
759759
name: PropertyName;
760760
}
761761

@@ -904,7 +904,7 @@ namespace ts {
904904
}
905905

906906
// A TypeLiteral is the declaration node for an anonymous symbol.
907-
export interface TypeLiteralNode extends TypeNode, RealDeclaration {
907+
export interface TypeLiteralNode extends TypeNode, NamedDeclaration {
908908
kind: SyntaxKind.TypeLiteral;
909909
members: NodeArray<TypeElement>;
910910
}
@@ -948,7 +948,7 @@ namespace ts {
948948
indexType: TypeNode;
949949
}
950950

951-
export interface MappedTypeNode extends TypeNode, RealDeclaration {
951+
export interface MappedTypeNode extends TypeNode, NamedDeclaration {
952952
kind: SyntaxKind.MappedType;
953953
parent?: TypeAliasDeclaration;
954954
readonlyToken?: ReadonlyToken;
@@ -1219,7 +1219,7 @@ namespace ts {
12191219

12201220
export type BinaryOperatorToken = Token<BinaryOperator>;
12211221

1222-
export interface BinaryExpression extends Expression {
1222+
export interface BinaryExpression extends Expression, Declaration {
12231223
kind: SyntaxKind.BinaryExpression;
12241224
left: Expression;
12251225
operatorToken: BinaryOperatorToken;
@@ -1405,7 +1405,7 @@ namespace ts {
14051405
* JSXAttribute or JSXSpreadAttribute. ObjectLiteralExpression, on the other hand, can only have properties of type
14061406
* ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.)
14071407
*/
1408-
export interface ObjectLiteralExpressionBase<T extends ObjectLiteralElement> extends PrimaryExpression, RealDeclaration {
1408+
export interface ObjectLiteralExpressionBase<T extends ObjectLiteralElement> extends PrimaryExpression, NamedDeclaration {
14091409
properties: NodeArray<T>;
14101410
}
14111411

@@ -1419,7 +1419,7 @@ namespace ts {
14191419
export type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression | ParenthesizedExpression;
14201420
export type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression;
14211421

1422-
export interface PropertyAccessExpression extends MemberExpression, RealDeclaration {
1422+
export interface PropertyAccessExpression extends MemberExpression, NamedDeclaration {
14231423
kind: SyntaxKind.PropertyAccessExpression;
14241424
expression: LeftHandSideExpression;
14251425
name: Identifier;
@@ -1451,7 +1451,7 @@ namespace ts {
14511451
| SuperElementAccessExpression
14521452
;
14531453

1454-
export interface CallExpression extends LeftHandSideExpression, RealDeclaration {
1454+
export interface CallExpression extends LeftHandSideExpression, NamedDeclaration {
14551455
kind: SyntaxKind.CallExpression;
14561456
expression: LeftHandSideExpression;
14571457
typeArguments?: NodeArray<TypeNode>;
@@ -1470,7 +1470,7 @@ namespace ts {
14701470
typeArguments?: NodeArray<TypeNode>;
14711471
}
14721472

1473-
export interface NewExpression extends PrimaryExpression, RealDeclaration {
1473+
export interface NewExpression extends PrimaryExpression, NamedDeclaration {
14741474
kind: SyntaxKind.NewExpression;
14751475
expression: LeftHandSideExpression;
14761476
typeArguments?: NodeArray<TypeNode>;
@@ -1764,7 +1764,7 @@ namespace ts {
17641764

17651765
export type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration;
17661766

1767-
export interface ClassLikeDeclaration extends RealDeclaration {
1767+
export interface ClassLikeDeclaration extends NamedDeclaration {
17681768
name?: Identifier;
17691769
typeParameters?: NodeArray<TypeParameterDeclaration>;
17701770
heritageClauses?: NodeArray<HeritageClause>;
@@ -1780,12 +1780,12 @@ namespace ts {
17801780
kind: SyntaxKind.ClassExpression;
17811781
}
17821782

1783-
export interface ClassElement extends RealDeclaration {
1783+
export interface ClassElement extends NamedDeclaration {
17841784
_classElementBrand: any;
17851785
name?: PropertyName;
17861786
}
17871787

1788-
export interface TypeElement extends RealDeclaration {
1788+
export interface TypeElement extends NamedDeclaration {
17891789
_typeElementBrand: any;
17901790
name?: PropertyName;
17911791
questionToken?: QuestionToken;
@@ -1813,7 +1813,7 @@ namespace ts {
18131813
type: TypeNode;
18141814
}
18151815

1816-
export interface EnumMember extends RealDeclaration {
1816+
export interface EnumMember extends NamedDeclaration {
18171817
kind: SyntaxKind.EnumMember;
18181818
parent?: EnumDeclaration;
18191819
// This does include ComputedPropertyName, but the parser will give an error
@@ -1902,14 +1902,14 @@ namespace ts {
19021902
// import d, * as ns from "mod" => name = d, namedBinding: NamespaceImport = { name: ns }
19031903
// import { a, b as x } from "mod" => name = undefined, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]}
19041904
// import d, { a, b as x } from "mod" => name = d, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]}
1905-
export interface ImportClause extends RealDeclaration {
1905+
export interface ImportClause extends NamedDeclaration {
19061906
kind: SyntaxKind.ImportClause;
19071907
parent?: ImportDeclaration;
19081908
name?: Identifier; // Default binding
19091909
namedBindings?: NamedImportBindings;
19101910
}
19111911

1912-
export interface NamespaceImport extends RealDeclaration {
1912+
export interface NamespaceImport extends NamedDeclaration {
19131913
kind: SyntaxKind.NamespaceImport;
19141914
parent?: ImportClause;
19151915
name: Identifier;
@@ -1942,14 +1942,14 @@ namespace ts {
19421942

19431943
export type NamedImportsOrExports = NamedImports | NamedExports;
19441944

1945-
export interface ImportSpecifier extends RealDeclaration {
1945+
export interface ImportSpecifier extends NamedDeclaration {
19461946
kind: SyntaxKind.ImportSpecifier;
19471947
parent?: NamedImports;
19481948
propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent)
19491949
name: Identifier; // Declared name
19501950
}
19511951

1952-
export interface ExportSpecifier extends RealDeclaration {
1952+
export interface ExportSpecifier extends NamedDeclaration {
19531953
kind: SyntaxKind.ExportSpecifier;
19541954
parent?: NamedExports;
19551955
propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent)
@@ -2115,7 +2115,7 @@ namespace ts {
21152115
typeExpression: JSDocTypeExpression;
21162116
}
21172117

2118-
export interface JSDocTypedefTag extends JSDocTag, RealDeclaration {
2118+
export interface JSDocTypedefTag extends JSDocTag, NamedDeclaration {
21192119
kind: SyntaxKind.JSDocTypedefTag;
21202120
fullName?: JSDocNamespaceDeclaration | Identifier;
21212121
name?: Identifier;
@@ -2249,7 +2249,7 @@ namespace ts {
22492249

22502250

22512251
// Source files are declarations when they are external modules.
2252-
export interface SourceFile extends RealDeclaration {
2252+
export interface SourceFile extends NamedDeclaration {
22532253
kind: SyntaxKind.SourceFile;
22542254
statements: NodeArray<Statement>;
22552255
endOfFileToken: Token<SyntaxKind.EndOfFileToken>;

src/compiler/utilities.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ namespace ts {
566566
case SyntaxKind.GetAccessor:
567567
case SyntaxKind.SetAccessor:
568568
case SyntaxKind.TypeAliasDeclaration:
569-
errorNode = (<RealDeclaration>node).name;
569+
errorNode = (<NamedDeclaration>node).name;
570570
break;
571571
case SyntaxKind.ArrowFunction:
572572
return getErrorSpanForArrowFunction(sourceFile, <ArrowFunction>node);
@@ -1802,7 +1802,7 @@ namespace ts {
18021802
}
18031803
}
18041804
else {
1805-
return declaration.name;
1805+
return (declaration as NamedDeclaration).name;
18061806
}
18071807
}
18081808

@@ -1826,7 +1826,7 @@ namespace ts {
18261826
case SyntaxKind.PropertyAssignment:
18271827
case SyntaxKind.PropertyAccessExpression:
18281828
// Name in member declaration or property name in property access
1829-
return (<RealDeclaration | PropertyAccessExpression>parent).name === node;
1829+
return (<NamedDeclaration | PropertyAccessExpression>parent).name === node;
18301830
case SyntaxKind.QualifiedName:
18311831
// Name on right hand side of dot in a type query
18321832
if ((<QualifiedName>parent).right === node) {
@@ -2790,7 +2790,7 @@ namespace ts {
27902790
forEach(declarations, (member: Declaration) => {
27912791
if ((member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor)
27922792
&& hasModifier(member, ModifierFlags.Static) === hasModifier(accessor, ModifierFlags.Static)) {
2793-
const memberName = getPropertyNameForPropertyNameNode(member.name);
2793+
const memberName = getPropertyNameForPropertyNameNode((member as NamedDeclaration).name);
27942794
const accessorName = getPropertyNameForPropertyNameNode(accessor.name);
27952795
if (memberName === accessorName) {
27962796
if (!firstAccessor) {
@@ -4102,7 +4102,7 @@ namespace ts {
41024102
|| kind === SyntaxKind.MergeDeclarationMarker;
41034103
}
41044104

4105-
export function isDeclaration(node: Node): node is RealDeclaration {
4105+
export function isDeclaration(node: Node): node is NamedDeclaration {
41064106
return isDeclarationKind(node.kind);
41074107
}
41084108

src/services/completions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ namespace ts.Completions {
12141214
// TODO(jfreeman): Account for computed property name
12151215
// NOTE: if one only performs this step when m.name is an identifier,
12161216
// things like '__proto__' are not filtered out.
1217-
existingName = (<Identifier>m.name).text;
1217+
existingName = (getNameOfDeclaration(m) as Identifier).text;
12181218
}
12191219

12201220
existingMemberNames.set(existingName, true);

src/services/navigateTo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace ts.NavigateTo {
5252
rawItems = filter(rawItems, item => {
5353
const decl = item.declaration;
5454
if (decl.kind === SyntaxKind.ImportClause || decl.kind === SyntaxKind.ImportSpecifier || decl.kind === SyntaxKind.ImportEqualsDeclaration) {
55-
const importer = checker.getSymbolAtLocation(decl.name);
55+
const importer = checker.getSymbolAtLocation((decl as NamedDeclaration).name);
5656
const imported = checker.getAliasedSymbol(importer);
5757
return importer.name !== imported.name;
5858
}

0 commit comments

Comments
 (0)