-
Notifications
You must be signed in to change notification settings - Fork 72
/
types.d.ts
1447 lines (1447 loc) · 31.9 KB
/
types.d.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
declare module "php-parser" {
/**
* Defines an array structure
* @example
* // PHP code :
* [1, 'foo' => 'bar', 3]
*
* // AST structure :
* {
* "kind": "array",
* "shortForm": true
* "items": [
* {"kind": "number", "value": "1"},
* {
* "kind": "entry",
* "key": {"kind": "string", "value": "foo", "isDoubleQuote": false},
* "value": {"kind": "string", "value": "bar", "isDoubleQuote": false}
* },
* {"kind": "number", "value": "3"}
* ]
* }
* @property items - List of array items
* @property shortForm - Indicate if the short array syntax is used, ex `[]` instead `array()`
*/
class Array extends Expression {
/**
* List of array items
*/
items: (Entry | Expression | Variable)[];
/**
* Indicate if the short array syntax is used, ex `[]` instead `array()`
*/
shortForm: boolean;
}
/**
* Defines an arrow function (it's like a closure)
*/
class ArrowFunc extends Expression {
arguments: Parameter[];
type: Identifier;
body: Expression;
byref: boolean;
nullable: boolean;
isStatic: boolean;
}
/**
* Assigns a value to the specified target
*/
class Assign extends Expression {
left: Expression;
right: Expression;
operator: string;
}
/**
* Assigns a value to the specified target
*/
class AssignRef extends Expression {
left: Expression;
right: Expression;
operator: string;
}
/**
* Attribute group
*/
class AttrGroup extends Node {
attrs: Attribute[];
}
/**
* Attribute Value
*/
class Attribute extends Node {
name: string;
args: Parameter[];
}
/**
* Binary operations
*/
class Bin extends Operation {
type: string;
left: Expression;
right: Expression;
}
/**
* A block statement, i.e., a sequence of statements surrounded by braces.
*/
class Block extends Statement {
children: Node[];
}
/**
* Defines a boolean value (true/false)
*/
class Boolean extends Literal {
value: boolean;
}
/**
* A break statement
*/
class Break extends Statement {
level: number | null;
}
/**
* Passing by Reference - so the function can modify the variable
*/
class ByRef extends Expression {
what: ExpressionStatement;
}
/**
* Executes a call statement
*/
class Call extends Expression {
what: Identifier | Variable;
arguments: Expression[];
}
/**
* A switch case statement
* @property test - if null, means that the default case
*/
class Case extends Statement {
/**
* if null, means that the default case
*/
test: Expression | null;
body: Block | null;
}
/**
* Binary operations
*/
class Cast extends Operation {
type: string;
raw: string;
expr: Expression;
}
/**
* Defines a catch statement
*/
class Catch extends Statement {
what: Name[];
variable: Variable;
body: Block;
}
/**
* A class definition
*/
class Class extends Declaration {
extends: Identifier | null;
implements: Identifier[] | null;
body: Declaration[];
isAnonymous: boolean;
isAbstract: boolean;
isFinal: boolean;
isReadonly: boolean;
attrGroups: AttrGroup[];
}
/**
* Defines a class/interface/trait constant
*/
class ClassConstant extends ConstantStatement {
/**
* Generic flags parser
*/
parseFlags(flags: (number | null)[]): void;
visibility: string;
final: boolean;
nullable: boolean;
type: TypeReference | IntersectionType | UnionType | null;
attrGroups: AttrGroup[];
}
/**
* Defines a clone call
*/
class Clone extends Expression {
what: Expression;
}
/**
* Defines a closure
*/
class Closure extends Expression {
arguments: Parameter[];
uses: Variable[];
type: Identifier;
byref: boolean;
nullable: boolean;
body: Block | null;
isStatic: boolean;
attrGroups: AttrGroup[];
}
/**
* Abstract documentation node (ComentLine or CommentBlock)
*/
class Comment extends Node {
value: string;
}
/**
* A comment block (multiline)
*/
class CommentBlock extends Comment {}
/**
* A single line comment
*/
class CommentLine extends Comment {}
/**
* Defines a constant
*/
class Constant extends Node {
name: string;
value: Node | string | number | boolean | null;
}
/**
* Declares a constants into the current scope
*/
class ConstantStatement extends Statement {
constants: Constant[];
}
/**
* A continue statement
*/
class Continue extends Statement {
level: number | null;
}
/**
* A declaration statement (function, class, interface...)
*/
class Declaration extends Statement {
/**
* Generic flags parser
*/
parseFlags(flags: (number | null)[]): void;
name: Identifier | string;
}
/**
* The declare construct is used to set execution directives for a block of code
*/
class Declare extends Block {
/**
* The node is declared as a short tag syntax :
* ```php
* <?php
* declare(ticks=1):
* // some statements
* enddeclare;
* ```
*/
readonly MODE_SHORT: string;
/**
* The node is declared bracket enclosed code :
* ```php
* <?php
* declare(ticks=1) {
* // some statements
* }
* ```
*/
readonly MODE_BLOCK: string;
/**
* The node is declared as a simple statement. In order to make things simpler
* children of the node are automatically collected until the next
* declare statement.
* ```php
* <?php
* declare(ticks=1);
* // some statements
* declare(ticks=2);
* // some statements
* ```
*/
readonly MODE_NONE: string;
directives: DeclareDirective[];
mode: string;
}
/**
* Defines a constant
*/
class DeclareDirective extends Node {
key: Identifier;
value: Node | string | number | boolean | null;
}
/**
* Defines a do/while statement
*/
class Do extends Statement {
test: Expression;
body: Block | null;
}
/**
* Defines system based call
*/
class Echo extends Statement {
shortForm: boolean;
expressions: Expression[];
}
/**
* Defines an empty check call
*/
class Empty extends Expression {}
/**
* Defines an encapsed string (contains expressions)
* @property type - Defines the type of encapsed string (shell, heredoc, string)
* @property label - The heredoc label, defined only when the type is heredoc
*/
class Encapsed extends Literal {
/**
* The node is a double quote string :
* ```php
* <?php
* echo "hello $world";
* ```
*/
readonly TYPE_STRING: string;
/**
* The node is a shell execute string :
* ```php
* <?php
* echo `ls -larth $path`;
* ```
*/
readonly TYPE_SHELL: string;
/**
* The node is a shell execute string :
* ```php
* <?php
* echo <<<STR
* Hello $world
* STR
* ;
* ```
*/
readonly TYPE_HEREDOC: string;
/**
* The node contains a list of constref / variables / expr :
* ```php
* <?php
* echo $foo->bar_$baz;
* ```
*/
readonly TYPE_OFFSET: string;
/**
* Defines the type of encapsed string (shell, heredoc, string)
*/
type: string;
/**
* The heredoc label, defined only when the type is heredoc
*/
label: string | null;
value: EncapsedPart[];
}
/**
* Part of `Encapsed` node
*/
class EncapsedPart extends Expression {
expression: Expression;
syntax: string;
curly: boolean;
}
/**
* An array entry - see [Array](#array)
* @property key - The entry key/offset
* @property value - The entry value
* @property byRef - By reference
* @property unpack - Argument unpacking
*/
class Entry extends Expression {
/**
* The entry key/offset
*/
key: Node | null;
/**
* The entry value
*/
value: Node;
/**
* By reference
*/
byRef: boolean;
/**
* Argument unpacking
*/
unpack: boolean;
}
/**
* A enum definition
*/
class Enum extends Declaration {
valueType: Identifier | null;
implements: Identifier[];
body: Declaration[];
attrGroups: AttrGroup[];
}
/**
* Declares a cases into the current scope
*/
class EnumCase extends Node {
name: string;
value: string | number | null;
}
/**
* Defines an error node (used only on silentMode)
*/
class Error extends Node {
message: string;
line: number;
token: number | string;
expected: string | any[];
}
/**
* Defines an eval statement
*/
class Eval extends Expression {
source: Node;
}
/**
* Defines an exit / die call
*/
class Exit extends Expression {
expression: Node | null;
useDie: boolean;
}
/**
* Any expression node. Since the left-hand side of an assignment may
* be any expression in general, an expression can also be a pattern.
*/
class Expression extends Node {}
/**
* Defines an expression based statement
*/
class ExpressionStatement extends Statement {
expression: Expression;
}
/**
* Defines a for iterator
*/
class For extends Statement {
init: Expression[];
test: Expression[];
increment: Expression[];
body: Block | null;
shortForm: boolean;
}
/**
* Defines a foreach iterator
*/
class Foreach extends Statement {
source: Expression;
key: Expression | null;
value: Expression;
body: Block | null;
shortForm: boolean;
}
/**
* Defines a classic function
*/
class Function extends Declaration {
arguments: Parameter[];
type: Identifier;
byref: boolean;
nullable: boolean;
body: Block | null;
attrGroups: AttrGroup[];
}
/**
* Imports a variable from the global scope
*/
class Global extends Statement {
items: Variable[];
}
/**
* Defines goto statement
*/
class Goto extends Statement {
label: string;
}
/**
* Halts the compiler execution
* @property after - String after the halt statement
*/
class Halt extends Statement {
/**
* String after the halt statement
*/
after: string;
}
/**
* Defines an identifier node
*/
class Identifier extends Node {
name: string;
}
/**
* Defines a if statement
*/
class If extends Statement {
test: Expression;
body: Block;
alternate: Block | If | null;
shortForm: boolean;
}
/**
* Defines system include call
*/
class Include extends Expression {
target: Node;
once: boolean;
require: boolean;
}
/**
* Defines inline html output (treated as echo output)
*/
class Inline extends Literal {
value: string;
}
/**
* An interface definition
*/
class Interface extends Declaration {
extends: Identifier[];
body: Declaration[];
attrGroups: AttrGroup[];
}
/**
* A union of types
*/
class IntersectionType extends Declaration {
types: TypeReference[];
}
/**
* Defines an isset call
*/
class Isset extends Expression {}
/**
* A label statement (referenced by goto)
*/
class Label extends Statement {
name: string;
}
/**
* Defines list assignment
*/
class List extends Expression {
shortForm: boolean;
items: Entry[];
}
/**
* Defines an array structure
*/
class Literal extends Expression {
raw: string;
value: EncapsedPart[] | Node | string | number | boolean | null;
}
/**
* Defines the location of the node (with it's source contents as string)
*/
class Location {
source: string | null;
start: Position;
end: Position;
}
/**
* Lookup on an offset in the specified object
*/
class Lookup extends Expression {
what: Expression;
offset: Expression;
}
/**
* Defines magic constant
*/
class Magic extends Literal {}
/**
* Defines a match expression
* @property cond - Condition expression to match against
* @property arms - Arms for comparison
*/
class Match extends Expression {
/**
* Condition expression to match against
*/
cond: Expression;
/**
* Arms for comparison
*/
arms: MatchArm[];
}
/**
* An array entry - see [Array](#array)
* @property conds - The match condition expression list - null indicates default arm
* @property body - The return value expression
*/
class MatchArm extends Expression {
/**
* The match condition expression list - null indicates default arm
*/
conds: Expression[] | null;
/**
* The return value expression
*/
body: Expression;
}
/**
* Defines a class/interface/trait method
*/
class Method extends Function {
isAbstract: boolean;
isFinal: boolean;
isStatic: boolean;
visibility: string;
}
/**
* Defines a class reference node
*/
class Name extends Reference {
/**
* This is an identifier without a namespace separator, such as Foo
*/
readonly UNQUALIFIED_NAME: string;
/**
* This is an identifier with a namespace separator, such as Foo\Bar
*/
readonly QUALIFIED_NAME: string;
/**
* This is an identifier with a namespace separator that begins with
* a namespace separator, such as \Foo\Bar. The namespace \Foo is also
* a fully qualified name.
*/
readonly FULL_QUALIFIED_NAME: string;
/**
* This is an identifier starting with namespace, such as namespace\Foo\Bar.
*/
readonly RELATIVE_NAME: string;
name: string;
resolution: string;
}
/**
* Named arguments.
*/
class namedargument extends Expression {
name: string;
value: Expression;
}
/**
* The main program node
*/
class Namespace extends Block {
name: string;
withBrackets: boolean;
}
/**
* Creates a new instance of the specified class
*/
class New extends Expression {
what: Identifier | Variable | Class;
arguments: Variable[];
}
/**
* A generic AST node
*/
class Node {
/**
* Attach comments to current node
*/
setTrailingComments(docs: any): void;
/**
* Destroying an unused node
*/
destroy(): void;
/**
* Includes current token position of the parser
*/
includeToken(parser: any): void;
/**
* Helper for extending the Node class
*/
static extends(
type: string,
constructor: (...params: any[]) => any,
): (...params: any[]) => any;
loc: Location | null;
leadingComments: CommentBlock[] | Comment[] | null;
trailingComments: CommentBlock[] | Comment[] | null;
kind: string;
}
/**
* Ignore this node, it implies a no operation block, for example :
* [$foo, $bar, /* here a noop node * /]
*/
class Noop extends Node {}
/**
* Defines a nowdoc string
*/
class NowDoc extends Literal {
label: string;
raw: string;
value: string;
}
/**
* Represents the null keyword
*/
class NullKeyword extends Node {}
/**
* Lookup to an object property
*/
class NullSafePropertyLookup extends Lookup {}
/**
* Defines a numeric value
*/
class Number extends Literal {
value: number;
}
/**
* Lookup on an offset in an array
*/
class OffsetLookup extends Lookup {}
/**
* Defines binary operations
*/
class Operation extends Expression {}
type MODIFIER_PUBLIC = 1;
type MODIFIER_PROTECTED = 2;
type MODIFIER_PRIVATE = 4;
/**
* Defines a function parameter
*/
class Parameter extends Declaration {
type: Identifier | null;
value: Node | null;
byref: boolean;
variadic: boolean;
readonly: boolean;
nullable: boolean;
attrGroups: AttrGroup[];
flags: MODIFIER_PUBLIC | MODIFIER_PROTECTED | MODIFIER_PRIVATE;
}
/**
* Defines a class reference node
*/
class ParentReference extends Reference {}
/**
* Each Position object consists of a line number (1-indexed) and a column number (0-indexed):
*/
class Position {
line: number;
column: number;
offset: number;
}
/**
* Defines a post operation `$i++` or `$i--`
*/
class Post extends Operation {
type: string;
what: Variable;
}
/**
* Defines a pre operation `++$i` or `--$i`
*/
class Pre extends Operation {
type: string;
what: Variable;
}
/**
* Outputs
*/
class Print extends Expression {}
/**
* The main program node
*/
class Program extends Block {
errors: Error[];
comments: Comment[] | null;
tokens: String[] | null;
}
/**
* Defines a class property
*/
class Property extends Statement {
name: string;
value: Node | null;
readonly: boolean;
nullable: boolean;
type: Identifier | Identifier[] | null;
attrGroups: AttrGroup[];
}
/**
* Lookup to an object property
*/
class PropertyLookup extends Lookup {}
/**
* Declares a properties into the current scope
*/
class PropertyStatement extends Statement {
/**
* Generic flags parser
*/
parseFlags(flags: (number | null)[]): void;
properties: Property[];
visibility: string | null;
isStatic: boolean;
}
/**
* Defines a reference node
*/
class Reference extends Node {}
/**
* Defines a short if statement that returns a value
*/
class RetIf extends Expression {
test: Expression;
trueExpr: Expression;
falseExpr: Expression;
}
/**
* A continue statement
*/
class Return extends Statement {
expr: Expression | null;
}
/**
* Defines a class reference node
*/
class SelfReference extends Reference {}
/**
* Avoids to show/log warnings & notices from the inner expression
*/
class Silent extends Expression {
expr: Expression;
}
/**
* Any statement.
*/
class Statement extends Node {}
/**
* Declares a static variable into the current scope
*/
class Static extends Statement {
variables: StaticVariable[];
}
/**
* Lookup to a static property
*/
class StaticLookup extends Lookup {}
/**
* Defines a class reference node
*/
class StaticReference extends Reference {}
/**
* Defines a constant
*/
class StaticVariable extends Node {
variable: Variable;
defaultValue: Node | string | number | boolean | null;
}
/**
* Defines a string (simple or double quoted) - chars are already escaped
*/
class String extends Literal {
unicode: boolean;
isDoubleQuote: boolean;
value: string;
}
/**
* Defines a switch statement
*/
class Switch extends Statement {
test: Expression;
body: Block;
shortForm: boolean;
}
/**
* Defines a throw statement
*/
class Throw extends Statement {
what: Expression;
}
/**
* A trait definition
*/
class Trait extends Declaration {
body: Declaration[];
}
/**
* Defines a trait alias
*/
class TraitAlias extends Node {
trait: Identifier | null;
method: Identifier;
as: Identifier | null;
visibility: string | null;
}
/**
* Defines a trait alias
*/
class TraitPrecedence extends Node {
trait: Identifier | null;
method: Identifier;
instead: Identifier[];
}
/**
* Defines a trait usage
*/
class TraitUse extends Node {
traits: Identifier[];
adaptations: Node[] | null;
}
/**
* Defines a try statement
*/
class Try extends Statement {
body: Block;
catches: Catch[];
always: Block;
}
/**
* Defines a class reference node
*/
class TypeReference extends Reference {
name: string;
}
/**
* Unary operations
*/
class Unary extends Operation {
type: string;
what: Expression;
}
/**
* A union of types
*/
class UnionType extends Declaration {
types: TypeReference[];
}
/**
* Deletes references to a list of variables
*/
class Unset extends Statement {}
/**
* Defines a use statement (with a list of use items)
* @property type - Possible value : function, const
*/
class UseGroup extends Statement {
name: string | null;
/**
* Possible value : function, const
*/
type: string | null;
item: UseItem[];
}
/**
* Defines a use statement (from namespace)
* @property type - Possible value : function, const
*/
class UseItem extends Statement {
/**
* Importing a constant
*/
readonly TYPE_CONST: string;
/**
* Importing a function
*/
readonly TYPE_FUNC: string;
name: string;
/**
* Possible value : function, const
*/
type: string | null;
alias: Identifier | null;
}
/**
* Any expression node. Since the left-hand side of an assignment may
* be any expression in general, an expression can also be a pattern.
* @example
* // PHP code :
* $foo
* // AST output
* {
* "kind": "variable",
* "name": "foo",
* "curly": false
* }
* @property name - The variable name (can be a complex expression when the name is resolved dynamically)
* @property curly - Indicate if the name is defined between curlies, ex `${foo}`
*/
class Variable extends Expression {
/**
* The variable name (can be a complex expression when the name is resolved dynamically)
*/
name: string | Node;
/**
* Indicate if the name is defined between curlies, ex `${foo}`
*/
curly: boolean;
}
/**
* Introduce a list of items into the arguments of the call
*/
class Variadic extends Expression {
what: any[] | Expression;
}
/**
* Defines a variadic placeholder (the ellipsis in PHP 8.1+'s first-class callable syntax)
*/
class VariadicPlaceholder extends Node {}
/**
* Defines a while statement