@samuelbines/nunjucks 0.0.3

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 (66) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +55 -0
  3. package/dist/scripts/smoke.d.ts +1 -0
  4. package/dist/scripts/smoke.js +95 -0
  5. package/dist/src/compiler.d.ts +12 -0
  6. package/dist/src/compiler.js +1050 -0
  7. package/dist/src/environment.d.ts +103 -0
  8. package/dist/src/environment.js +621 -0
  9. package/dist/src/express-app.d.ts +2 -0
  10. package/dist/src/express-app.js +33 -0
  11. package/dist/src/filters.d.ts +44 -0
  12. package/dist/src/filters.js +424 -0
  13. package/dist/src/globals.d.ts +14 -0
  14. package/dist/src/globals.js +342 -0
  15. package/dist/src/index.d.ts +28 -0
  16. package/dist/src/index.js +116 -0
  17. package/dist/src/interpreter.d.ts +16 -0
  18. package/dist/src/interpreter.js +489 -0
  19. package/dist/src/lexer.d.ts +72 -0
  20. package/dist/src/lexer.js +480 -0
  21. package/dist/src/lib.d.ts +74 -0
  22. package/dist/src/lib.js +237 -0
  23. package/dist/src/loader.d.ts +80 -0
  24. package/dist/src/loader.js +175 -0
  25. package/dist/src/nodes.d.ts +362 -0
  26. package/dist/src/nodes.js +894 -0
  27. package/dist/src/parser.d.ts +66 -0
  28. package/dist/src/parser.js +1068 -0
  29. package/dist/src/precompile.d.ts +15 -0
  30. package/dist/src/precompile.js +108 -0
  31. package/dist/src/runtime.d.ts +33 -0
  32. package/dist/src/runtime.js +314 -0
  33. package/dist/src/transformer.d.ts +3 -0
  34. package/dist/src/transformer.js +161 -0
  35. package/dist/src/types.d.ts +27 -0
  36. package/dist/src/types.js +2 -0
  37. package/dist/tests/compiler.test.d.ts +1 -0
  38. package/dist/tests/compiler.test.js +201 -0
  39. package/dist/tests/enviornment.test.d.ts +1 -0
  40. package/dist/tests/enviornment.test.js +279 -0
  41. package/dist/tests/express.test.d.ts +1 -0
  42. package/dist/tests/express.test.js +86 -0
  43. package/dist/tests/filters.test.d.ts +13 -0
  44. package/dist/tests/filters.test.js +286 -0
  45. package/dist/tests/globals.test.d.ts +1 -0
  46. package/dist/tests/globals.test.js +579 -0
  47. package/dist/tests/interpreter.test.d.ts +1 -0
  48. package/dist/tests/interpreter.test.js +208 -0
  49. package/dist/tests/lexer.test.d.ts +1 -0
  50. package/dist/tests/lexer.test.js +249 -0
  51. package/dist/tests/lib.test.d.ts +1 -0
  52. package/dist/tests/lib.test.js +236 -0
  53. package/dist/tests/loader.test.d.ts +1 -0
  54. package/dist/tests/loader.test.js +301 -0
  55. package/dist/tests/nodes.test.d.ts +1 -0
  56. package/dist/tests/nodes.test.js +137 -0
  57. package/dist/tests/parser.test.d.ts +1 -0
  58. package/dist/tests/parser.test.js +294 -0
  59. package/dist/tests/precompile.test.d.ts +1 -0
  60. package/dist/tests/precompile.test.js +224 -0
  61. package/dist/tests/runtime.test.d.ts +1 -0
  62. package/dist/tests/runtime.test.js +237 -0
  63. package/dist/tests/transformer.test.d.ts +1 -0
  64. package/dist/tests/transformer.test.js +125 -0
  65. package/dist/tsconfig.tsbuildinfo +1 -0
  66. package/package.json +59 -0
