forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
1844 lines (1593 loc) · 72.4 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module ts {
export interface Map<T> {
[index: string]: T;
}
export interface TextRange {
pos: number;
end: number;
}
// token > SyntaxKind.Identifer => token is a keyword
export const enum SyntaxKind {
Unknown,
EndOfFileToken,
SingleLineCommentTrivia,
MultiLineCommentTrivia,
NewLineTrivia,
WhitespaceTrivia,
// We detect and provide better error recovery when we encounter a git merge marker. This
// allows us to edit files with git-conflict markers in them in a much more pleasant manner.
ConflictMarkerTrivia,
// Literals
NumericLiteral,
StringLiteral,
RegularExpressionLiteral,
NoSubstitutionTemplateLiteral,
// Pseudo-literals
TemplateHead,
TemplateMiddle,
TemplateTail,
// Punctuation
OpenBraceToken,
CloseBraceToken,
OpenParenToken,
CloseParenToken,
OpenBracketToken,
CloseBracketToken,
DotToken,
DotDotDotToken,
SemicolonToken,
CommaToken,
LessThanToken,
GreaterThanToken,
LessThanEqualsToken,
GreaterThanEqualsToken,
EqualsEqualsToken,
ExclamationEqualsToken,
EqualsEqualsEqualsToken,
ExclamationEqualsEqualsToken,
EqualsGreaterThanToken,
PlusToken,
MinusToken,
AsteriskToken,
SlashToken,
PercentToken,
PlusPlusToken,
MinusMinusToken,
LessThanLessThanToken,
GreaterThanGreaterThanToken,
GreaterThanGreaterThanGreaterThanToken,
AmpersandToken,
BarToken,
CaretToken,
ExclamationToken,
TildeToken,
AmpersandAmpersandToken,
BarBarToken,
QuestionToken,
ColonToken,
AtToken,
// Assignments
EqualsToken,
PlusEqualsToken,
MinusEqualsToken,
AsteriskEqualsToken,
SlashEqualsToken,
PercentEqualsToken,
LessThanLessThanEqualsToken,
GreaterThanGreaterThanEqualsToken,
GreaterThanGreaterThanGreaterThanEqualsToken,
AmpersandEqualsToken,
BarEqualsToken,
CaretEqualsToken,
// Identifiers
Identifier,
// Reserved words
BreakKeyword,
CaseKeyword,
CatchKeyword,
ClassKeyword,
ConstKeyword,
ContinueKeyword,
DebuggerKeyword,
DefaultKeyword,
DeleteKeyword,
DoKeyword,
ElseKeyword,
EnumKeyword,
ExportKeyword,
ExtendsKeyword,
FalseKeyword,
FinallyKeyword,
ForKeyword,
FunctionKeyword,
IfKeyword,
ImportKeyword,
InKeyword,
InstanceOfKeyword,
NewKeyword,
NullKeyword,
ReturnKeyword,
SuperKeyword,
SwitchKeyword,
ThisKeyword,
ThrowKeyword,
TrueKeyword,
TryKeyword,
TypeOfKeyword,
VarKeyword,
VoidKeyword,
WhileKeyword,
WithKeyword,
// Strict mode reserved words
AsKeyword,
ImplementsKeyword,
InterfaceKeyword,
LetKeyword,
PackageKeyword,
PrivateKeyword,
ProtectedKeyword,
PublicKeyword,
StaticKeyword,
YieldKeyword,
// Contextual keywords
AnyKeyword,
BooleanKeyword,
ConstructorKeyword,
DeclareKeyword,
GetKeyword,
ModuleKeyword,
RequireKeyword,
NumberKeyword,
SetKeyword,
StringKeyword,
SymbolKeyword,
TypeKeyword,
FromKeyword,
OfKeyword, // LastKeyword and LastToken
// Parse tree nodes
// Names
QualifiedName,
ComputedPropertyName,
// Signature elements
TypeParameter,
Parameter,
Decorator,
// TypeMember
PropertySignature,
PropertyDeclaration,
MethodSignature,
MethodDeclaration,
Constructor,
GetAccessor,
SetAccessor,
CallSignature,
ConstructSignature,
IndexSignature,
// Type
TypeReference,
FunctionType,
ConstructorType,
TypeQuery,
TypeLiteral,
ArrayType,
TupleType,
UnionType,
ParenthesizedType,
// Binding patterns
ObjectBindingPattern,
ArrayBindingPattern,
BindingElement,
// Expression
ArrayLiteralExpression,
ObjectLiteralExpression,
PropertyAccessExpression,
ElementAccessExpression,
CallExpression,
NewExpression,
TaggedTemplateExpression,
TypeAssertionExpression,
ParenthesizedExpression,
FunctionExpression,
ArrowFunction,
DeleteExpression,
TypeOfExpression,
VoidExpression,
PrefixUnaryExpression,
PostfixUnaryExpression,
BinaryExpression,
ConditionalExpression,
TemplateExpression,
YieldExpression,
SpreadElementExpression,
ClassExpression,
OmittedExpression,
// Misc
TemplateSpan,
HeritageClauseElement,
SemicolonClassElement,
// Element
Block,
VariableStatement,
EmptyStatement,
ExpressionStatement,
IfStatement,
DoStatement,
WhileStatement,
ForStatement,
ForInStatement,
ForOfStatement,
ContinueStatement,
BreakStatement,
ReturnStatement,
WithStatement,
SwitchStatement,
LabeledStatement,
ThrowStatement,
TryStatement,
DebuggerStatement,
VariableDeclaration,
VariableDeclarationList,
FunctionDeclaration,
ClassDeclaration,
InterfaceDeclaration,
TypeAliasDeclaration,
EnumDeclaration,
ModuleDeclaration,
ModuleBlock,
CaseBlock,
ImportEqualsDeclaration,
ImportDeclaration,
ImportClause,
NamespaceImport,
NamedImports,
ImportSpecifier,
ExportAssignment,
ExportDeclaration,
NamedExports,
ExportSpecifier,
MissingDeclaration,
// Module references
ExternalModuleReference,
// Clauses
CaseClause,
DefaultClause,
HeritageClause,
CatchClause,
// Property assignments
PropertyAssignment,
ShorthandPropertyAssignment,
// Enum
EnumMember,
// Top-level nodes
SourceFile,
// Synthesized list
SyntaxList,
// Enum value count
Count,
// Markers
FirstAssignment = EqualsToken,
LastAssignment = CaretEqualsToken,
FirstReservedWord = BreakKeyword,
LastReservedWord = WithKeyword,
FirstKeyword = BreakKeyword,
LastKeyword = OfKeyword,
FirstFutureReservedWord = ImplementsKeyword,
LastFutureReservedWord = YieldKeyword,
FirstTypeNode = TypeReference,
LastTypeNode = ParenthesizedType,
FirstPunctuation = OpenBraceToken,
LastPunctuation = CaretEqualsToken,
FirstToken = Unknown,
LastToken = LastKeyword,
FirstTriviaToken = SingleLineCommentTrivia,
LastTriviaToken = ConflictMarkerTrivia,
FirstLiteralToken = NumericLiteral,
LastLiteralToken = NoSubstitutionTemplateLiteral,
FirstTemplateToken = NoSubstitutionTemplateLiteral,
LastTemplateToken = TemplateTail,
FirstBinaryOperator = LessThanToken,
LastBinaryOperator = CaretEqualsToken,
FirstNode = QualifiedName,
}
export const enum NodeFlags {
Export = 0x00000001, // Declarations
Ambient = 0x00000002, // Declarations
Public = 0x00000010, // Property/Method
Private = 0x00000020, // Property/Method
Protected = 0x00000040, // Property/Method
Static = 0x00000080, // Property/Method
Default = 0x00000100, // Function/Class (export default declaration)
MultiLine = 0x00000200, // Multi-line array or object literal
Synthetic = 0x00000400, // Synthetic node (for full fidelity)
DeclarationFile = 0x00000800, // Node is a .d.ts file
Let = 0x00001000, // Variable declaration
Const = 0x00002000, // Variable declaration
OctalLiteral = 0x00004000,
ExportContext = 0x00008000, // Export context (initialized by binding)
Modifier = Export | Ambient | Public | Private | Protected | Static | Default,
AccessibilityModifier = Public | Private | Protected,
BlockScoped = Let | Const
}
export const enum ParserContextFlags {
// Set if this node was parsed in strict mode. Used for grammar error checks, as well as
// checking if the node can be reused in incremental settings.
StrictMode = 1 << 0,
// If this node was parsed in a context where 'in-expressions' are not allowed.
DisallowIn = 1 << 1,
// If this node was parsed in the 'yield' context created when parsing a generator.
Yield = 1 << 2,
// If this node was parsed in the parameters of a generator.
GeneratorParameter = 1 << 3,
// If this node was parsed as part of a decorator
Decorator = 1 << 4,
// If the parser encountered an error when parsing the code that created this node. Note
// the parser only sets this directly on the node it creates right after encountering the
// error.
ThisNodeHasError = 1 << 5,
// Context flags set directly by the parser.
ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | Decorator | ThisNodeHasError,
// Context flags computed by aggregating child flags upwards.
// Used during incremental parsing to determine if this node or any of its children had an
// error. Computed only once and then cached.
ThisNodeOrAnySubNodesHasError = 1 << 6,
// Used to know if we've computed data from children and cached it in this node.
HasAggregatedChildData = 1 << 7
}
export const enum RelationComparisonResult {
Succeeded = 1, // Should be truthy
Failed = 2,
FailedAndReported = 3
}
export interface Node extends TextRange {
kind: SyntaxKind;
flags: NodeFlags;
// Specific context the parser was in when this node was created. Normally undefined.
// Only set when the parser was in some interesting context (like async/yield).
parserContextFlags?: ParserContextFlags;
decorators?: NodeArray<Decorator>; // Array of decorators (in document order)
modifiers?: ModifiersArray; // Array of modifiers
id?: number; // Unique id (used to look up NodeLinks)
parent?: Node; // Parent node (initialized by binding)
symbol?: Symbol; // Symbol declared by node (initialized by binding)
locals?: SymbolTable; // Locals associated with node (initialized by binding)
nextContainer?: Node; // Next container in declaration order (initialized by binding)
localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes)
}
export interface NodeArray<T> extends Array<T>, TextRange {
hasTrailingComma?: boolean;
}
export interface ModifiersArray extends NodeArray<Node> {
flags: number;
}
export interface Identifier extends PrimaryExpression {
text: string; // Text of identifier (with escapes converted to characters)
}
export interface QualifiedName extends Node {
// Must have same layout as PropertyAccess
left: EntityName;
right: Identifier;
}
export type EntityName = Identifier | QualifiedName;
export type DeclarationName = Identifier | LiteralExpression | ComputedPropertyName | BindingPattern;
export interface Declaration extends Node {
_declarationBrand: any;
name?: DeclarationName;
}
export interface ComputedPropertyName extends Node {
expression: Expression;
}
export interface Decorator extends Node {
expression: LeftHandSideExpression;
}
export interface TypeParameterDeclaration extends Declaration {
name: Identifier;
constraint?: TypeNode;
// For error recovery purposes.
expression?: Expression;
}
export interface SignatureDeclaration extends Declaration {
typeParameters?: NodeArray<TypeParameterDeclaration>;
parameters: NodeArray<ParameterDeclaration>;
type?: TypeNode;
}
// SyntaxKind.VariableDeclaration
export interface VariableDeclaration extends Declaration {
parent?: VariableDeclarationList;
name: Identifier | BindingPattern; // Declared variable name
type?: TypeNode; // Optional type annotation
initializer?: Expression; // Optional initializer
}
export interface VariableDeclarationList extends Node {
declarations: NodeArray<VariableDeclaration>;
}
// SyntaxKind.Parameter
export interface ParameterDeclaration extends Declaration {
dotDotDotToken?: Node; // Present on rest parameter
name: Identifier | BindingPattern; // Declared parameter name
questionToken?: Node; // Present on optional parameter
type?: TypeNode; // Optional type annotation
initializer?: Expression; // Optional initializer
}
// SyntaxKind.BindingElement
export interface BindingElement extends Declaration {
propertyName?: Identifier; // Binding property name (in object binding pattern)
dotDotDotToken?: Node; // Present on rest binding element
name: Identifier | BindingPattern; // Declared binding element name
initializer?: Expression; // Optional initializer
}
// SyntaxKind.Property
export interface PropertyDeclaration extends Declaration, ClassElement {
name: DeclarationName; // Declared property name
questionToken?: Node; // Present on optional property
type?: TypeNode; // Optional type annotation
initializer?: Expression; // Optional initializer
}
export interface ObjectLiteralElement extends Declaration {
_objectLiteralBrandBrand: any;
}
// SyntaxKind.PropertyAssignment
export interface PropertyAssignment extends ObjectLiteralElement {
_propertyAssignmentBrand: any;
name: DeclarationName;
questionToken?: Node;
initializer: Expression;
}
// SyntaxKind.ShorthandPropertyAssignment
export interface ShorthandPropertyAssignment extends ObjectLiteralElement {
name: Identifier;
questionToken?: Node;
}
// SyntaxKind.VariableDeclaration
// SyntaxKind.Parameter
// SyntaxKind.BindingElement
// SyntaxKind.Property
// SyntaxKind.PropertyAssignment
// SyntaxKind.ShorthandPropertyAssignment
// SyntaxKind.EnumMember
export interface VariableLikeDeclaration extends Declaration {
propertyName?: Identifier;
dotDotDotToken?: Node;
name: DeclarationName;
questionToken?: Node;
type?: TypeNode;
initializer?: Expression;
}
export interface BindingPattern extends Node {
elements: NodeArray<BindingElement>;
}
/**
* Several node kinds share function-like features such as a signature,
* a name, and a body. These nodes should extend FunctionLikeDeclaration.
* Examples:
* FunctionDeclaration
* MethodDeclaration
* AccessorDeclaration
*/
export interface FunctionLikeDeclaration extends SignatureDeclaration {
_functionLikeDeclarationBrand: any;
asteriskToken?: Node;
questionToken?: Node;
body?: Block | Expression;
}
export interface FunctionDeclaration extends FunctionLikeDeclaration, Statement {
name?: Identifier;
body?: Block;
}
// Note that a MethodDeclaration is considered both a ClassElement and an ObjectLiteralElement.
// Both the grammars for ClassDeclaration and ObjectLiteralExpression allow for MethodDeclarations
// as child elements, and so a MethodDeclaration satisfies both interfaces. This avoids the
// alternative where we would need separate kinds/types for ClassMethodDeclaration and
// ObjectLiteralMethodDeclaration, which would look identical.
//
// Because of this, it may be necessary to determine what sort of MethodDeclaration you have
// at later stages of the compiler pipeline. In that case, you can either check the parent kind
// of the method, or use helpers like isObjectLiteralMethodDeclaration
export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement {
body?: Block;
}
export interface ConstructorDeclaration extends FunctionLikeDeclaration, ClassElement {
body?: Block;
}
// For when we encounter a semicolon in a class declaration. ES6 allows these as class elements.
export interface SemicolonClassElement extends ClassElement {
_semicolonClassElementBrand: any;
}
// See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a
// ClassElement and an ObjectLiteralElement.
export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement {
_accessorDeclarationBrand: any;
body: Block;
}
export interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement {
_indexSignatureDeclarationBrand: any;
}
export interface TypeNode extends Node {
_typeNodeBrand: any;
}
export interface FunctionOrConstructorTypeNode extends TypeNode, SignatureDeclaration {
_functionOrConstructorTypeNodeBrand: any;
}
export interface TypeReferenceNode extends TypeNode {
typeName: EntityName;
typeArguments?: NodeArray<TypeNode>;
}
export interface TypeQueryNode extends TypeNode {
exprName: EntityName;
}
// A TypeLiteral is the declaration node for an anonymous symbol.
export interface TypeLiteralNode extends TypeNode, Declaration {
members: NodeArray<Node>;
}
export interface ArrayTypeNode extends TypeNode {
elementType: TypeNode;
}
export interface TupleTypeNode extends TypeNode {
elementTypes: NodeArray<TypeNode>;
}
export interface UnionTypeNode extends TypeNode {
types: NodeArray<TypeNode>;
}
export interface ParenthesizedTypeNode extends TypeNode {
type: TypeNode;
}
export interface StringLiteralTypeNode extends LiteralExpression, TypeNode { }
// Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing.
// Consider 'Expression'. Without the brand, 'Expression' is actually no different
// (structurally) than 'Node'. Because of this you can pass any Node to a function that
// takes an Expression without any error. By using the 'brands' we ensure that the type
// checker actually thinks you have something of the right type. Note: the brands are
// never actually given values. At runtime they have zero cost.
export interface Expression extends Node {
_expressionBrand: any;
contextualType?: Type; // Used to temporarily assign a contextual type during overload resolution
}
export interface UnaryExpression extends Expression {
_unaryExpressionBrand: any;
}
export interface PrefixUnaryExpression extends UnaryExpression {
operator: SyntaxKind;
operand: UnaryExpression;
}
export interface PostfixUnaryExpression extends PostfixExpression {
operand: LeftHandSideExpression;
operator: SyntaxKind;
}
export interface PostfixExpression extends UnaryExpression {
_postfixExpressionBrand: any;
}
export interface LeftHandSideExpression extends PostfixExpression {
_leftHandSideExpressionBrand: any;
}
export interface MemberExpression extends LeftHandSideExpression {
_memberExpressionBrand: any;
}
export interface PrimaryExpression extends MemberExpression {
_primaryExpressionBrand: any;
}
export interface DeleteExpression extends UnaryExpression {
expression: UnaryExpression;
}
export interface TypeOfExpression extends UnaryExpression {
expression: UnaryExpression;
}
export interface VoidExpression extends UnaryExpression {
expression: UnaryExpression;
}
export interface YieldExpression extends Expression {
asteriskToken?: Node;
expression: Expression;
}
export interface BinaryExpression extends Expression {
left: Expression;
operatorToken: Node;
right: Expression;
}
export interface ConditionalExpression extends Expression {
condition: Expression;
questionToken: Node;
whenTrue: Expression;
colonToken: Node;
whenFalse: Expression;
}
export interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclaration {
name?: Identifier;
body: Block | Expression; // Required, whereas the member inherited from FunctionDeclaration is optional
}
export interface ArrowFunction extends Expression, FunctionLikeDeclaration {
equalsGreaterThanToken: Node;
}
// The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral,
// or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters.
// For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1".
export interface LiteralExpression extends PrimaryExpression {
text: string;
isUnterminated?: boolean;
hasExtendedUnicodeEscape?: boolean;
}
export interface StringLiteralExpression extends LiteralExpression {
_stringLiteralExpressionBrand: any;
}
export interface TemplateExpression extends PrimaryExpression {
head: LiteralExpression;
templateSpans: NodeArray<TemplateSpan>;
}
// Each of these corresponds to a substitution expression and a template literal, in that order.
// The template literal must have kind TemplateMiddleLiteral or TemplateTailLiteral.
export interface TemplateSpan extends Node {
expression: Expression;
literal: LiteralExpression;
}
export interface ParenthesizedExpression extends PrimaryExpression {
expression: Expression;
}
export interface ArrayLiteralExpression extends PrimaryExpression {
elements: NodeArray<Expression>;
}
export interface SpreadElementExpression extends Expression {
expression: Expression;
}
// An ObjectLiteralExpression is the declaration node for an anonymous symbol.
export interface ObjectLiteralExpression extends PrimaryExpression, Declaration {
properties: NodeArray<ObjectLiteralElement>;
}
export interface PropertyAccessExpression extends MemberExpression {
expression: LeftHandSideExpression;
dotToken: Node;
name: Identifier;
}
export interface ElementAccessExpression extends MemberExpression {
expression: LeftHandSideExpression;
argumentExpression?: Expression;
}
export interface CallExpression extends LeftHandSideExpression {
expression: LeftHandSideExpression;
typeArguments?: NodeArray<TypeNode>;
arguments: NodeArray<Expression>;
}
export interface HeritageClauseElement extends Node {
expression: LeftHandSideExpression;
typeArguments?: NodeArray<TypeNode>;
}
export interface NewExpression extends CallExpression, PrimaryExpression { }
export interface TaggedTemplateExpression extends MemberExpression {
tag: LeftHandSideExpression;
template: LiteralExpression | TemplateExpression;
}
export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression;
export interface TypeAssertion extends UnaryExpression {
type: TypeNode;
expression: UnaryExpression;
}
export interface Statement extends Node, ModuleElement {
_statementBrand: any;
}
export interface Block extends Statement {
statements: NodeArray<Statement>;
}
export interface VariableStatement extends Statement {
declarationList: VariableDeclarationList;
}
export interface ExpressionStatement extends Statement {
expression: Expression;
}
export interface IfStatement extends Statement {
expression: Expression;
thenStatement: Statement;
elseStatement?: Statement;
}
export interface IterationStatement extends Statement {
statement: Statement;
}
export interface DoStatement extends IterationStatement {
expression: Expression;
}
export interface WhileStatement extends IterationStatement {
expression: Expression;
}
export interface ForStatement extends IterationStatement {
initializer?: VariableDeclarationList | Expression;
condition?: Expression;
iterator?: Expression;
}
export interface ForInStatement extends IterationStatement {
initializer: VariableDeclarationList | Expression;
expression: Expression;
}
export interface ForOfStatement extends IterationStatement {
initializer: VariableDeclarationList | Expression;
expression: Expression;
}
export interface BreakOrContinueStatement extends Statement {
label?: Identifier;
}
export interface ReturnStatement extends Statement {
expression?: Expression;
}
export interface WithStatement extends Statement {
expression: Expression;
statement: Statement;
}
export interface SwitchStatement extends Statement {
expression: Expression;
caseBlock: CaseBlock;
}
export interface CaseBlock extends Node {
clauses: NodeArray<CaseOrDefaultClause>;
}
export interface CaseClause extends Node {
expression?: Expression;
statements: NodeArray<Statement>;
}
export interface DefaultClause extends Node {
statements: NodeArray<Statement>;
}
export type CaseOrDefaultClause = CaseClause | DefaultClause;
export interface LabeledStatement extends Statement {
label: Identifier;
statement: Statement;
}
export interface ThrowStatement extends Statement {
expression: Expression;
}
export interface TryStatement extends Statement {
tryBlock: Block;
catchClause?: CatchClause;
finallyBlock?: Block;
}
export interface CatchClause extends Node {
variableDeclaration: VariableDeclaration;
block: Block;
}
export interface ModuleElement extends Node {
_moduleElementBrand: any;
}
export interface ClassLikeDeclaration extends Declaration {
name?: Identifier;
typeParameters?: NodeArray<TypeParameterDeclaration>;
heritageClauses?: NodeArray<HeritageClause>;
members: NodeArray<ClassElement>;
}
export interface ClassDeclaration extends ClassLikeDeclaration, Statement {
}
export interface ClassExpression extends ClassLikeDeclaration, PrimaryExpression {
}
export interface ClassElement extends Declaration {
_classElementBrand: any;
}
export interface InterfaceDeclaration extends Declaration, ModuleElement {
name: Identifier;
typeParameters?: NodeArray<TypeParameterDeclaration>;
heritageClauses?: NodeArray<HeritageClause>;
members: NodeArray<Declaration>;
}
export interface HeritageClause extends Node {
token: SyntaxKind;
types?: NodeArray<HeritageClauseElement>;
}
export interface TypeAliasDeclaration extends Declaration, ModuleElement {
name: Identifier;
type: TypeNode;
}
export interface EnumMember extends Declaration {
// This does include ComputedPropertyName, but the parser will give an error
// if it parses a ComputedPropertyName in an EnumMember
name: DeclarationName;
initializer?: Expression;
}
export interface EnumDeclaration extends Declaration, ModuleElement {
name: Identifier;
members: NodeArray<EnumMember>;
}
export interface ModuleDeclaration extends Declaration, ModuleElement {
name: Identifier | LiteralExpression;
body: ModuleBlock | ModuleDeclaration;
}
export interface ModuleBlock extends Node, ModuleElement {
statements: NodeArray<ModuleElement>
}
export interface ImportEqualsDeclaration extends Declaration, ModuleElement {
name: Identifier;
// 'EntityName' for an internal module reference, 'ExternalModuleReference' for an external
// module reference.
moduleReference: EntityName | ExternalModuleReference;
}
export interface ExternalModuleReference extends Node {
expression?: Expression;
}
// In case of:
// import "mod" => importClause = undefined, moduleSpecifier = "mod"
// In rest of the cases, module specifier is string literal corresponding to module
// ImportClause information is shown at its declaration below.
export interface ImportDeclaration extends ModuleElement {
importClause?: ImportClause;
moduleSpecifier: Expression;
}
// In case of:
// import d from "mod" => name = d, namedBinding = undefined
// import * as ns from "mod" => name = undefined, namedBinding: NamespaceImport = { name: ns }
// import d, * as ns from "mod" => name = d, namedBinding: NamespaceImport = { name: ns }
// import { a, b as x } from "mod" => name = undefined, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]}
// import d, { a, b as x } from "mod" => name = d, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]}
export interface ImportClause extends Declaration {
name?: Identifier; // Default binding
namedBindings?: NamespaceImport | NamedImports;
}
export interface NamespaceImport extends Declaration {
name: Identifier;
}
export interface ExportDeclaration extends Declaration, ModuleElement {
exportClause?: NamedExports;
moduleSpecifier?: Expression;
}
export interface NamedImportsOrExports extends Node {
elements: NodeArray<ImportOrExportSpecifier>;
}
export type NamedImports = NamedImportsOrExports;
export type NamedExports = NamedImportsOrExports;
export interface ImportOrExportSpecifier extends Declaration {
propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent)
name: Identifier; // Declared name
}
export type ImportSpecifier = ImportOrExportSpecifier;
export type ExportSpecifier = ImportOrExportSpecifier;
export interface ExportAssignment extends Declaration, ModuleElement {
isExportEquals?: boolean;
expression?: Expression;
type?: TypeNode;
}
export interface FileReference extends TextRange {
fileName: string;
}
export interface CommentRange extends TextRange {
hasTrailingNewLine?: boolean;
}
// Source files are declarations when they are external modules.
export interface SourceFile extends Declaration {
statements: NodeArray<ModuleElement>;
endOfFileToken: Node;
fileName: string;
text: string;
amdDependencies: {path: string; name: string}[];
amdModuleName: string;
referencedFiles: FileReference[];