-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
1943 lines (1718 loc) · 80.6 KB
/
index.js
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
// @flow
/*::
export type BabelFileResult = {
ast?: ?Object,
code?: ?string,
map?: ?Object,
ignored?: ?boolean,
metadata?: ?BabelFileMetadata,
};
export type BabelFileMetadata = {
usedHelpers: Array<string>;
marked: Array<{
type: string,
message: string,
loc: Object,
}>;
modules: BabelFileModulesMetadata,
};
export type BabelFileModulesMetadata = {
imports: Array<Object>,
exports: {
exported: Array<Object>,
specifiers: Array<Object>,
},
};
export type BabelParserOptions = {
sourceFilename?: string;
sourceType?: "module" | "script";
plugins?: Array<string>;
};
export interface BabelPipeline {
lint(code: string, opts?: Object): BabelFileResult,
pretransform(code: string, opts?: Object): BabelFileResult,
transform(code: string, opts?: Object): BabelFileResult,
analyse(code: string, opts?: Object, visitor?: Object): BabelFileMetadata,
transformFromAst(ast: Object, code: string, opts: Object): BabelFileResult,
}
export interface BabelStore extends Map<any, any> {
dynamicData: Object,
setDynamic(key: string, fn: Function): void,
get(key: string): any,
}
export type Plugin = (babel: Babel) => {
manipulateOptions?: Function,
post?: Function,
pre?: Function,
visitor: BabelVisitor,
};
export interface BabelPlugin extends BabelStore {
constructor(plugin: Object, key?: string): Plugin,
initialized: boolean,
raw: Object,
manipulateOptions: ?Function,
post: ?Function,
pre: ?Function,
visitor: BabelVisitor,
take(key: string): any,
chain(target: Object, key: string): Function,
maybeInherit(loc: string): void,
init(loc: string, i: number): void,
normaliseVisitor(visitor: Object): Object,
}
export interface BabelPluginPass extends BabelStore {
constructor(file: BabelFile, plugin: BabelPlugin, options?: Object): BabelPluginPass,
key: string,
plugin: Plugin,
file: BabelFile,
opts: Object,
addHelper(name: string): Object,
addImport(source: string, imported: string, name?: string): Object,
getModuleName(): ?string,
buildCodeFrameError(node: Object, msg: string, error?: Class<Error>): Error,
}
export interface BabelLogger {
constructor(file: BabelFile, filename: string): BabelLogger,
filename: string,
file: BabelFile,
warn(msg: string): void,
error(msg: string, error?: Class<Error>): void,
deprecate(msg: string): void,
verbose(msg: string): void,
debug(msg: string): void,
deopt(node: Object, msg: string): void,
}
export interface BabelOptionManager {
constructor(log?: BabelLogger): BabelOptionManager,
resolvedConfigs: Array<string>,
options: Object,
log?: BabelLogger,
// static memoisePluginContainer(fn: Function, loc?: string, i?: any, alias?: string): BabelPlugin,
// static createBareOptions(): Object,
// static normalisePlugin(plugin: Function | BabelPlugin, loc?: string, i?: any, alias?: string): void,
// static normalisePlugins(loc: string, dirname: string, plugins: Array<string | [string, Object]>): Array<any>,
mergeOptions(opts: { options: Object, extending: Object, alias?: string, loc?: string, dirname?: string }): void,
mergePresets(presets: Array<string | Object>, dirname: string): void,
resolvePresets(presets: Array<string | Object>, dirname: string, onResolve?: Function): Array<any>,
normaliseOptions(): void,
init(opts?: Object): Object,
}
export interface BabelFile extends BabelStore {
constructor(opts: ?Object, pipeline: BabelPipeline): BabelFile,
opts: Object,
parserOpts: BabelParserOptions,
ast: Node,
code: string,
shebang: string,
metadata: BabelFileMetadata,
path: BabelPath,
scope: BabelScope,
hub: BabelHub,
log: BabelLogger,
pipeline: BabelPipeline,
pluginPasses: Array<BabelPluginPass>,
pluginVisitors: Array<Object>,
dynamicImportTypes: Object,
dynamicImportIds: Object,
dynamicImports: Array<Object>,
usedHelpers: Object,
declarations: Object,
getMetadata(): void,
initOptions(opts: Object): Object,
buildPluginsForOptions(opts: Object): void,
getModuleName(): ?string,
resolveModuleSource(source: string): string,
addImport(source: string, imported: string, name?: string): Object,
addHelper(name: string): Object,
addTemplateObject(helperName: string, strings: Array<Object>, raw: Object): Object,
buildCodeFrameError(node: Node, msg: string, error: Class<Error>): Error,
mergeSourceMap(map: Object): void,
parse(code: string): Node,
addAST(ast: Node): void,
transform(): BabelFileResult,
wrap(code: string, callback: Function): BabelFileResult,
addCode(code: string): void,
parseCode(): void,
shouldIgnore(): boolean,
call(key: 'pre' | 'post', pluginPasses: Array<BabelPluginPass>): void,
parseInputSourceMap(code: string): string,
parseShebang(): void,
makeResult(opts: BabelFileResult): BabelFileResult,
generate(): BabelFileResult,
}
export type Babel = {
File: BabelFile,
options: Object,
buildExternalHelpers: Function,
template(code: string): Template,
resolvePlugin: Function,
resolvePreset: Function,
version: string,
util: any,
types: Types,
traverse: Function,
OptionManager: BabelOptionManager,
Pipeline: BabelPipeline,
analyse(code: string, opts?: Object, visitor?: Object): BabelFileMetadata,
transform(code: string, opts?: Object): BabelFileResult,
transformFromAst(ast: Object, code: string, opts: Object): BabelFileResult,
transformFile(filename: string, opts: ?Object, callback: Function): void,
transformFileSync(filename: string, opts: ?Object): string,
};
export interface BabelTraverse {
(parent: Object | Array<Object>, opts?: Object, scope?: BabelScope, state: BabelPluginPass, parentPath: BabelPath): void,
visitors: BabelVisitors,
verify: BabelVisitorVerify,
explode: BabelVisitorExplode,
NodePath: Class<BabelPath>,
Scope: Class<BabelScope>,
Hub: Class<BabelHub>,
cheap(node: Node, enter: (node: Node) => void): void,
node(node: Node, opts: Object, scope: BabelScope, state: BabelPluginPass, parentPath: BabelPath, shipKeys?: Object): void,
clearNode(node: Node, opts: Object): void,
removeProperties(tree: Node, opts: Object): Node,
hasType(tree: Node, scope: BabelScope, type: Object, blacklistTypes: Array<string>): boolean,
clearCache(): void,
copyCache(source: Object, destination: Object): void,
}
export type BabelVisitorMethod = (path: BabelPath, state: BabelPluginPass) => mixed;
export type BabelVisitor = {
[key: string]: { enter?: BabelVisitorMethod, exit?: BabelVisitorMethod } | BabelVisitorMethod,
};
type BabelVisitorVerify = (visitor: BabelVisitor) => void;
type BabelVisitorExplode = (visitor: BabelVisitor) => BabelVisitor;
export type BabelVisitors = {
explode: BabelVisitorExplode,
verify: BabelVisitorVerify,
merge(visitors: Array<BabelVisitor>, states: Array<BabelPluginPass>, wrapper?: ?Function): Object,
};
export interface BabelHub {
constructor(file: BabelFile, options: Object): BabelHub,
file: BabelFile,
options: Object,
}
export interface BabelTraversalContext {
constructor(scope: BabelScope, opts: Object, state: BabelPluginPass, parentPath: BabelPath): BabelTraversalContext,
parentPath: BabelPath,
scope: BabelScope,
state: BabelPluginPass,
opts: Object,
queue: ?Array<BabelPath>,
shouldVisit(node: Node): boolean,
create(node: Node, obj: ?Array<Node>, key: string, listKey: string): BabelPath,
maybeQueue(path: BabelPath, notPriority?: boolean): void,
visitMultipe(container: Array<Node>, parent: Node, listKey: string): boolean,
visitSingle(node: Node, key: string): boolean,
visitQueue(queue: Array<BabelPath>): boolean,
visit(node: Node | Array<Node>, key: string): boolean,
}
export type BabelContainer = Object | Array<Object>;
export interface BabelPath {
constructor(hub: BabelHub, parent: Object): BabelPath,
parent: Object,
hub: BabelHub,
contexts: Array<BabelTraversalContext>,
data: Object,
shouldSkip: boolean,
shouldStop: boolean,
removed: boolean,
state: BabelPluginPass,
opts: ?Object,
skipKeys: ?Object,
parentPath: BabelPath,
context: BabelTraversalContext,
container: ?BabelContainer,
listKey: ?string,
inList: boolean,
parentKey: ?string,
key: ?string,
node: ?Object,
scope: BabelScope,
type: string,
typeAnnotation: ?Object,
// static get(opts: {
// hub: BabelHub,
// parentPath?: BabelPath,
// parent?: Node,
// container?: ?BabelContainer,
// listKey?: string,
// key?: string,
// }): BabelPath,
getScope(scope: BabelScope): BabelScope,
setData(key: string, val: any): any,
getData(key: string, def?: any): any,
buildCodeFrameError(msg: string, error?: Class<Error>): Error,
traverse(visitor: Object, state?: any): void,
mark(type: string, message: string): void,
set(key: string, node: Node): void,
getPathLocation(): string,
debug(buildMessage: Function): void,
findParent(callback: (path: BabelPath) => boolean): BabelPath | null,
find(callback: (path: BabelPath) => boolean): BabelPath | null,
getFunctionParent(): BabelPath,
getStatementParent(): BabelPath,
getEarliestCommonAncestorFrom(paths: Array<BabelPath>): BabelPath,
getDeepestCommonAncestorFrom(paths: Array<BabelPath>, filter?: Function): BabelPath,
getAncestry(): Array<BabelPath>,
isAncestor(maybeDescendant: BabelPath): boolean,
isDescendant(maybeAncestor: BabelPath): boolean,
inType(...types: Array<string>): boolean,
inShadow(key?: string): ?boolean,
getTypeAnnotation(): Node,
isBaseType(baseName: string, soft?: boolean): boolean,
couldBeBaseType(name: string): boolean,
baseTypeStrictlyMatches(right: BabelPath): ?boolean,
isGenericType(genericName: string): boolean,
replaceWithMultiple(node: Array<Node>): void,
replaceWithSourceString(replacement: string): void,
replaceWith(replacement: Node): void,
replaceExpressionWithStatements(nodes: Array<Node>): Node,
replaceInline(nodes: Node | Array<Node>): void,
evaluateTruthy(): ?boolean,
evaluate(): { confident: boolean, value: any },
toComputedKey(): Node,
ensureBlock(): Node,
arrowFunctionToShadowed(): void,
matchesPattern(pattern: string, allowPartial?: boolean): boolean,
isStatic(): boolean,
has(key: string): boolean,
is(key: string): boolean,
isnt(key: string): boolean,
equals(key: string, value: any): boolean,
isNodeType(type: string): boolean,
canHaveVariableDeclarationOrExpression(): boolean,
canSwapBetweenExpressionAndStatement(replacement: Node): boolean,
isCompletionRecord(allowInsideFunction?: boolean): boolean,
isStatementOrBlock(): boolean,
referencesImport(moduleSource: string, importName: string): boolean,
getSource(): string,
willIMaybeExecuteBefore(target: BabelPath): boolean,
resolve(dangerous?: boolean, resolved?: Array<BabelPath>): BabelPath,
call(key: string): boolean,
isBlackListed(): boolean,
visit(): boolean,
skip(): void,
skipKey(key: string): void,
stop(): void,
setScope(): void,
setContext(context: Object): BabelPath,
resync(): void,
popContext(): void,
pushContext(context: Object): void,
setup(parentPath: ?BabelPath, container: ?BabelContainer, listKey: ?string, key: ?string): void,
requeue(pathToQueue?: BabelPath): void,
remove(): void,
insertBefore(nodes: Array<Node>): Array<BabelPath>,
insertAfter(nodes: Array<Node>): Array<BabelPath>,
updateSiblingKeys(fromIndex: number, incrementBy: number): void,
unshiftContainer(listKey: string, nodes: Array<Node>): Array<BabelPath>,
pushContainer(listKey: string, nodes: Array<Node>): void,
hoist(scope?: BabelScope): void,
getStatementParent(): ?BabelPath,
getOpposite(): ?BabelPath,
getCompletionRecord(): Array<BabelPath>,
getSibling(key: string): ?BabelPath,
getPrevSibling(): ?BabelPath,
getNextSibling(): ?BabelPath,
getAllNextSiblings(): Array<BabelPath>,
getAllPrevSiblings(): Array<BabelPath>,
get(key: string, context?: boolean | BabelTraversalContext): any,
getBindingIdentifiers(duplicates?: boolean): { [key: string]: Identifier },
getOuterBindingIdentifiers(duplicates?: boolean): { [key: string]: Identifier },
getBindingIdentifierPaths(duplicates?: boolean, outerOnly?: boolean): { [key: string]: BabelPath },
getOuterBindingIdentifierPaths(duplicates?: boolean): { [key: string]: BabelPath },
shareCommentsWithSiblings(): void,
addComment(type: string, content: string, line?: boolean): void,
addComments(type: string, comments: Array<{ type: string, value: string }>): void,
}
export interface BabelScope {
constructor(path: BabelPath, parentScope?: BabelScope): BabelScope,
uid: number,
parent: ?BabelScope,
hub: BabelHub,
parentBlock: Node,
block: Node,
path: BabelPath,
labels: Map<string, BabelPath>,
// static globals: Array<string>,
// static contextVariables: Array<string>,
traverse(node: Node, opts: Object, state?: Object): void,
generateDeclaredUidIdentifier(name?: string): Node,
generateUidIdentifier(name?: string): Node,
generateUid(name?: string): string,
generateUidIdentifierBasedOnNode(parent: Node, defaultName?: string): Node,
isStatic(node: Node): boolean,
maybeGenerateMemoised(node: Node, dontPush?: boolean): ?Node,
checkBlockScopedCollisions(local: BabelBinding, kind: BabelBindingKind, name: string, id: Node): void,
rename(oldName: string, newName: string, block?: boolean): void,
dump(): void,
toArray(node: Node, i?: number): Node,
hasLabel(name: string): boolean,
getLabel(name: string): BabelPath,
registerLabel(path: BabelPath): void,
registerDeclaration(path: BabelPath): void,
buildUndefinedNode(): Node,
registerConstantViolation(path: BabelPath): void,
registerBinding(kind: string, path: BabelPath, bindingPath?: BabelPath): void,
addGlobal(node: Object): void,
hasUid(name: string): boolean,
hasGlobal(name: string): boolean,
hasReference(name: string): boolean,
isPure(node: Node, constantsOnly?: boolean): boolean,
setData(key: string, val: any): any,
getData(key: string): any,
removeData(key: string): void,
init(): void,
crawl(): void,
push(opts: {
id: Node,
init?: Node,
unique?: boolean,
_blockHoist?: number,
kind: 'var' | 'let'
}): void,
getProgramParent(): BabelScope,
getFunctionParent(): BabelScope,
getBlockParent(): BabelScope,
getAllBindings(): { [key: string]: BabelBinding },
getAllBindingsOfKind(): { [key: string]: BabelBinding },
bindingIdentifierEquals(name: string, node: Node): boolean,
getBinding(name: string): ?BabelBinding,
getOwnBinding(name: string): ?BabelBinding,
getBindingIdentifier(name: string): ?Node,
getOwnBindingIdentifier(name: string): ?Node,
hasOwnBinding(name: string): boolean,
hasBinding(name: string, noGlobals?: boolean): boolean,
parentHasBinding(name: string, noGlobals?: boolean): boolean,
moveBindingTo(name: string, scope: BabelScope): void,
removeOwnBinding(name: string): void,
removeBinding(name: string): void,
}
export type BabelBindingKind = 'let' | 'var' | 'hoisted' | 'module';
type BabelBindingOptions = {
existing?: boolean,
identifier: Node,
scope: BabelScope,
path: BabelPath,
kind: BabelBindingKind,
}
export interface BabelBinding {
constructor(opts: BabelBindingOptions): BabelBinding,
identifier: Node,
scope: BabelScope,
path: BabelPath,
kind: BabelBindingKind,
constantViolations: Array<BabelPath>,
constant: boolean,
referencePaths: Array<BabelPath>,
referenced: boolean,
references: number,
hasDeoptedValue: boolean,
hasValue: boolean,
value: any,
deoptValue(): void,
setValue(value: any): void,
clearValue(): void,
reassign(path: BabelPath): void,
reference(path: BabelPath): void,
dereference(): void,
}
export type Template = (code: string, opts?: Object) => (opts: { [key: string]: Node }) => Node;
export interface Comment {
value: string;
start: number;
end: number;
loc: SourceLocation;
}
export interface CommentBlock extends Comment {
type: "CommentBlock";
}
export interface CommentLine extends Comment {
type: "CommentLine";
}
export interface SourceLocation {
start: {
line: number;
column: number;
};
end: {
line: number;
column: number;
};
}
export interface Node {
+type: string;
leadingComments?: Array<Comment>;
innerComments?: Array<Comment>;
trailingComments?: Array<Comment>;
start: number;
end: number;
loc: SourceLocation;
}
export interface ArrayExpression extends Node {
type: "ArrayExpression";
elements: Array<Expression | SpreadElement>;
}
export interface AssignmentExpression extends Node {
type: "AssignmentExpression";
operator: "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "<<=" | ">>=" | ">>>=" | "|=" | "^=" | "&=";
left: LVal;
right: Expression;
}
export interface BinaryExpression extends Node {
type: "BinaryExpression";
operator: "+" | "-" | "/" | "%" | "*" | "**" | "&" | "|" | ">>" | ">>>" | "<<" | "^" | "==" | "===" | "!=" | "!==" | "in" | "instanceof" | ">" | "<" | ">=" | "<=";
left: Expression;
right: Expression;
}
export interface Directive extends Node {
type: "Directive";
value: DirectiveLiteral;
}
export interface DirectiveLiteral extends Node {
type: "DirectiveLiteral";
value: string;
}
export interface BlockStatement extends Node {
type: "BlockStatement";
directives?: Directive[];
body: Statement[];
}
export interface BreakStatement extends Node {
type: "BreakStatement";
label: Identifier;
}
export interface CallExpression extends Node {
type: "CallExpression";
callee: Expression | Super;
arguments: Array<Expression | SpreadElement>;
}
export interface CatchClause extends Node {
type: "CatchClause";
param: Identifier;
body: BlockStatement;
}
export interface ConditionalExpression extends Node {
type: "ConditionalExpression";
test: Expression;
consequent: Expression;
alternate: Expression;
}
export interface ContinueStatement extends Node {
type: "ContinueStatement";
label: Identifier;
}
export interface DebuggerStatement extends Node {
type: "DebuggerStatement";
}
export interface DoWhileStatement extends Node {
type: "DoWhileStatement";
test: Expression;
body: Statement;
}
export interface EmptyStatement extends Node {
type: "EmptyStatement";
}
export interface ExpressionStatement extends Node {
type: "ExpressionStatement";
expression: Expression;
}
export interface File extends Node {
type: "File";
program: Program;
comments: Comment[];
tokens: any[];
}
export interface ForInStatement extends Node {
type: "ForInStatement";
left: VariableDeclaration | LVal;
right: Expression;
body: Statement;
}
export interface ForStatement extends Node {
type: "ForStatement";
init: VariableDeclaration | Expression;
test: Expression;
update: Expression;
body: Statement;
}
export interface FunctionDeclaration extends Node {
type: "FunctionDeclaration";
id: Identifier;
params: Array<LVal>;
body: BlockStatement;
generator: boolean;
async: boolean;
returnType?: TypeAnnotation;
typeParameters?: TypeParameterDeclaration;
}
export interface FunctionExpression extends Node {
type: "FunctionExpression";
id: Identifier;
params: Array<LVal>;
body: BlockStatement;
generator: boolean;
async: boolean;
returnType?: TypeAnnotation;
typeParameters?: TypeParameterDeclaration;
}
export interface Identifier extends Node {
type: "Identifier";
name: string;
typeAnnotation?: TypeAnnotation;
}
export interface IfStatement extends Node {
type: "IfStatement";
test: Expression;
consequent: Statement;
alternate: Statement;
}
export interface LabeledStatement extends Node {
type: "LabeledStatement";
label: Identifier;
body: Statement;
}
export interface StringLiteral extends Node {
type: "StringLiteral";
value: string;
}
export interface NumericLiteral extends Node {
type: "NumericLiteral";
value: number;
}
export interface NullLiteral extends Node {
type: "NullLiteral";
}
export interface BooleanLiteral extends Node {
type: "BooleanLiteral";
value: boolean;
}
export interface RegExpLiteral extends Node {
type: "RegExpLiteral";
pattern: string;
flags?: string;
}
export interface LogicalExpression extends Node {
type: "LogicalExpression";
operator: "||" | "&&";
left: Expression;
right: Expression;
}
export interface MemberExpression extends Node {
type: "MemberExpression";
object: Expression | Super;
property: Expression;
computed: boolean;
}
export interface NewExpression extends Node {
type: "NewExpression";
callee: Expression | Super;
arguments: Array<Expression | SpreadElement>;
}
export interface Program extends Node {
type: "Program";
sourceType: "script" | "module";
directives?: Directive[];
body: Array<Statement | ModuleDeclaration>;
}
export interface ObjectExpression extends Node {
type: "ObjectExpression";
properties: Array<ObjectProperty | ObjectMethod | SpreadProperty>;
}
export interface ObjectMethod extends Node {
type: "ObjectMethod";
key: Expression;
kind: "get" | "set" | "method";
shorthand: boolean;
computed: boolean;
value: Expression;
decorators?: Decorator[];
id: Identifier;
params: Array<LVal>;
body: BlockStatement;
generator: boolean;
async: boolean;
returnType?: TypeAnnotation;
typeParameters?: TypeParameterDeclaration;
}
export interface ObjectProperty extends Node {
type: "ObjectProperty";
key: Expression;
computed: boolean;
value: Expression;
decorators?: Decorator[];
shorthand: boolean;
}
export interface RestElement extends Node {
type: "RestElement";
argument: LVal;
typeAnnotation?: TypeAnnotation;
}
export interface ReturnStatement extends Node {
type: "ReturnStatement";
argument: Expression;
}
export interface SequenceExpression extends Node {
type: "SequenceExpression";
expressions: Expression[];
}
export interface SwitchCase extends Node {
type: "SwitchCase";
test: Expression;
consequent: Statement[];
}
export interface SwitchStatement extends Node {
type: "SwitchStatement";
discriminant: Expression;
cases: SwitchCase[];
}
export interface ThisExpression extends Node {
type: "ThisExpression";
}
export interface ThrowStatement extends Node {
type: "ThrowStatement";
argument: Expression;
}
export interface TryStatement extends Node {
type: "TryStatement";
block: BlockStatement;
handler: CatchClause;
finalizer: BlockStatement;
}
export interface UnaryExpression extends Node {
type: "UnaryExpression";
operator: "-" | "+" | "!" | "~" | "typeof" | "void" | "delete";
prefix: boolean;
argument: Expression;
}
export interface UpdateExpression extends Node {
type: "UpdateExpression";
operator: "++" | "--";
prefix: boolean;
argument: Expression;
}
export interface VariableDeclaration extends Node {
type: "VariableDeclaration";
declarations: VariableDeclarator[];
kind: "var" | "let" | "const";
}
export interface VariableDeclarator extends Node {
type: "VariableDeclarator";
id: LVal;
init: Expression;
}
export interface WhileStatement extends Node {
type: "WhileStatement";
test: Expression;
body: Statement;
}
export interface WithStatement extends Node {
type: "WithStatement";
object: Expression;
body: BlockStatement | Statement;
}
export interface AssignmentPattern extends Node {
type: "AssignmentPattern";
left: Identifier;
right: Expression;
}
export interface ArrayPattern extends Node {
type: "ArrayPattern";
elements: Array<Expression>;
typeAnnotation?: TypeAnnotation;
}
export interface ArrowFunctionExpression extends Node {
type: "ArrowFunctionExpression";
id: Identifier;
params: Array<LVal>;
body: BlockStatement | Expression;
generator: boolean;
async: boolean;
expression: boolean;
returnType?: TypeAnnotation;
typeParameters?: TypeParameterDeclaration;
}
export interface ClassBody extends Node {
type: "ClassBody";
body: Array<ClassMethod | ClassProperty>;
}
export interface ClassDeclaration extends Node {
type: "ClassDeclaration";
id: Identifier;
superClass: Expression;
body: ClassBody;
decorators?: Decorator[];
implements?: ClassImplements[];
mixins?: any[];
typeParameters?: TypeParameterDeclaration;
superTypeParameters?: TypeParameterInstantiation;
}
export interface ClassExpression extends Node {
type: "ClassExpression";
id: Identifier;
superClass: Expression;
body: ClassBody;
decorators?: Decorator[];
implements?: ClassImplements[];
mixins?: any[];
typeParameters?: TypeParameterDeclaration;
superTypeParameters?: TypeParameterInstantiation;
}
export interface ExportAllDeclaration extends Node {
type: "ExportAllDeclaration";
source: StringLiteral;
}
export interface ExportDefaultDeclaration extends Node {
type: "ExportDefaultDeclaration";
declaration: Declaration | Expression;
}
export interface ExportNamedDeclaration extends Node {
type: "ExportNamedDeclaration";
declaration: Declaration;
specifiers: ExportSpecifier[];
source: StringLiteral;
}
export interface ExportSpecifier extends Node {
type: "ExportSpecifier";
local: Identifier;
imported: Identifier;
exported: Identifier;
}
export interface ForOfStatement extends Node {
type: "ForOfStatement";
left: VariableDeclaration | LVal;
right: Expression;
body: Statement;
}
export interface ImportDeclaration extends Node {
type: "ImportDeclaration";
specifiers: Array<ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier>;
source: StringLiteral;
}
export interface ImportDefaultSpecifier extends Node {
type: "ImportDefaultSpecifier";
local: Identifier;
}
export interface ImportNamespaceSpecifier extends Node {
type: "ImportNamespaceSpecifier";
local: Identifier;
}
export interface ImportSpecifier extends Node {
type: "ImportSpecifier";
local: Identifier;
imported: Identifier;
}
export interface MetaProperty extends Node {
type: "MetaProperty";
meta: Identifier;
property: Identifier;
}
export interface ClassMethod extends Node {
type: "ClassMethod";
key: Expression;
value?: FunctionExpression;
kind: "constructor" | "method" | "get" | "set";
computed: boolean;
// static: boolean;
decorators?: Decorator[];
id: Identifier;
params: Array<LVal>;
body: BlockStatement;
generator: boolean;
async: boolean;
expression: boolean;
returnType?: TypeAnnotation;
typeParameters?: TypeParameterDeclaration;
}
// See: https://github.com/babel/babel/blob/master/doc/ast/spec.md#objectpattern
export interface AssignmentProperty extends Node {
type: "ObjectProperty";
key: Expression;
computed: boolean;
value: Pattern;
decorators?: Decorator[];
shorthand: boolean;
}
export interface ObjectPattern extends Node {
type: "ObjectPattern";
properties: Array<AssignmentProperty | RestProperty>;
typeAnnotation?: TypeAnnotation;
}
export interface SpreadElement extends Node {
type: "SpreadElement";
argument: Expression;
}
export interface Super extends Node {
type: "Super";
}
export interface TaggedTemplateExpression extends Node {
type: "TaggedTemplateExpression";
tag: Expression;
quasi: TemplateLiteral;
}
export interface TemplateElement extends Node {
type: "TemplateElement";
tail: boolean;
value: {
cooked: string;