@jorgsowa/php-parser 3.2.5-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +108 -0
  3. package/dist/@jorgsowa/php-parser.js +11239 -0
  4. package/dist/@jorgsowa/php-parser.min.js +2 -0
  5. package/dist/@jorgsowa/php-parser.min.js.LICENSE.txt +10 -0
  6. package/package.json +86 -0
  7. package/src/ast/array.js +44 -0
  8. package/src/ast/arrowfunc.js +43 -0
  9. package/src/ast/assign.js +28 -0
  10. package/src/ast/assignref.js +27 -0
  11. package/src/ast/attrgroup.js +21 -0
  12. package/src/ast/attribute.js +26 -0
  13. package/src/ast/bin.js +27 -0
  14. package/src/ast/block.js +24 -0
  15. package/src/ast/boolean.js +23 -0
  16. package/src/ast/break.js +21 -0
  17. package/src/ast/byref.js +21 -0
  18. package/src/ast/call.js +26 -0
  19. package/src/ast/case.js +26 -0
  20. package/src/ast/cast.js +28 -0
  21. package/src/ast/catch.js +29 -0
  22. package/src/ast/class.js +36 -0
  23. package/src/ast/classconstant.js +71 -0
  24. package/src/ast/clone.js +21 -0
  25. package/src/ast/closure.js +47 -0
  26. package/src/ast/comment.js +23 -0
  27. package/src/ast/commentblock.js +22 -0
  28. package/src/ast/commentline.js +22 -0
  29. package/src/ast/constant.js +26 -0
  30. package/src/ast/constantstatement.js +24 -0
  31. package/src/ast/continue.js +24 -0
  32. package/src/ast/declaration.js +60 -0
  33. package/src/ast/declare.js +71 -0
  34. package/src/ast/declaredirective.js +26 -0
  35. package/src/ast/do.js +26 -0
  36. package/src/ast/echo.js +26 -0
  37. package/src/ast/empty.js +23 -0
  38. package/src/ast/encapsed.js +75 -0
  39. package/src/ast/encapsedpart.js +28 -0
  40. package/src/ast/entry.js +30 -0
  41. package/src/ast/enum.js +30 -0
  42. package/src/ast/enumcase.js +26 -0
  43. package/src/ast/error.js +30 -0
  44. package/src/ast/eval.js +24 -0
  45. package/src/ast/exit.js +26 -0
  46. package/src/ast/expression.js +20 -0
  47. package/src/ast/expressionstatement.js +24 -0
  48. package/src/ast/for.js +33 -0
  49. package/src/ast/foreach.js +33 -0
  50. package/src/ast/function.js +34 -0
  51. package/src/ast/global.js +24 -0
  52. package/src/ast/goto.js +22 -0
  53. package/src/ast/halt.js +22 -0
  54. package/src/ast/identifier.js +26 -0
  55. package/src/ast/if.js +30 -0
  56. package/src/ast/include.js +28 -0
  57. package/src/ast/inline.js +23 -0
  58. package/src/ast/interface.js +28 -0
  59. package/src/ast/intersectiontype.js +24 -0
  60. package/src/ast/isset.js +23 -0
  61. package/src/ast/label.js +21 -0
  62. package/src/ast/list.js +26 -0
  63. package/src/ast/literal.js +28 -0
  64. package/src/ast/location.js +22 -0
  65. package/src/ast/lookup.js +26 -0
  66. package/src/ast/magic.js +22 -0
  67. package/src/ast/match.js +26 -0
  68. package/src/ast/matcharm.js +26 -0
  69. package/src/ast/method.js +24 -0
  70. package/src/ast/name.js +55 -0
  71. package/src/ast/namedargument.js +27 -0
  72. package/src/ast/namespace.js +26 -0
  73. package/src/ast/new.js +26 -0
  74. package/src/ast/node.js +111 -0
  75. package/src/ast/noop.js +20 -0
  76. package/src/ast/nowdoc.js +26 -0
  77. package/src/ast/nullkeyword.js +20 -0
  78. package/src/ast/nullsafepropertylookup.js +22 -0
  79. package/src/ast/number.js +23 -0
  80. package/src/ast/offsetlookup.js +22 -0
  81. package/src/ast/operation.js +19 -0
  82. package/src/ast/parameter.js +61 -0
  83. package/src/ast/parentreference.js +24 -0
  84. package/src/ast/position.js +22 -0
  85. package/src/ast/post.js +26 -0
  86. package/src/ast/pre.js +26 -0
  87. package/src/ast/print.js +23 -0
  88. package/src/ast/program.js +32 -0
  89. package/src/ast/property.js +46 -0
  90. package/src/ast/propertyhook.js +33 -0
  91. package/src/ast/propertylookup.js +22 -0
  92. package/src/ast/propertystatement.js +59 -0
  93. package/src/ast/reference.js +21 -0
  94. package/src/ast/retif.js +28 -0
  95. package/src/ast/return.js +21 -0
  96. package/src/ast/selfreference.js +24 -0
  97. package/src/ast/silent.js +24 -0
  98. package/src/ast/statement.js +19 -0
  99. package/src/ast/static.js +24 -0
  100. package/src/ast/staticlookup.js +22 -0
  101. package/src/ast/staticreference.js +24 -0
  102. package/src/ast/staticvariable.js +26 -0
  103. package/src/ast/string.js +28 -0
  104. package/src/ast/switch.js +28 -0
  105. package/src/ast/throw.js +21 -0
  106. package/src/ast/trait.js +24 -0
  107. package/src/ast/traitalias.js +44 -0
  108. package/src/ast/traitprecedence.js +28 -0
  109. package/src/ast/traituse.js +26 -0
  110. package/src/ast/try.js +28 -0
  111. package/src/ast/typereference.js +40 -0
  112. package/src/ast/unary.js +26 -0
  113. package/src/ast/uniontype.js +24 -0
  114. package/src/ast/unset.js +23 -0
  115. package/src/ast/usegroup.js +30 -0
  116. package/src/ast/useitem.js +45 -0
  117. package/src/ast/variable.js +36 -0
  118. package/src/ast/variadic.js +25 -0
  119. package/src/ast/variadicplaceholder.js +24 -0
  120. package/src/ast/while.js +28 -0
  121. package/src/ast/yield.js +27 -0
  122. package/src/ast/yieldfrom.js +25 -0
  123. package/src/ast.js +593 -0
  124. package/src/index.js +239 -0
  125. package/src/lexer/attribute.js +85 -0
  126. package/src/lexer/comments.js +63 -0
  127. package/src/lexer/initial.js +64 -0
  128. package/src/lexer/numbers.js +171 -0
  129. package/src/lexer/property.js +96 -0
  130. package/src/lexer/scripting.js +114 -0
  131. package/src/lexer/strings.js +524 -0
  132. package/src/lexer/tokens.js +356 -0
  133. package/src/lexer/utils.js +112 -0
  134. package/src/lexer.js +561 -0
  135. package/src/parser/array.js +113 -0
  136. package/src/parser/class.js +718 -0
  137. package/src/parser/comment.js +52 -0
  138. package/src/parser/enum.js +56 -0
  139. package/src/parser/expr.js +848 -0
  140. package/src/parser/function.js +507 -0
  141. package/src/parser/if.js +94 -0
  142. package/src/parser/loops.js +168 -0
  143. package/src/parser/main.js +21 -0
  144. package/src/parser/namespace.js +231 -0
  145. package/src/parser/scalar.js +492 -0
  146. package/src/parser/statement.js +444 -0
  147. package/src/parser/switch.js +99 -0
  148. package/src/parser/try.js +43 -0
  149. package/src/parser/utils.js +203 -0
  150. package/src/parser/variable.js +363 -0
  151. package/src/parser.js +748 -0
  152. package/src/tokens.js +177 -0
  153. package/types.d.ts +1457 -0
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright (C) 2018 Glayzzle (BSD3 License)
3
+ * @authors https://github.com/glayzzle/php-parser/graphs/contributors
4
+ * @url http://glayzzle.com
5
+ */
6
+ "use strict";
7
+
8
+ const Expression = require("./expression");
9
+ const KIND = "yieldfrom";
10
+
11
+ /**
12
+ * Defines a yield from generator statement
13
+ * @constructor YieldFrom
14
+ * @memberOf module:php-parser
15
+ * @extends {Expression}
16
+ * @property {Expression} value
17
+ * @see http://php.net/manual/en/language.generators.syntax.php
18
+ */
19
+ module.exports = Expression.extends(
20
+ KIND,
21
+ function YieldFrom(value, docs, location) {
22
+ Expression.apply(this, [KIND, docs, location]);
23
+ this.value = value;
24
+ },
25
+ );
package/src/ast.js ADDED
@@ -0,0 +1,593 @@
1
+ /**
2
+ * Copyright (C) 2018 Glayzzle (BSD3 License)
3
+ * @authors https://github.com/glayzzle/php-parser/graphs/contributors
4
+ * @url http://glayzzle.com
5
+ */
6
+ "use strict";
7
+
8
+ const Location = require("./ast/location");
9
+ const Position = require("./ast/position");
10
+
11
+ /**
12
+ * ## Class hierarchy
13
+ *
14
+ * - [Location](#location)
15
+ * - [Position](#position)
16
+ * - [Node](#node)
17
+ * - [Noop](#noop)
18
+ * - [NullKeyword](#nullkeyword)
19
+ * - [StaticVariable](#staticvariable)
20
+ * - [EncapsedPart](#encapsedpart)
21
+ * - [Constant](#constant)
22
+ * - [Identifier](#identifier)
23
+ * - [Reference](#reference)
24
+ * - [TypeReference](#typereference)
25
+ * - [ParentReference](#parentreference)
26
+ * - [StaticReference](#staticreference)
27
+ * - [SelfReference](#selfreference)
28
+ * - [Name](#name)
29
+ * - [TraitUse](#traituse)
30
+ * - [TraitAlias](#traitalias)
31
+ * - [TraitPrecedence](#traitprecedence)
32
+ * - [Comment](#comment)
33
+ * - [CommentLine](#commentline)
34
+ * - [CommentBlock](#commentblock)
35
+ * - [Error](#error)
36
+ * - [Expression](#expression)
37
+ * - [Entry](#entry)
38
+ * - [ArrowFunc](#arrowfunc)
39
+ * - [Closure](#closure)
40
+ * - [ByRef](#byref)
41
+ * - [Silent](#silent)
42
+ * - [RetIf](#retif)
43
+ * - [New](#new)
44
+ * - [Include](#include)
45
+ * - [Call](#call)
46
+ * - [Eval](#eval)
47
+ * - [Exit](#exit)
48
+ * - [Clone](#clone)
49
+ * - [Assign](#assign)
50
+ * - [AssignRef](#assignref)
51
+ * - [Array](#array)
52
+ * - [List](#list)
53
+ * - [Variable](#variable)
54
+ * - [Variadic](#variadic)
55
+ * - [Yield](#yield)
56
+ * - [YieldFrom](#yieldfrom)
57
+ * - [Print](#print)
58
+ * - [Isset](#isset)
59
+ * - [Empty](#empty)
60
+ * - [Lookup](#lookup)
61
+ * - [PropertyLookup](#propertylookup)
62
+ * - [StaticLookup](#staticlookup)
63
+ * - [OffsetLookup](#offsetlookup)
64
+ * - [Operation](#operation)
65
+ * - [Pre](#pre)
66
+ * - [Post](#post)
67
+ * - [Bin](#bin)
68
+ * - [Unary](#unary)
69
+ * - [Cast](#cast)
70
+ * - [Literal](#literal)
71
+ * - [Boolean](#boolean)
72
+ * - [String](#string)
73
+ * - [Number](#number)
74
+ * - [Inline](#inline)
75
+ * - [Magic](#magic)
76
+ * - [Nowdoc](#nowdoc)
77
+ * - [Encapsed](#encapsed)
78
+ * - [Statement](#statement)
79
+ * - [ConstantStatement](#constantstatement)
80
+ * - [ClassConstant](#classconstant)
81
+ * - [Return](#return)
82
+ * - [Label](#label)
83
+ * - [Continue](#continue)
84
+ * - [Case](#case)
85
+ * - [Break](#break)
86
+ * - [Echo](#echo)
87
+ * - [Unset](#unset)
88
+ * - [Halt](#halt)
89
+ * - [Declare](#declare)
90
+ * - [Global](#global)
91
+ * - [Static](#static)
92
+ * - [If](#if)
93
+ * - [Do](#do)
94
+ * - [While](#while)
95
+ * - [For](#for)
96
+ * - [Foreach](#foreach)
97
+ * - [Switch](#switch)
98
+ * - [Goto](#goto)
99
+ * - [Try](#try)
100
+ * - [Catch](#catch)
101
+ * - [Throw](#throw)
102
+ * - [UseGroup](#usegroup)
103
+ * - [UseItem](#useitem)
104
+ * - [Block](#block)
105
+ * - [Program](#program)
106
+ * - [Namespace](#namespace)
107
+ * - [PropertyStatement](#propertystatement)
108
+ * - [Property](#property)
109
+ * - [PropertyHook](#propertyhook)
110
+ * - [Declaration](#declaration)
111
+ * - [Class](#class)
112
+ * - [Interface](#interface)
113
+ * - [Trait](#trait)
114
+ * - [Function](#function)
115
+ * - [Method](#method)
116
+ * - [Parameter](#parameter)
117
+ * ---
118
+ */
119
+
120
+ /**
121
+ * The AST builder class
122
+ * @constructor AST
123
+ * @memberOf module:php-parser
124
+ * @tutorial AST
125
+ * @property {Boolean} withPositions - Should locate any node (by default false)
126
+ * @property {Boolean} withSource - Should extract the node original code (by default false)
127
+ */
128
+ const AST = function (withPositions, withSource) {
129
+ this.withPositions = withPositions;
130
+ this.withSource = withSource;
131
+ };
132
+
133
+ // operators in ascending order of precedence
134
+ AST.precedence = {};
135
+ [
136
+ ["or"],
137
+ ["xor"],
138
+ ["and"],
139
+ ["="],
140
+ ["?"],
141
+ ["??"],
142
+ ["||"],
143
+ ["&&"],
144
+ ["|"],
145
+ ["^"],
146
+ ["&"],
147
+ ["==", "!=", "===", "!==", /* '<>', */ "<=>"],
148
+ ["<", "<=", ">", ">="],
149
+ ["<<", ">>"],
150
+ ["+", "-", "."],
151
+ ["*", "/", "%"],
152
+ ["!"],
153
+ ["instanceof"],
154
+ ["cast", "silent"],
155
+ ["**"],
156
+ // TODO: [ (array)
157
+ // TODO: clone, new
158
+ ].forEach(function (list, index) {
159
+ list.forEach(function (operator) {
160
+ AST.precedence[operator] = index + 1;
161
+ });
162
+ });
163
+
164
+ /**
165
+ * @private
166
+ * @function AST#isRightAssociative
167
+ * @memberOf module:php-parser
168
+ * @param operator
169
+ * @return {boolean}
170
+ */
171
+ AST.prototype.isRightAssociative = function (operator) {
172
+ return operator === "**" || operator === "??";
173
+ };
174
+
175
+ /**
176
+ * Change parent node informations after swapping childs
177
+ * @private
178
+ * @function AST#swapLocations
179
+ * @memberOf module:php-parser
180
+ */
181
+ AST.prototype.swapLocations = function (target, first, last, parser) {
182
+ if (this.withPositions) {
183
+ target.loc.start = first.loc.start;
184
+ target.loc.end = last.loc.end;
185
+ if (this.withSource) {
186
+ target.loc.source = parser.lexer._input.substring(
187
+ target.loc.start.offset,
188
+ target.loc.end.offset,
189
+ );
190
+ }
191
+ }
192
+ };
193
+
194
+ /**
195
+ * Includes locations from first & last into the target
196
+ * @private
197
+ * @function AST#resolveLocations
198
+ * @memberOf module:php-parser
199
+ */
200
+ AST.prototype.resolveLocations = function (target, first, last, parser) {
201
+ if (this.withPositions) {
202
+ if (target.loc.start.offset > first.loc.start.offset) {
203
+ target.loc.start = first.loc.start;
204
+ }
205
+ /* istanbul ignore next */
206
+ if (target.loc.end.offset < last.loc.end.offset) {
207
+ target.loc.end = last.loc.end;
208
+ }
209
+ if (this.withSource) {
210
+ target.loc.source = parser.lexer._input.substring(
211
+ target.loc.start.offset,
212
+ target.loc.end.offset,
213
+ );
214
+ }
215
+ }
216
+ };
217
+
218
+ /**
219
+ * Check and fix precence, by default using right
220
+ * @private
221
+ * @function AST#resolvePrecedence
222
+ * @memberOf module:php-parser
223
+ */
224
+ AST.prototype.resolvePrecedence = function (result, parser) {
225
+ let buffer, lLevel, rLevel;
226
+ // handling precendence
227
+ if (result.kind === "call") {
228
+ // including what argument into location
229
+ this.resolveLocations(result, result.what, result, parser);
230
+ } else if (
231
+ result.kind === "propertylookup" ||
232
+ result.kind === "staticlookup" ||
233
+ (result.kind === "offsetlookup" && result.offset)
234
+ ) {
235
+ // including what argument into location
236
+ this.resolveLocations(result, result.what, result.offset, parser);
237
+ } else if (result.kind === "bin") {
238
+ if (result.right && !result.right.parenthesizedExpression) {
239
+ if (result.right.kind === "bin") {
240
+ lLevel = AST.precedence[result.type];
241
+ rLevel = AST.precedence[result.right.type];
242
+ if (
243
+ lLevel &&
244
+ rLevel &&
245
+ rLevel <= lLevel &&
246
+ (result.type !== result.right.type ||
247
+ !this.isRightAssociative(result.type))
248
+ ) {
249
+ // https://github.com/glayzzle/php-parser/issues/79
250
+ // shift precedence
251
+ buffer = result.right;
252
+ result.right = result.right.left;
253
+ this.swapLocations(result, result.left, result.right, parser);
254
+ buffer.left = this.resolvePrecedence(result, parser);
255
+ this.swapLocations(buffer, buffer.left, buffer.right, parser);
256
+ result = buffer;
257
+ }
258
+ } else if (result.right.kind === "retif") {
259
+ lLevel = AST.precedence[result.type];
260
+ rLevel = AST.precedence["?"];
261
+ if (lLevel && rLevel && rLevel <= lLevel) {
262
+ buffer = result.right;
263
+ result.right = result.right.test;
264
+ this.swapLocations(result, result.left, result.right, parser);
265
+ buffer.test = this.resolvePrecedence(result, parser);
266
+ this.swapLocations(buffer, buffer.test, buffer.falseExpr, parser);
267
+ result = buffer;
268
+ }
269
+ }
270
+ }
271
+ } else if (
272
+ (result.kind === "silent" || result.kind === "cast") &&
273
+ result.expr &&
274
+ !result.expr.parenthesizedExpression
275
+ ) {
276
+ // https://github.com/glayzzle/php-parser/issues/172
277
+ if (result.expr.kind === "bin") {
278
+ buffer = result.expr;
279
+ result.expr = result.expr.left;
280
+ this.swapLocations(result, result, result.expr, parser);
281
+ buffer.left = this.resolvePrecedence(result, parser);
282
+ this.swapLocations(buffer, buffer.left, buffer.right, parser);
283
+ result = buffer;
284
+ } else if (result.expr.kind === "retif") {
285
+ buffer = result.expr;
286
+ result.expr = result.expr.test;
287
+ this.swapLocations(result, result, result.expr, parser);
288
+ buffer.test = this.resolvePrecedence(result, parser);
289
+ this.swapLocations(buffer, buffer.test, buffer.falseExpr, parser);
290
+ result = buffer;
291
+ }
292
+ } else if (result.kind === "unary") {
293
+ // https://github.com/glayzzle/php-parser/issues/75
294
+ if (result.what && !result.what.parenthesizedExpression) {
295
+ // unary precedence is always lower
296
+ if (result.what.kind === "bin") {
297
+ buffer = result.what;
298
+ result.what = result.what.left;
299
+ this.swapLocations(result, result, result.what, parser);
300
+ buffer.left = this.resolvePrecedence(result, parser);
301
+ this.swapLocations(buffer, buffer.left, buffer.right, parser);
302
+ result = buffer;
303
+ } else if (result.what.kind === "retif") {
304
+ buffer = result.what;
305
+ result.what = result.what.test;
306
+ this.swapLocations(result, result, result.what, parser);
307
+ buffer.test = this.resolvePrecedence(result, parser);
308
+ this.swapLocations(buffer, buffer.test, buffer.falseExpr, parser);
309
+ result = buffer;
310
+ }
311
+ }
312
+ } else if (result.kind === "retif") {
313
+ // https://github.com/glayzzle/php-parser/issues/77
314
+ if (
315
+ result.falseExpr &&
316
+ result.falseExpr.kind === "retif" &&
317
+ !result.falseExpr.parenthesizedExpression
318
+ ) {
319
+ buffer = result.falseExpr;
320
+ result.falseExpr = buffer.test;
321
+ this.swapLocations(result, result.test, result.falseExpr, parser);
322
+ buffer.test = this.resolvePrecedence(result, parser);
323
+ this.swapLocations(buffer, buffer.test, buffer.falseExpr, parser);
324
+ result = buffer;
325
+ }
326
+ } else if (result.kind === "assign") {
327
+ // https://github.com/glayzzle/php-parser/issues/81
328
+ if (
329
+ result.right &&
330
+ result.right.kind === "bin" &&
331
+ !result.right.parenthesizedExpression
332
+ ) {
333
+ lLevel = AST.precedence["="];
334
+ rLevel = AST.precedence[result.right.type];
335
+ // only shifts with and, xor, or
336
+ if (lLevel && rLevel && rLevel < lLevel) {
337
+ buffer = result.right;
338
+ result.right = result.right.left;
339
+ buffer.left = result;
340
+ this.swapLocations(buffer, buffer.left, result.right, parser);
341
+ result = buffer;
342
+ }
343
+ }
344
+ } else if (result.kind === "expressionstatement") {
345
+ this.swapLocations(result, result.expression, result, parser);
346
+ }
347
+ return result;
348
+ };
349
+
350
+ /**
351
+ * Prepares an AST node
352
+ * @private
353
+ * @function AST#prepare
354
+ * @memberOf module:php-parser
355
+ * @param {String|null} kind - Defines the node type
356
+ * @param {*} docs - (if null, the kind must be passed at the function call)
357
+ * @param {Parser} parser - The parser instance (use for extracting locations)
358
+ * @return {Function}
359
+ */
360
+ AST.prototype.prepare = function (kind, docs, parser) {
361
+ let start = null;
362
+ if (this.withPositions || this.withSource) {
363
+ start = parser.position();
364
+ }
365
+ const self = this;
366
+ // returns the node
367
+ const result = function () {
368
+ let location = null;
369
+ const args = Array.prototype.slice.call(arguments);
370
+ args.push(docs);
371
+ if (self.withPositions || self.withSource) {
372
+ let src = null;
373
+ if (self.withSource) {
374
+ src = parser.lexer._input.substring(start.offset, parser.prev[2]);
375
+ }
376
+ // if with source, need location on swapLocations function
377
+ location = new Location(
378
+ src,
379
+ start,
380
+ new Position(parser.prev[0], parser.prev[1], parser.prev[2]),
381
+ );
382
+ // last argument is always the location
383
+ args.push(location);
384
+ }
385
+ // handle lazy kind definitions
386
+ if (!kind) {
387
+ kind = args.shift();
388
+ }
389
+ // build the object
390
+ const node = self[kind];
391
+ if (typeof node !== "function") {
392
+ throw new Error('Undefined node "' + kind + '"');
393
+ }
394
+ const astNode = Object.create(node.prototype);
395
+ node.apply(astNode, args);
396
+ result.instance = astNode;
397
+ /* istanbul ignore next */
398
+ if (result.trailingComments) {
399
+ // buffer of trailingComments
400
+ astNode.trailingComments = result.trailingComments;
401
+ }
402
+ if (typeof result.postBuild === "function") {
403
+ result.postBuild(astNode);
404
+ }
405
+ if (parser.debug) {
406
+ delete self.stack[result.stackUid];
407
+ }
408
+ return self.resolvePrecedence(astNode, parser);
409
+ };
410
+ if (parser.debug) {
411
+ if (!this.stack) {
412
+ this.stack = {};
413
+ this.stackUid = 1;
414
+ }
415
+ this.stack[++this.stackUid] = {
416
+ position: start,
417
+ stack: new Error().stack.split("\n").slice(3, 5),
418
+ };
419
+ result.stackUid = this.stackUid;
420
+ }
421
+
422
+ /**
423
+ * Sets a list of trailing comments
424
+ * @private
425
+ * @param {*} docs
426
+ */
427
+ result.setTrailingComments = function (docs) {
428
+ if (result.instance) {
429
+ // already created
430
+ result.instance.setTrailingComments(docs);
431
+ } else {
432
+ result.trailingComments = docs;
433
+ }
434
+ };
435
+
436
+ /**
437
+ * Release a node without using it on the AST
438
+ * @private
439
+ * @param {*} target
440
+ */
441
+ result.destroy = function (target) {
442
+ if (docs) {
443
+ // release current docs stack
444
+ if (target) {
445
+ if (!target.leadingComments) {
446
+ target.leadingComments = docs;
447
+ } else {
448
+ target.leadingComments = docs.concat(target.leadingComments);
449
+ }
450
+ } else {
451
+ parser._docIndex = parser._docs.length - docs.length;
452
+ }
453
+ }
454
+ if (parser.debug) {
455
+ delete self.stack[result.stackUid];
456
+ }
457
+ };
458
+ return result;
459
+ };
460
+
461
+ AST.prototype.checkNodes = function () {
462
+ const errors = [];
463
+ for (const k in this.stack) {
464
+ if (Object.prototype.hasOwnProperty.call(this.stack, k)) {
465
+ this.stack[k].key = k;
466
+ errors.push(this.stack[k]);
467
+ }
468
+ }
469
+ this.stack = {};
470
+ return errors;
471
+ };
472
+
473
+ // Define all AST nodes
474
+ [
475
+ require("./ast/array"),
476
+ require("./ast/arrowfunc"),
477
+ require("./ast/assign"),
478
+ require("./ast/assignref"),
479
+ require("./ast/attribute"),
480
+ require("./ast/attrgroup"),
481
+ require("./ast/bin"),
482
+ require("./ast/block"),
483
+ require("./ast/boolean"),
484
+ require("./ast/break"),
485
+ require("./ast/byref"),
486
+ require("./ast/call"),
487
+ require("./ast/case"),
488
+ require("./ast/cast"),
489
+ require("./ast/catch"),
490
+ require("./ast/class"),
491
+ require("./ast/classconstant"),
492
+ require("./ast/clone"),
493
+ require("./ast/closure"),
494
+ require("./ast/comment"),
495
+ require("./ast/commentblock"),
496
+ require("./ast/commentline"),
497
+ require("./ast/constant"),
498
+ require("./ast/constantstatement"),
499
+ require("./ast/continue"),
500
+ require("./ast/declaration"),
501
+ require("./ast/declare"),
502
+ require("./ast/declaredirective"),
503
+ require("./ast/do"),
504
+ require("./ast/echo"),
505
+ require("./ast/empty"),
506
+ require("./ast/encapsed"),
507
+ require("./ast/encapsedpart"),
508
+ require("./ast/entry"),
509
+ require("./ast/enum"),
510
+ require("./ast/enumcase"),
511
+ require("./ast/error"),
512
+ require("./ast/eval"),
513
+ require("./ast/exit"),
514
+ require("./ast/expression"),
515
+ require("./ast/expressionstatement"),
516
+ require("./ast/for"),
517
+ require("./ast/foreach"),
518
+ require("./ast/function"),
519
+ require("./ast/global"),
520
+ require("./ast/goto"),
521
+ require("./ast/halt"),
522
+ require("./ast/identifier"),
523
+ require("./ast/if"),
524
+ require("./ast/include"),
525
+ require("./ast/inline"),
526
+ require("./ast/interface"),
527
+ require("./ast/intersectiontype"),
528
+ require("./ast/isset"),
529
+ require("./ast/label"),
530
+ require("./ast/list"),
531
+ require("./ast/literal"),
532
+ require("./ast/lookup"),
533
+ require("./ast/magic"),
534
+ require("./ast/match"),
535
+ require("./ast/matcharm"),
536
+ require("./ast/method"),
537
+ require("./ast/name"),
538
+ require("./ast/namespace"),
539
+ require("./ast/namedargument"),
540
+ require("./ast/new"),
541
+ require("./ast/node"),
542
+ require("./ast/noop"),
543
+ require("./ast/nowdoc"),
544
+ require("./ast/nullkeyword"),
545
+ require("./ast/nullsafepropertylookup"),
546
+ require("./ast/number"),
547
+ require("./ast/offsetlookup"),
548
+ require("./ast/operation"),
549
+ require("./ast/parameter"),
550
+ require("./ast/parentreference"),
551
+ require("./ast/post"),
552
+ require("./ast/pre"),
553
+ require("./ast/print"),
554
+ require("./ast/program"),
555
+ require("./ast/property"),
556
+ require("./ast/propertyhook"),
557
+ require("./ast/propertylookup"),
558
+ require("./ast/propertystatement"),
559
+ require("./ast/reference"),
560
+ require("./ast/retif"),
561
+ require("./ast/return"),
562
+ require("./ast/selfreference"),
563
+ require("./ast/silent"),
564
+ require("./ast/statement"),
565
+ require("./ast/static"),
566
+ require("./ast/staticvariable"),
567
+ require("./ast/staticlookup"),
568
+ require("./ast/staticreference"),
569
+ require("./ast/string"),
570
+ require("./ast/switch"),
571
+ require("./ast/throw"),
572
+ require("./ast/trait"),
573
+ require("./ast/traitalias"),
574
+ require("./ast/traitprecedence"),
575
+ require("./ast/traituse"),
576
+ require("./ast/try"),
577
+ require("./ast/typereference"),
578
+ require("./ast/unary"),
579
+ require("./ast/uniontype"),
580
+ require("./ast/unset"),
581
+ require("./ast/usegroup"),
582
+ require("./ast/useitem"),
583
+ require("./ast/variable"),
584
+ require("./ast/variadic"),
585
+ require("./ast/variadicplaceholder"),
586
+ require("./ast/while"),
587
+ require("./ast/yield"),
588
+ require("./ast/yieldfrom"),
589
+ ].forEach(function (ctor) {
590
+ AST.prototype[ctor.kind] = ctor;
591
+ });
592
+
593
+ module.exports = AST;