@@ -0,0 +1,894 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Mul = exports.Sub = exports.Concat = exports.Add = exports.And = exports.Or = exports.Is = exports.In = exports.TemplateData = exports.Extends = exports.KeywordArgs = exports.FilterAsync = exports.Filter = exports.Caller = exports.AsyncAll = exports.AsyncEach = exports.IfAsync = exports.Dict = exports.ArrayNode = exports.Group = exports.Root = exports.NodeList = exports.Symbol = exports.Literal = exports.Value = exports.CallExtension = exports.CompareOperand = exports.Compare = exports.BinOp = exports.UnaryOp = exports.Capture = exports.Output = exports.Case = exports.Switch = exports.Set = exports.Include = exports.FunCall = exports.TemplateRef = exports.Super = exports.Block = exports.Import = exports.Macro = exports.For = exports.InlineIf = exports.If = exports.LookupVal = exports.Pair = exports.FromImport = exports.Slice = exports.Node = void 0;
4
+ exports.NodeCreator = exports.CallExtensionAsync = exports.Pos = exports.Neg = exports.Not = exports.Pow = exports.Mod = exports.FloorDiv = exports.Div = void 0;
5
+ exports.printNodes = printNodes;
6
+ //Done: Sun 4th Jan 2026 (maybe everything should be async by default)
7
+ const lib_1 = require("./lib");
8
+ function traverseAndCheck(obj, type, results) {
9
+ if (obj instanceof type) {
10
+ results?.push(obj);
11
+ }
12
+ if (obj instanceof Node) {
13
+ obj.findAll(type, results);
14
+ }
15
+ }
16
+ class Node {
17
+ lineno;
18
+ colno;
19
+ value;
20
+ children = [];
21
+ body;
22
+ constructor(lineno = 0, colno = 0, // public extname = '', // public __typename: string = this.constructor.name, // public fields: string[] = []
23
+ value) {
24
+ this.lineno = lineno;
25
+ this.colno = colno;
26
+ this.value = value;
27
+ }
28
+ get fields() {
29
+ return this.constructor.fields;
30
+ }
31
+ static fields = [];
32
+ findAll(type, results = []) {
33
+ if (this instanceof NodeList) {
34
+ this.children.forEach((child) => traverseAndCheck(child, type, results));
35
+ }
36
+ else {
37
+ this.fields.forEach((field) => traverseAndCheck(this[field], type, results));
38
+ }
39
+ return results;
40
+ }
41
+ iterFields(func) {
42
+ this.fields.forEach((field) => {
43
+ func(this[field], field);
44
+ });
45
+ }
46
+ }
47
+ exports.Node = Node;
48
+ class Slice extends Node {
49
+ start;
50
+ stop;
51
+ step;
52
+ constructor(lineno, colno, start, stop, step) {
53
+ super(lineno, colno);
54
+ this.start = start;
55
+ this.stop = stop;
56
+ this.step = step;
57
+ this.start = start || new NodeList();
58
+ this.stop = stop;
59
+ this.step = step;
60
+ }
61
+ static fields = ['start', 'stop', 'step'];
62
+ get typename() {
63
+ return 'Slice';
64
+ }
65
+ }
66
+ exports.Slice = Slice;
67
+ class FromImport extends Node {
68
+ template;
69
+ names;
70
+ withContext;
71
+ constructor(lineno, colno, template, names, withContext) {
72
+ super(lineno, colno);
73
+ this.template = template;
74
+ this.names = names;
75
+ this.withContext = withContext;
76
+ (this.names = names || new NodeList()), (this.template = template);
77
+ this.names = names;
78
+ this.withContext = withContext;
79
+ }
80
+ static fields = ['template', 'names', 'withContext'];
81
+ get typename() {
82
+ return 'FromImport';
83
+ }
84
+ }
85
+ exports.FromImport = FromImport;
86
+ class Pair extends Node {
87
+ key;
88
+ constructor(lineno, colno, key, value = null) {
89
+ super(lineno, colno);
90
+ this.key = key;
91
+ this.key = key;
92
+ this.value = value;
93
+ }
94
+ static fields = ['key', 'value'];
95
+ get typename() {
96
+ return 'Pair';
97
+ }
98
+ }
99
+ exports.Pair = Pair;
100
+ class LookupVal extends Node {
101
+ target;
102
+ val;
103
+ constructor(lineno, colno, target, val) {
104
+ super(lineno, colno);
105
+ this.target = target;
106
+ this.val = val;
107
+ this.target = target;
108
+ this.val = val;
109
+ }
110
+ static fields = ['target', 'val'];
111
+ get typename() {
112
+ return 'LookupVal';
113
+ }
114
+ }
115
+ exports.LookupVal = LookupVal;
116
+ class If extends Node {
117
+ cond;
118
+ else_;
119
+ constructor(lineno, colno, cond, body, else_) {
120
+ super(lineno, colno);
121
+ this.cond = cond;
122
+ this.else_ = else_;
123
+ this.cond = cond;
124
+ this.body = body;
125
+ this.else_ = else_;
126
+ }
127
+ static fields = ['cond', 'body', 'else_'];
128
+ get typename() {
129
+ return 'If';
130
+ }
131
+ }
132
+ exports.If = If;
133
+ class InlineIf extends Node {
134
+ cond;
135
+ else_;
136
+ constructor(lineno, colno, cond, body, else_) {
137
+ super(lineno, colno);
138
+ this.cond = cond;
139
+ this.else_ = else_;
140
+ this.cond = cond;
141
+ this.body = body;
142
+ this.else_ = else_;
143
+ }
144
+ static fields = ['cond', 'body', 'else_'];
145
+ get typename() {
146
+ return 'InlineIf';
147
+ }
148
+ }
149
+ exports.InlineIf = InlineIf;
150
+ class For extends Node {
151
+ arr;
152
+ name;
153
+ else_;
154
+ static fields = ['arr', 'name', 'body', 'else_'];
155
+ constructor(lineno, colno, arr = [], name, body, else_) {
156
+ super(lineno, colno);
157
+ this.arr = arr;
158
+ this.name = name;
159
+ this.else_ = else_;
160
+ this.arr = arr;
161
+ this.name = name;
162
+ this.body = body;
163
+ this.else_ = else_;
164
+ }
165
+ get typename() {
166
+ return 'For';
167
+ }
168
+ }
169
+ exports.For = For;
170
+ class Macro extends Node {
171
+ name;
172
+ args;
173
+ constructor(lineno, colno, name, args, body) {
174
+ super(lineno, colno);
175
+ this.name = name;
176
+ this.args = args;
177
+ this.name = name;
178
+ this.args = args;
179
+ this.body = body;
180
+ }
181
+ static fields = ['name', 'args', 'body'];
182
+ get typename() {
183
+ return 'Macro';
184
+ }
185
+ }
186
+ exports.Macro = Macro;
187
+ class Import extends Node {
188
+ template;
189
+ target;
190
+ withContext;
191
+ static fields = ['template', 'target', 'withContext'];
192
+ get typename() {
193
+ return 'Import';
194
+ }
195
+ constructor(lineno, colno, template, target, withContext) {
196
+ super(lineno, colno);
197
+ this.template = template;
198
+ this.target = target;
199
+ this.withContext = withContext;
200
+ this.template = template;
201
+ this.target = target;
202
+ this.withContext = withContext;
203
+ }
204
+ }
205
+ exports.Import = Import;
206
+ class Block extends Node {
207
+ body;
208
+ name;
209
+ constructor(lineno, colno, body, name) {
210
+ super(lineno, colno);
211
+ this.body = body;
212
+ this.name = name;
213
+ this.name = name;
214
+ this.body = body;
215
+ }
216
+ static fields = ['name', 'body'];
217
+ get typename() {
218
+ return 'Block';
219
+ }
220
+ }
221
+ exports.Block = Block;
222
+ class Super extends Node {
223
+ blockName;
224
+ symbol;
225
+ constructor(lineno, colno, blockName, symbol) {
226
+ super(lineno, colno);
227
+ this.blockName = blockName;
228
+ this.symbol = symbol;
229
+ this.blockName = blockName;
230
+ this.symbol = symbol;
231
+ }
232
+ static fields = ['blockName', 'symbol'];
233
+ get typename() {
234
+ return 'Super';
235
+ }
236
+ }
237
+ exports.Super = Super;
238
+ class TemplateRef extends Node {
239
+ template;
240
+ constructor(lineno, colno, template) {
241
+ super(lineno, colno);
242
+ this.template = template;
243
+ this.template = template;
244
+ }
245
+ static fields = ['template'];
246
+ get typename() {
247
+ return 'TemplateRef';
248
+ }
249
+ }
250
+ exports.TemplateRef = TemplateRef;
251
+ class FunCall extends Node {
252
+ name;
253
+ args;
254
+ constructor(lineno, colno, name, args) {
255
+ super(lineno, colno);
256
+ this.name = name;
257
+ this.args = args;
258
+ this.name = name;
259
+ this.args = args;
260
+ }
261
+ static fields = ['name', 'args'];
262
+ get typename() {
263
+ return 'FunCall';
264
+ }
265
+ }
266
+ exports.FunCall = FunCall;
267
+ class Include extends Node {
268
+ template;
269
+ ignoreMissing;
270
+ constructor(lineno, colno, template, ignoreMissing = false) {
271
+ super(lineno, colno);
272
+ this.template = template;
273
+ this.ignoreMissing = ignoreMissing;
274
+ this.template = template;
275
+ this.ignoreMissing = ignoreMissing;
276
+ }
277
+ static fields = ['template', 'ignoreMissing'];
278
+ get typename() {
279
+ return 'Include';
280
+ }
281
+ }
282
+ exports.Include = Include;
283
+ class Set extends Node {
284
+ targets;
285
+ constructor(lineno, colno, targets, value) {
286
+ super(lineno, colno);
287
+ this.targets = targets || '';
288
+ this.value = value;
289
+ }
290
+ static fields = ['targets', 'value'];
291
+ get typename() {
292
+ return 'Set';
293
+ }
294
+ }
295
+ exports.Set = Set;
296
+ class Switch extends Node {
297
+ expr;
298
+ cases;
299
+ _default;
300
+ constructor(lineno, colno, expr, cases, _default) {
301
+ super(lineno, colno);
302
+ this.expr = expr;
303
+ this.cases = cases;
304
+ this._default = _default;
305
+ this.expr = expr || '';
306
+ this.cases = cases;
307
+ this._default = _default;
308
+ }
309
+ static fields = ['expr', 'cases', 'default'];
310
+ get typename() {
311
+ return 'Switch';
312
+ }
313
+ }
314
+ exports.Switch = Switch;
315
+ class Case extends Node {
316
+ cond;
317
+ constructor(lineno, colno, cond, body) {
318
+ super(lineno, colno);
319
+ this.cond = cond;
320
+ this.cond = cond;
321
+ this.body = body;
322
+ }
323
+ static fields = ['cond', 'body'];
324
+ get typename() {
325
+ return 'Case';
326
+ }
327
+ }
328
+ exports.Case = Case;
329
+ class Output extends Node {
330
+ get typename() {
331
+ return 'Output';
332
+ }
333
+ constructor(lineno, colno, args) {
334
+ super(lineno, colno);
335
+ this.children = args;
336
+ }
337
+ }
338
+ exports.Output = Output;
339
+ class Capture extends Node {
340
+ constructor(lineno, colno, body) {
341
+ super(lineno, colno);
342
+ this.body = body;
343
+ }
344
+ static fields = ['body'];
345
+ get typename() {
346
+ return 'Capture';
347
+ }
348
+ }
349
+ exports.Capture = Capture;
350
+ class UnaryOp extends Node {
351
+ target;
352
+ constructor(lineno, colno, target) {
353
+ super(lineno, colno);
354
+ this.target = target;
355
+ this.target = target;
356
+ }
357
+ static fields = ['target'];
358
+ get typename() {
359
+ return 'UnaryOp';
360
+ }
361
+ }
362
+ exports.UnaryOp = UnaryOp;
363
+ class BinOp extends Node {
364
+ left;
365
+ right;
366
+ constructor(lineno, colno, left, right) {
367
+ super(lineno, colno);
368
+ this.left = left;
369
+ this.right = right;
370
+ this.right = right;
371
+ }
372
+ static fields = ['left', 'right'];
373
+ get typename() {
374
+ return 'BinOp';
375
+ }
376
+ }
377
+ exports.BinOp = BinOp;
378
+ class Compare extends Node {
379
+ expr;
380
+ ops;
381
+ constructor(lineno, colno, expr, ops = []) {
382
+ super(lineno, colno);
383
+ this.expr = expr;
384
+ this.ops = ops;
385
+ this.expr = expr;
386
+ this.ops = ops;
387
+ }
388
+ static fields = ['expr', 'ops'];
389
+ get typename() {
390
+ return 'Compare';
391
+ }
392
+ }
393
+ exports.Compare = Compare;
394
+ class CompareOperand extends Node {
395
+ expr;
396
+ type;
397
+ constructor(lineno, colno, expr, type) {
398
+ super(lineno, colno);
399
+ this.expr = expr;
400
+ this.type = type;
401
+ this.expr = expr;
402
+ this.type = type;
403
+ }
404
+ static fields = ['expr', 'type'];
405
+ get typename() {
406
+ return 'CompareOperand';
407
+ }
408
+ }
409
+ exports.CompareOperand = CompareOperand;
410
+ class CallExtension extends Node {
411
+ ext;
412
+ prop;
413
+ args;
414
+ contentArgs;
415
+ extname;
416
+ autoescape;
417
+ static fields = ['extname', 'prop', 'args', 'contentArgs'];
418
+ get typename() {
419
+ return 'CallExtension';
420
+ }
421
+ constructor(lineno, colno, ext, prop, args, contentArgs = []) {
422
+ super(lineno, colno);
423
+ this.ext = ext;
424
+ this.prop = prop;
425
+ this.args = args;
426
+ this.contentArgs = contentArgs;
427
+ // this.parent();
428
+ this.extname = typeof ext === 'string' ? ext : ext.__name || '';
429
+ this.prop = prop;
430
+ this.args = args || new NodeList();
431
+ this.contentArgs = contentArgs;
432
+ this.autoescape = !(typeof ext === 'string') && ext.autoescape;
433
+ }
434
+ }
435
+ exports.CallExtension = CallExtension;
436
+ class Value extends Node {
437
+ value;
438
+ static fields = ['value'];
439
+ get typename() {
440
+ return 'Value';
441
+ }
442
+ constructor(lineno, colno, value) {
443
+ super(lineno, colno);
444
+ this.value = value;
445
+ this.value = value;
446
+ }
447
+ }
448
+ exports.Value = Value;
449
+ class Literal extends Value {
450
+ get typename() {
451
+ return 'Literal';
452
+ }
453
+ }
454
+ exports.Literal = Literal;
455
+ class Symbol extends Value {
456
+ get typename() {
457
+ return 'Symbol';
458
+ }
459
+ }
460
+ exports.Symbol = Symbol;
461
+ class NodeList extends Node {
462
+ children = [];
463
+ static fields = ['children'];
464
+ get typename() {
465
+ return 'NodeList';
466
+ }
467
+ constructor(lineno = 0, colno = 0, children) {
468
+ super(lineno, colno);
469
+ this.children = children;
470
+ }
471
+ addChild(node) {
472
+ this.children?.push(node);
473
+ }
474
+ }
475
+ exports.NodeList = NodeList;
476
+ class Root extends NodeList {
477
+ get typename() {
478
+ return 'Root';
479
+ }
480
+ }
481
+ exports.Root = Root;
482
+ class Group extends NodeList {
483
+ get typename() {
484
+ return 'Group';
485
+ }
486
+ }
487
+ exports.Group = Group;
488
+ class ArrayNode extends NodeList {
489
+ get typename() {
490
+ return 'Array';
491
+ }
492
+ }
493
+ exports.ArrayNode = ArrayNode;
494
+ class Dict extends NodeList {
495
+ get typename() {
496
+ return 'Dict';
497
+ }
498
+ }
499
+ exports.Dict = Dict;
500
+ class IfAsync extends If {
501
+ get typename() {
502
+ return 'IfAsync';
503
+ }
504
+ }
505
+ exports.IfAsync = IfAsync;
506
+ class AsyncEach extends For {
507
+ get typename() {
508
+ return 'AsyncEach';
509
+ }
510
+ }
511
+ exports.AsyncEach = AsyncEach;
512
+ class AsyncAll extends For {
513
+ get typename() {
514
+ return 'AsyncAll';
515
+ }
516
+ }
517
+ exports.AsyncAll = AsyncAll;
518
+ class Caller extends Macro {
519
+ get typename() {
520
+ return 'Caller';
521
+ }
522
+ }
523
+ exports.Caller = Caller;
524
+ class Filter extends Macro {
525
+ get typename() {
526
+ return 'Filter';
527
+ }
528
+ }
529
+ exports.Filter = Filter;
530
+ // @ts-ignore
531
+ class FilterAsync extends Filter {
532
+ name;
533
+ args;
534
+ symbol;
535
+ static fields = [
536
+ 'name',
537
+ 'args',
538
+ 'symbol',
539
+ ];
540
+ constructor(lineno, colno, name, args, symbol) {
541
+ super(lineno, colno, name, args);
542
+ this.name = name;
543
+ this.args = args;
544
+ this.symbol = symbol;
545
+ this.name = name;
546
+ this.args = args;
547
+ this.symbol = symbol;
548
+ }
549
+ get typename() {
550
+ return 'FilterAsync';
551
+ }
552
+ }
553
+ exports.FilterAsync = FilterAsync;
554
+ class KeywordArgs extends Dict {
555
+ constructor(lineno = 0, colno = 0) {
556
+ super(lineno, colno);
557
+ }
558
+ get typename() {
559
+ return 'KeywordArgs';
560
+ }
561
+ }
562
+ exports.KeywordArgs = KeywordArgs;
563
+ class Extends extends TemplateRef {
564
+ get typename() {
565
+ return 'Extends';
566
+ }
567
+ }
568
+ exports.Extends = Extends;
569
+ class TemplateData extends Literal {
570
+ get typename() {
571
+ return 'TemplateData';
572
+ }
573
+ }
574
+ exports.TemplateData = TemplateData;
575
+ class In extends BinOp {
576
+ get typename() {
577
+ return 'In';
578
+ }
579
+ }
580
+ exports.In = In;
581
+ class Is extends BinOp {
582
+ get typename() {
583
+ return 'Is';
584
+ }
585
+ }
586
+ exports.Is = Is;
587
+ class Or extends BinOp {
588
+ get typename() {
589
+ return 'Or';
590
+ }
591
+ }
592
+ exports.Or = Or;
593
+ class And extends BinOp {
594
+ get typename() {
595
+ return 'And';
596
+ }
597
+ }
598
+ exports.And = And;
599
+ class Add extends BinOp {
600
+ get typename() {
601
+ return 'Add';
602
+ }
603
+ }
604
+ exports.Add = Add;
605
+ class Concat extends BinOp {
606
+ get typename() {
607
+ return 'Concat';
608
+ }
609
+ }
610
+ exports.Concat = Concat;
611
+ class Sub extends BinOp {
612
+ get typename() {
613
+ return 'Sub';
614
+ }
615
+ }
616
+ exports.Sub = Sub;
617
+ class Mul extends BinOp {
618
+ get typename() {
619
+ return 'Mul';
620
+ }
621
+ }
622
+ exports.Mul = Mul;
623
+ class Div extends BinOp {
624
+ get typename() {
625
+ return 'Div';
626
+ }
627
+ }
628
+ exports.Div = Div;
629
+ class FloorDiv extends BinOp {
630
+ get typename() {
631
+ return 'FloorDiv';
632
+ }
633
+ }
634
+ exports.FloorDiv = FloorDiv;
635
+ class Mod extends BinOp {
636
+ get typename() {
637
+ return 'Mod';
638
+ }
639
+ }
640
+ exports.Mod = Mod;
641
+ class Pow extends BinOp {
642
+ get typename() {
643
+ return 'Pow';
644
+ }
645
+ }
646
+ exports.Pow = Pow;
647
+ class Not extends UnaryOp {
648
+ get typename() {
649
+ return 'Not';
650
+ }
651
+ }
652
+ exports.Not = Not;
653
+ class Neg extends UnaryOp {
654
+ get typename() {
655
+ return 'Neg';
656
+ }
657
+ }
658
+ exports.Neg = Neg;
659
+ class Pos extends UnaryOp {
660
+ get typename() {
661
+ return 'Pos';
662
+ }
663
+ }
664
+ exports.Pos = Pos;
665
+ class CallExtensionAsync extends CallExtension {
666
+ name; // todo remove this
667
+ get typename() {
668
+ return 'CallExtensionAsync';
669
+ }
670
+ }
671
+ exports.CallExtensionAsync = CallExtensionAsync;
672
+ function print(str, indent = 0, inline = false) {
673
+ const lines = str.split('\n');
674
+ lines.forEach((line, i) => {
675
+ if (line && ((inline && i > 0) || !inline)) {
676
+ process.stdout.write(' '.repeat(indent));
677
+ }
678
+ const nl = i === lines?.length - 1 ? '' : '\n';
679
+ process.stdout.write(`${line}${nl}`);
680
+ });
681
+ }
682
+ // Print the AST in a nicely formatted tree format for debuggin
683
+ function printNodes(node, indent = 0) {
684
+ lib_1.p.log(node?.typename + ': ', indent);
685
+ if (node instanceof NodeList) {
686
+ print('\n');
687
+ node.children.forEach((n) => {
688
+ printNodes(n, indent + 2);
689
+ });
690
+ }
691
+ else if (node instanceof CallExtension) {
692
+ print(`${node.extname}.${node.prop}\n`);
693
+ if (node.args) {
694
+ printNodes(node.args, indent + 2);
695
+ }
696
+ if (node.contentArgs) {
697
+ node.contentArgs.forEach((n) => {
698
+ printNodes(n, indent + 2);
699
+ });
700
+ }
701
+ }
702
+ else {
703
+ let nodes = [];
704
+ let props = null;
705
+ node.iterFields((val, fieldName) => {
706
+ if (val instanceof Node) {
707
+ nodes?.push([fieldName, val]);
708
+ }
709
+ else {
710
+ props = props || {};
711
+ props[fieldName] = val;
712
+ }
713
+ });
714
+ print(props ? (0, lib_1.dump)(props, 2) + '\n' : '\n', 0, true);
715
+ nodes.forEach(([fieldName, n]) => {
716
+ print(`[${fieldName}] =>`, indent + 2);
717
+ printNodes(n, indent + 4);
718
+ });
719
+ }
720
+ }
721
+ const NodeTypes = {
722
+ Add,
723
+ And,
724
+ Array: ArrayNode,
725
+ AsyncEach,
726
+ AsyncAll,
727
+ BinOp,
728
+ Block,
729
+ Caller,
730
+ CallExtension,
731
+ CallExtensionAsync,
732
+ Capture,
733
+ Case,
734
+ Compare,
735
+ CompareOperand,
736
+ Concat,
737
+ Dict,
738
+ Div,
739
+ Extends,
740
+ Filter,
741
+ FilterAsync,
742
+ FloorDiv,
743
+ For,
744
+ FromImport,
745
+ FunCall,
746
+ Group,
747
+ If,
748
+ IfAsync,
749
+ Import,
750
+ In,
751
+ Include,
752
+ InlineIf,
753
+ Is,
754
+ KeywordArgs,
755
+ Literal,
756
+ LookupVal,
757
+ Macro,
758
+ Mod,
759
+ Mul,
760
+ Neg,
761
+ NodeList,
762
+ Not,
763
+ Or,
764
+ Output,
765
+ Pair,
766
+ Pos,
767
+ Pow,
768
+ Root,
769
+ Set,
770
+ Slice,
771
+ Sub,
772
+ Super,
773
+ Switch,
774
+ Symbol,
775
+ TemplateData,
776
+ Value,
777
+ };
778
+ const NodeCreator = (key) => {
779
+ switch (key) {
780
+ case 'Add':
781
+ return Add;
782
+ case 'And':
783
+ return And;
784
+ case 'Array':
785
+ return ArrayNode;
786
+ case 'AsyncEach':
787
+ return AsyncEach;
788
+ case 'AsyncAll':
789
+ return AsyncAll;
790
+ case 'BinOp':
791
+ return BinOp;
792
+ case 'Block':
793
+ return Block;
794
+ case 'Caller':
795
+ return Caller;
796
+ case 'CallExtension':
797
+ return CallExtension;
798
+ case 'CallExtensionAsync':
799
+ return CallExtensionAsync;
800
+ case 'Capture':
801
+ return Capture;
802
+ case 'Case':
803
+ return Case;
804
+ case 'Compare':
805
+ return Compare;
806
+ case 'CompareOperand':
807
+ return CompareOperand;
808
+ case 'Concat':
809
+ return Concat;
810
+ case 'Dict':
811
+ return Dict;
812
+ case 'Div':
813
+ return Div;
814
+ case 'Extends':
815
+ return Extends;
816
+ case 'Filter':
817
+ return Filter;
818
+ case 'FilterAsync':
819
+ return FilterAsync;
820
+ case 'FloorDiv':
821
+ return FloorDiv;
822
+ case 'For':
823
+ return For;
824
+ case 'FromImport':
825
+ return FromImport;
826
+ case 'FunCall':
827
+ return FunCall;
828
+ case 'Group':
829
+ return Group;
830
+ case 'If':
831
+ return If;
832
+ case 'IfAsync':
833
+ return IfAsync;
834
+ case 'Import':
835
+ return Import;
836
+ case 'In':
837
+ return In;
838
+ case 'Include':
839
+ return Include;
840
+ case 'InlineIf':
841
+ return InlineIf;
842
+ case 'Is':
843
+ return Is;
844
+ case 'KeywordArgs':
845
+ return KeywordArgs;
846
+ case 'Literal':
847
+ return Literal;
848
+ case 'LookupVal':
849
+ return LookupVal;
850
+ case 'Macro':
851
+ return Macro;
852
+ case 'Mod':
853
+ return Mod;
854
+ case 'Mul':
855
+ return Mul;
856
+ case 'Neg':
857
+ return Neg;
858
+ case 'NodeList':
859
+ return NodeList;
860
+ case 'Not':
861
+ return Not;
862
+ case 'Or':
863
+ return Or;
864
+ case 'Output':
865
+ return Output;
866
+ case 'Pair':
867
+ return Pair;
868
+ case 'Pos':
869
+ return Pos;
870
+ case 'Pow':
871
+ return Pow;
872
+ case 'Root':
873
+ return Root;
874
+ case 'Set':
875
+ return Set;
876
+ case 'Slice':
877
+ return Slice;
878
+ case 'Sub':
879
+ return Sub;
880
+ case 'Super':
881
+ return Super;
882
+ case 'Switch':
883
+ return Switch;
884
+ case 'Symbol':
885
+ return Symbol;
886
+ case 'TemplateData':
887
+ return TemplateData;
888
+ case 'Value':
889
+ return Value;
890
+ default:
891
+ throw new Error(`No node type found: ${key}`);
892
+ }
893
+ };
894
+ exports.NodeCreator = NodeCreator;