Skip to content

Commit 22f353a

Browse files
committed
Turn ClassElement and TypeElement into unions too
Slows down compilation another 3%, so I'm not sure we'll want to take this change.
1 parent 6a17532 commit 22f353a

File tree

1 file changed

+34
-41
lines changed

1 file changed

+34
-41
lines changed

src/compiler/types.ts

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,6 @@ namespace ts {
616616
| CallExpression
617617
| CallSignatureDeclaration
618618
| ClassDeclaration
619-
| ClassElement
620619
| ClassExpression
621620
| ClassLikeDeclaration
622621
| ConstructSignatureDeclaration
@@ -717,13 +716,14 @@ namespace ts {
717716
typeParameters?: NodeArray<TypeParameterDeclaration>;
718717
parameters: NodeArray<ParameterDeclaration>;
719718
type?: TypeNode;
719+
questionToken?: QuestionToken;
720720
}
721721

722-
export interface CallSignatureDeclaration extends SignatureDeclaration, TypeElement {
722+
export interface CallSignatureDeclaration extends SignatureDeclaration {
723723
kind: SyntaxKind.CallSignature;
724724
}
725725

726-
export interface ConstructSignatureDeclaration extends SignatureDeclaration, TypeElement {
726+
export interface ConstructSignatureDeclaration extends SignatureDeclaration {
727727
kind: SyntaxKind.ConstructSignature;
728728
}
729729

@@ -762,15 +762,15 @@ namespace ts {
762762
initializer?: Expression; // Optional initializer
763763
}
764764

765-
export interface PropertySignature extends TypeElement {
765+
export interface PropertySignature extends DeclarationBase {
766766
kind: SyntaxKind.PropertySignature | SyntaxKind.JSDocRecordMember;
767767
name: PropertyName; // Declared property name
768768
questionToken?: QuestionToken; // Present on optional property
769769
type?: TypeNode; // Optional type annotation
770770
initializer?: Expression; // Optional initializer
771771
}
772772

773-
export interface PropertyDeclaration extends ClassElement {
773+
export interface PropertyDeclaration extends DeclarationBase {
774774
kind: SyntaxKind.PropertyDeclaration;
775775
questionToken?: QuestionToken; // Present for use with reporting a grammar error
776776
name: PropertyName;
@@ -876,7 +876,7 @@ namespace ts {
876876
body?: FunctionBody;
877877
}
878878

879-
export interface MethodSignature extends SignatureDeclaration, TypeElement {
879+
export interface MethodSignature extends SignatureDeclaration {
880880
kind: SyntaxKind.MethodSignature;
881881
name: PropertyName;
882882
}
@@ -890,27 +890,28 @@ namespace ts {
890890
// Because of this, it may be necessary to determine what sort of MethodDeclaration you have
891891
// at later stages of the compiler pipeline. In that case, you can either check the parent kind
892892
// of the method, or use helpers like isObjectLiteralMethodDeclaration
893-
export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement {
893+
export interface MethodDeclaration extends FunctionLikeDeclaration, ObjectLiteralElement {
894894
kind: SyntaxKind.MethodDeclaration;
895895
name: PropertyName;
896896
body?: FunctionBody;
897897
}
898898

899-
export interface ConstructorDeclaration extends FunctionLikeDeclaration, ClassElement {
899+
export interface ConstructorDeclaration extends FunctionLikeDeclaration {
900900
kind: SyntaxKind.Constructor;
901901
parent?: ClassDeclaration | ClassExpression;
902902
body?: FunctionBody;
903903
}
904904

905905
/** For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. */
906-
export interface SemicolonClassElement extends ClassElement {
906+
export interface SemicolonClassElement extends DeclarationBase {
907907
kind: SyntaxKind.SemicolonClassElement;
908908
parent?: ClassDeclaration | ClassExpression;
909+
name?: PropertyName;
909910
}
910911

911912
// See the comment on MethodDeclaration for the intuition behind GetAccessorDeclaration being a
912913
// ClassElement and an ObjectLiteralElement.
913-
export interface GetAccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement {
914+
export interface GetAccessorDeclaration extends FunctionLikeDeclaration, ObjectLiteralElement {
914915
kind: SyntaxKind.GetAccessor;
915916
parent?: ClassDeclaration | ClassExpression | ObjectLiteralExpression;
916917
name: PropertyName;
@@ -919,7 +920,7 @@ namespace ts {
919920

920921
// See the comment on MethodDeclaration for the intuition behind SetAccessorDeclaration being a
921922
// ClassElement and an ObjectLiteralElement.
922-
export interface SetAccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement {
923+
export interface SetAccessorDeclaration extends FunctionLikeDeclaration, ObjectLiteralElement {
923924
kind: SyntaxKind.SetAccessor;
924925
parent?: ClassDeclaration | ClassExpression | ObjectLiteralExpression;
925926
name: PropertyName;
@@ -928,7 +929,7 @@ namespace ts {
928929

929930
export type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration;
930931

931-
export interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement, TypeElement {
932+
export interface IndexSignatureDeclaration extends SignatureDeclaration {
932933
kind: SyntaxKind.IndexSignature;
933934
parent?: ClassDeclaration | ClassExpression | InterfaceDeclaration | TypeLiteralNode;
934935
}
@@ -1695,7 +1696,7 @@ namespace ts {
16951696
kind: SyntaxKind.DebuggerStatement;
16961697
}
16971698

1698-
export interface MissingDeclaration extends DeclarationStatement, ClassElement, ObjectLiteralElement, TypeElement {
1699+
export interface MissingDeclaration extends DeclarationStatement, ObjectLiteralElement {
16991700
kind: SyntaxKind.MissingDeclaration;
17001701
name?: Identifier;
17011702
}
@@ -1863,34 +1864,26 @@ namespace ts {
18631864
kind: SyntaxKind.ClassExpression;
18641865
}
18651866

1866-
export interface ClassElement extends DeclarationBase {
1867-
kind:
1868-
| SyntaxKind.PropertyDeclaration
1869-
| SyntaxKind.MethodDeclaration
1870-
| SyntaxKind.Constructor
1871-
| SyntaxKind.SemicolonClassElement
1872-
| SyntaxKind.GetAccessor
1873-
| SyntaxKind.SetAccessor
1874-
| SyntaxKind.IndexSignature
1875-
| SyntaxKind.MissingDeclaration;
1876-
_classElementBrand: any;
1877-
name?: PropertyName;
1878-
}
1867+
export type ClassElement =
1868+
| PropertyDeclaration
1869+
| MethodDeclaration
1870+
| ConstructorDeclaration
1871+
| SemicolonClassElement
1872+
| GetAccessorDeclaration
1873+
| SetAccessorDeclaration
1874+
| IndexSignatureDeclaration
1875+
| MissingDeclaration;
18791876

1880-
export interface TypeElement extends DeclarationBase {
1881-
kind:
1882-
| SyntaxKind.CallSignature
1883-
| SyntaxKind.ConstructSignature
1884-
| SyntaxKind.PropertySignature
1885-
| SyntaxKind.MethodSignature
1886-
| SyntaxKind.IndexSignature
1887-
| SyntaxKind.MissingDeclaration
1888-
| SyntaxKind.JSDocPropertyTag
1889-
| SyntaxKind.JSDocRecordMember;
1890-
_typeElementBrand: any;
1891-
name?: PropertyName;
1892-
questionToken?: QuestionToken;
1893-
}
1877+
export type TypeElement =
1878+
| CallSignatureDeclaration
1879+
| ConstructSignatureDeclaration
1880+
| PropertySignature
1881+
| MethodSignature
1882+
| IndexSignatureDeclaration
1883+
| MissingDeclaration
1884+
| IndexSignatureDeclaration
1885+
| JSDocPropertyTag
1886+
| JSDocRecordMember;
18941887

18951888
export interface InterfaceDeclaration extends DeclarationStatement {
18961889
kind: SyntaxKind.InterfaceDeclaration;
@@ -2224,7 +2217,7 @@ namespace ts {
22242217
jsDocTypeLiteral?: JSDocTypeLiteral;
22252218
}
22262219

2227-
export interface JSDocPropertyTag extends JSDocTag, TypeElement {
2220+
export interface JSDocPropertyTag extends JSDocTag {
22282221
kind: SyntaxKind.JSDocPropertyTag;
22292222
name: Identifier;
22302223
typeExpression: JSDocTypeExpression;

0 commit comments

Comments
 (0)