@optionfactory/fml 8.0.0

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 (47) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +22 -0
  3. package/dist/client-errors.iife.js +109 -0
  4. package/dist/client-errors.iife.js.map +1 -0
  5. package/dist/client-errors.iife.min.js +2 -0
  6. package/dist/client-errors.iife.min.js.map +1 -0
  7. package/dist/fml.css +2 -0
  8. package/dist/fml.css.map +1 -0
  9. package/dist/fml.d.mts +1241 -0
  10. package/dist/fml.iife.js +8340 -0
  11. package/dist/fml.iife.js.map +1 -0
  12. package/dist/fml.iife.min.js +2 -0
  13. package/dist/fml.iife.min.js.map +1 -0
  14. package/dist/fml.min.mjs +2 -0
  15. package/dist/fml.min.mjs.map +1 -0
  16. package/dist/fml.mjs +8284 -0
  17. package/dist/fml.mjs.map +1 -0
  18. package/dist/ftl.d.mts +361 -0
  19. package/dist/ftl.iife.js +4719 -0
  20. package/dist/ftl.iife.js.map +1 -0
  21. package/dist/ftl.iife.min.js +2 -0
  22. package/dist/ftl.iife.min.js.map +1 -0
  23. package/dist/ftl.min.mjs +2 -0
  24. package/dist/ftl.min.mjs.map +1 -0
  25. package/dist/ftl.mjs +4700 -0
  26. package/dist/ftl.mjs.map +1 -0
  27. package/dist/ful.css +2 -0
  28. package/dist/ful.css.map +1 -0
  29. package/dist/ful.d.mts +581 -0
  30. package/dist/ful.iife.js +2814 -0
  31. package/dist/ful.iife.js.map +1 -0
  32. package/dist/ful.iife.min.js +2 -0
  33. package/dist/ful.iife.min.js.map +1 -0
  34. package/dist/ful.min.mjs +2 -0
  35. package/dist/ful.min.mjs.map +1 -0
  36. package/dist/ful.mjs +2780 -0
  37. package/dist/ful.mjs.map +1 -0
  38. package/dist/httpc.d.mts +306 -0
  39. package/dist/httpc.iife.js +755 -0
  40. package/dist/httpc.iife.js.map +1 -0
  41. package/dist/httpc.iife.min.js +2 -0
  42. package/dist/httpc.iife.min.js.map +1 -0
  43. package/dist/httpc.min.mjs +2 -0
  44. package/dist/httpc.min.mjs.map +1 -0
  45. package/dist/httpc.mjs +743 -0
  46. package/dist/httpc.mjs.map +1 -0
  47. package/package.json +72 -0
package/dist/ftl.mjs ADDED
@@ -0,0 +1,4700 @@
1
+ const nodes = {
2
+ ter: Symbol('ternary'),
3
+ elv: Symbol('elvis'),
4
+ nullc: Symbol('null-coalescence'),
5
+ or: Symbol('or'),
6
+ and: Symbol('and'),
7
+ eq: Symbol('eq'),
8
+ cmp: Symbol('cmp'),
9
+ not: Symbol('not'),
10
+ access: Symbol('access'),
11
+ member: Symbol('access-member'),
12
+ subscript: Symbol('access-subscript'),
13
+ method: Symbol('access-method-call'),
14
+ call: Symbol('module-function-call'),
15
+ tstring: Symbol('tstring'),
16
+ literal: Symbol('literal'),
17
+ array: Symbol('array-literal'),
18
+ dict: Symbol('dict-literal'),
19
+ function: Symbol('module-function'),
20
+ symbol: Symbol('symbol'),
21
+ templated: {
22
+ ten: Symbol('templated-node'),
23
+ teh: Symbol('templated-html'),
24
+ tet: Symbol('templated-text'),
25
+ tel: Symbol('templated-literal'),
26
+ },
27
+ dom: {
28
+ t: Symbol('text'),
29
+ h: Symbol('html'),
30
+ n: Symbol('node'),
31
+ },
32
+ };
33
+
34
+ // @generated by Peggy 5.1.0.
35
+ //
36
+ // https://peggyjs.org/
37
+
38
+
39
+ class peg$SyntaxError extends SyntaxError {
40
+ constructor(message, expected, found, location) {
41
+ super(message);
42
+ this.expected = expected;
43
+ this.found = found;
44
+ this.location = location;
45
+ this.name = "SyntaxError";
46
+ }
47
+
48
+ format(sources) {
49
+ let str = "Error: " + this.message;
50
+ if (this.location) {
51
+ let src = null;
52
+ const st = sources.find(s => s.source === this.location.source);
53
+ if (st) {
54
+ src = st.text.split(/\r\n|\n|\r/g);
55
+ }
56
+ const s = this.location.start;
57
+ const offset_s = (this.location.source && (typeof this.location.source.offset === "function"))
58
+ ? this.location.source.offset(s)
59
+ : s;
60
+ const loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column;
61
+ if (src) {
62
+ const e = this.location.end;
63
+ const filler = "".padEnd(offset_s.line.toString().length, " ");
64
+ const line = src[s.line - 1];
65
+ const last = s.line === e.line ? e.column : line.length + 1;
66
+ const hatLen = (last - s.column) || 1;
67
+ str += "\n --> " + loc + "\n"
68
+ + filler + " |\n"
69
+ + offset_s.line + " | " + line + "\n"
70
+ + filler + " | " + "".padEnd(s.column - 1, " ")
71
+ + "".padEnd(hatLen, "^");
72
+ } else {
73
+ str += "\n at " + loc;
74
+ }
75
+ }
76
+ return str;
77
+ }
78
+
79
+ static buildMessage(expected, found) {
80
+ function hex(ch) {
81
+ return ch.codePointAt(0).toString(16).toUpperCase();
82
+ }
83
+
84
+ const nonPrintable = Object.prototype.hasOwnProperty.call(RegExp.prototype, "unicode")
85
+ ? new RegExp("[\\p{C}\\p{Mn}\\p{Mc}]", "gu")
86
+ : null;
87
+ function unicodeEscape(s) {
88
+ if (nonPrintable) {
89
+ return s.replace(nonPrintable, ch => "\\u{" + hex(ch) + "}");
90
+ }
91
+ return s;
92
+ }
93
+
94
+ function literalEscape(s) {
95
+ return unicodeEscape(s
96
+ .replace(/\\/g, "\\\\")
97
+ .replace(/"/g, "\\\"")
98
+ .replace(/\0/g, "\\0")
99
+ .replace(/\t/g, "\\t")
100
+ .replace(/\n/g, "\\n")
101
+ .replace(/\r/g, "\\r")
102
+ .replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch))
103
+ .replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch)));
104
+ }
105
+
106
+ function classEscape(s) {
107
+ return unicodeEscape(s
108
+ .replace(/\\/g, "\\\\")
109
+ .replace(/\]/g, "\\]")
110
+ .replace(/\^/g, "\\^")
111
+ .replace(/-/g, "\\-")
112
+ .replace(/\0/g, "\\0")
113
+ .replace(/\t/g, "\\t")
114
+ .replace(/\n/g, "\\n")
115
+ .replace(/\r/g, "\\r")
116
+ .replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch))
117
+ .replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch)));
118
+ }
119
+
120
+ const DESCRIBE_EXPECTATION_FNS = {
121
+ literal(expectation) {
122
+ return "\"" + literalEscape(expectation.text) + "\"";
123
+ },
124
+
125
+ class(expectation) {
126
+ const escapedParts = expectation.parts.map(
127
+ part => (Array.isArray(part)
128
+ ? classEscape(part[0]) + "-" + classEscape(part[1])
129
+ : classEscape(part))
130
+ );
131
+
132
+ return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]" + (expectation.unicode ? "u" : "");
133
+ },
134
+
135
+ any() {
136
+ return "any character";
137
+ },
138
+
139
+ end() {
140
+ return "end of input";
141
+ },
142
+
143
+ other(expectation) {
144
+ return expectation.description;
145
+ },
146
+ };
147
+
148
+ function describeExpectation(expectation) {
149
+ return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
150
+ }
151
+
152
+ function describeExpected(expected) {
153
+ const descriptions = expected.map(describeExpectation);
154
+ descriptions.sort();
155
+
156
+ if (descriptions.length > 0) {
157
+ let j = 1;
158
+ for (let i = 1; i < descriptions.length; i++) {
159
+ if (descriptions[i - 1] !== descriptions[i]) {
160
+ descriptions[j] = descriptions[i];
161
+ j++;
162
+ }
163
+ }
164
+ descriptions.length = j;
165
+ }
166
+
167
+ switch (descriptions.length) {
168
+ case 1:
169
+ return descriptions[0];
170
+
171
+ case 2:
172
+ return descriptions[0] + " or " + descriptions[1];
173
+
174
+ default:
175
+ return descriptions.slice(0, -1).join(", ")
176
+ + ", or "
177
+ + descriptions[descriptions.length - 1];
178
+ }
179
+ }
180
+
181
+ function describeFound(found) {
182
+ return found ? "\"" + literalEscape(found) + "\"" : "end of input";
183
+ }
184
+
185
+ return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
186
+ }
187
+ }
188
+
189
+ function peg$parse(input, options) {
190
+ options = options !== undefined ? options : {};
191
+
192
+ const peg$FAILED = {};
193
+ const peg$source = options.grammarSource;
194
+
195
+ const peg$startRuleFunctions = {
196
+ TemplatedRoot: peg$parseTemplatedRoot,
197
+ ExpressionRoot: peg$parseExpressionRoot,
198
+ };
199
+ let peg$startRuleFunction = peg$parseTemplatedRoot;
200
+ const peg$c1 = "{{{{";
201
+ const peg$c2 = "}}}}";
202
+ const peg$c3 = "{{{";
203
+ const peg$c4 = "}}}";
204
+ const peg$c5 = "{{";
205
+ const peg$c6 = "}}";
206
+ const peg$c7 = "\\";
207
+ const peg$c9 = "{";
208
+ const peg$c13 = "?";
209
+ const peg$c15 = ":";
210
+ const peg$c17 = "?:";
211
+ const peg$c19 = "??";
212
+ const peg$c22 = "||";
213
+ const peg$c24 = "&&";
214
+ const peg$c26 = "!";
215
+ const peg$c28 = "?.";
216
+ const peg$c29 = ".";
217
+ const peg$c30 = "[";
218
+ const peg$c31 = "]";
219
+ const peg$c32 = "(";
220
+ const peg$c34 = ",";
221
+ const peg$c36 = ")";
222
+ const peg$c39 = "true";
223
+ const peg$c40 = "false";
224
+ const peg$c41 = "null";
225
+ const peg$c42 = "undefined";
226
+ const peg$c43 = "-";
227
+ const peg$c44 = "'";
228
+ const peg$c45 = "\"";
229
+ const peg$c46 = "`";
230
+ const peg$c47 = "}";
231
+ const peg$c49 = "#";
232
+ const peg$c53 = "==";
233
+ const peg$c54 = "!=";
234
+ const peg$c55 = ">=";
235
+ const peg$c56 = ">";
236
+ const peg$c57 = "<=";
237
+ const peg$c58 = "<";
238
+
239
+ const peg$r0 = /^[^\\{]/;
240
+ const peg$r1 = /^[0-9]/;
241
+ const peg$r2 = /^[^']/;
242
+ const peg$r3 = /^[^"]/;
243
+ const peg$r4 = /^[^\\`{]/;
244
+ const peg$r5 = /^[a-zA-Z$_]/;
245
+ const peg$r6 = /^[a-zA-Z$_0-9_]/;
246
+ const peg$r7 = /^[ \t\n\r]/;
247
+
248
+ const peg$e0 = peg$literalExpectation("{{{{", false);
249
+ const peg$e1 = peg$literalExpectation("}}}}", false);
250
+ const peg$e2 = peg$literalExpectation("{{{", false);
251
+ const peg$e3 = peg$literalExpectation("}}}", false);
252
+ const peg$e4 = peg$literalExpectation("{{", false);
253
+ const peg$e5 = peg$literalExpectation("}}", false);
254
+ const peg$e6 = peg$classExpectation(["\\", "{"], true, false, false);
255
+ const peg$e7 = peg$literalExpectation("\\", false);
256
+ const peg$e8 = peg$anyExpectation();
257
+ const peg$e9 = peg$literalExpectation("{", false);
258
+ const peg$e10 = peg$literalExpectation("?", false);
259
+ const peg$e11 = peg$literalExpectation(":", false);
260
+ const peg$e12 = peg$literalExpectation("?:", false);
261
+ const peg$e13 = peg$literalExpectation("??", false);
262
+ const peg$e14 = peg$literalExpectation("||", false);
263
+ const peg$e15 = peg$literalExpectation("&&", false);
264
+ const peg$e16 = peg$literalExpectation("!", false);
265
+ const peg$e17 = peg$otherExpectation("member");
266
+ const peg$e18 = peg$literalExpectation("?.", false);
267
+ const peg$e19 = peg$literalExpectation(".", false);
268
+ const peg$e20 = peg$otherExpectation("subscript");
269
+ const peg$e21 = peg$literalExpectation("[", false);
270
+ const peg$e22 = peg$literalExpectation("]", false);
271
+ const peg$e23 = peg$otherExpectation("method-call");
272
+ const peg$e24 = peg$literalExpectation("(", false);
273
+ const peg$e25 = peg$literalExpectation(",", false);
274
+ const peg$e26 = peg$literalExpectation(")", false);
275
+ const peg$e27 = peg$otherExpectation("module-function-call");
276
+ const peg$e28 = peg$otherExpectation("boolean-literal");
277
+ const peg$e29 = peg$literalExpectation("true", false);
278
+ const peg$e30 = peg$literalExpectation("false", false);
279
+ const peg$e31 = peg$otherExpectation("null-literal");
280
+ const peg$e32 = peg$literalExpectation("null", false);
281
+ const peg$e33 = peg$otherExpectation("undefined-literal");
282
+ const peg$e34 = peg$literalExpectation("undefined", false);
283
+ const peg$e35 = peg$otherExpectation("number-literal");
284
+ const peg$e36 = peg$literalExpectation("-", false);
285
+ const peg$e37 = peg$classExpectation([["0", "9"]], false, false, false);
286
+ const peg$e38 = peg$otherExpectation("string-literal");
287
+ const peg$e39 = peg$literalExpectation("'", false);
288
+ const peg$e40 = peg$classExpectation(["'"], true, false, false);
289
+ const peg$e41 = peg$literalExpectation("\"", false);
290
+ const peg$e42 = peg$classExpectation(["\""], true, false, false);
291
+ const peg$e43 = peg$literalExpectation("`", false);
292
+ const peg$e44 = peg$otherExpectation("tstring-expression");
293
+ const peg$e45 = peg$literalExpectation("}", false);
294
+ const peg$e46 = peg$otherExpectation("tstring-literal");
295
+ const peg$e47 = peg$classExpectation(["\\", "`", "{"], true, false, false);
296
+ const peg$e48 = peg$otherExpectation("array-literal");
297
+ const peg$e49 = peg$otherExpectation("dict-literal");
298
+ const peg$e50 = peg$otherExpectation("module-function");
299
+ const peg$e51 = peg$literalExpectation("#", false);
300
+ const peg$e52 = peg$classExpectation([["a", "z"], ["A", "Z"], "$", "_"], false, false, false);
301
+ const peg$e53 = peg$classExpectation([["a", "z"], ["A", "Z"], "$", "_", ["0", "9"], "_"], false, false, false);
302
+ const peg$e54 = peg$otherExpectation("symbol");
303
+ const peg$e55 = peg$literalExpectation("==", false);
304
+ const peg$e56 = peg$literalExpectation("!=", false);
305
+ const peg$e57 = peg$literalExpectation(">=", false);
306
+ const peg$e58 = peg$literalExpectation(">", false);
307
+ const peg$e59 = peg$literalExpectation("<=", false);
308
+ const peg$e60 = peg$literalExpectation("<", false);
309
+ const peg$e61 = peg$classExpectation([" ", "\t", "\n", "\r"], false, false, false);
310
+
311
+ function peg$f0(value) { return {type:nodes.templated.ten, value} }
312
+ function peg$f1(value) { return {type:nodes.templated.teh, value} }
313
+ function peg$f2(value) { return {type:nodes.templated.tet, value} }
314
+ function peg$f3(value) { return {type:nodes.templated.tel, value} }
315
+ function peg$f4(c) { return c; }
316
+ function peg$f5(parts) { return parts.join(''); }
317
+ function peg$f6(r) { return r; }
318
+ function peg$f7(cond, ifTrue, ifFalse) { return {type:nodes.ter, cond, ifTrue, ifFalse}; }
319
+ function peg$f8(cond, ifFalse) {return {type:nodes.elv, cond, ifFalse}; }
320
+ function peg$f9(lhs, rhs) { return {type:nodes.nullc, lhs, rhs}; }
321
+ function peg$f10(head, tail) {
322
+ let result = head;
323
+ for (const rhs of tail) {
324
+ result = {type: nodes.or, lhs: result, rhs};
325
+ }
326
+ return result;
327
+ }
328
+ function peg$f11(head, tail) {
329
+ let result = head;
330
+ for (const rhs of tail) {
331
+ result = {type: nodes.and, lhs: result, rhs};
332
+ }
333
+ return result;
334
+ }
335
+ function peg$f12(head, op, rhs) {return {op, rhs}; }
336
+ function peg$f13(head, tail) {
337
+ let result = head;
338
+ for (const element of tail) {
339
+ result = {type: nodes.eq, op: element.op, lhs: result, rhs: element.rhs};
340
+ }
341
+ return result;
342
+ }
343
+ function peg$f14(head, op, rhs) {return {op, rhs}; }
344
+ function peg$f15(head, tail) {
345
+ let result = head;
346
+ for (const element of tail) {
347
+ result = {type: nodes.cmp, op: element.op, lhs: result, rhs: element.rhs};
348
+ }
349
+ return result;
350
+ }
351
+ function peg$f16(expr) { return {type:nodes.not, expr} }
352
+ function peg$f17(lhs, rhs) { return {type: nodes.access, lhs, rhs} }
353
+ function peg$f18(op, rhs) {
354
+ return {type: nodes.member, ns: op === '?.', rhs: rhs.value};
355
+ }
356
+ function peg$f19(op, rhs) {
357
+ return {type: nodes.subscript, ns: op !== null, rhs};
358
+ }
359
+ function peg$f20(op, h, t) {
360
+ return {type: nodes.method, ns: op !== null, args: h === null ? [] : [h, ...t]};
361
+ }
362
+ function peg$f21(e) { return e }
363
+ function peg$f22(fn, h, t) {
364
+ const args = h === null ? [] : [h, ...t];
365
+ return {type: nodes.call, value: fn, args};
366
+ }
367
+ function peg$f23() {
368
+ return {type: nodes.literal, value: true};
369
+ }
370
+ function peg$f24() {
371
+ return {type: nodes.literal, value: false};
372
+ }
373
+ function peg$f25() {
374
+ return {type: nodes.literal, value: null};
375
+ }
376
+ function peg$f26() {
377
+ return {type: nodes.literal, value: undefined};
378
+ }
379
+ function peg$f27(value) {
380
+ return { type: nodes.literal, value: parseFloat(value) };
381
+ }
382
+ function peg$f28(value) { return {type: nodes.literal, value}; }
383
+ function peg$f29(value) { return {type: nodes.literal, value}; }
384
+ function peg$f30(parts) {
385
+ return {type: nodes.tstring, parts};
386
+ }
387
+ function peg$f31(expr) {
388
+ return expr;
389
+ }
390
+ function peg$f32(c) { return c; }
391
+ function peg$f33(parts) {
392
+ return { type: nodes.literal, value: parts.join('') };
393
+ }
394
+ function peg$f34(char) {
395
+ return { type: nodes.literal, value: char };
396
+ }
397
+ function peg$f35(h, t) {
398
+ const value = h === null ? [] : [h, ...t];
399
+ return {type: nodes.array, value};
400
+ }
401
+ function peg$f36(h, t) {
402
+ var value = [];
403
+ if (h !== null){
404
+ value.push(h);
405
+ }
406
+ value.push.apply(value, t);
407
+ return {type: nodes.dict, value};
408
+ }
409
+ function peg$f37(module, v) {
410
+ return {type: nodes.function, module, value: v}
411
+ }
412
+ function peg$f38(s) {
413
+ return {type: nodes.symbol, value: s};
414
+ }
415
+ let peg$currPos = options.peg$currPos | 0;
416
+ const peg$posDetailsCache = [{ line: 1, column: 1 }];
417
+ let peg$maxFailPos = peg$currPos;
418
+ let peg$maxFailExpected = options.peg$maxFailExpected || [];
419
+ let peg$silentFails = options.peg$silentFails | 0;
420
+
421
+ let peg$resultsCache = {};
422
+
423
+ let peg$result;
424
+
425
+ if (options.startRule) {
426
+ if (!(options.startRule in peg$startRuleFunctions)) {
427
+ throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
428
+ }
429
+
430
+ peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
431
+ }
432
+
433
+ function peg$getUnicode(pos = peg$currPos) {
434
+ const cp = input.codePointAt(pos);
435
+ if (cp === undefined) {
436
+ return "";
437
+ }
438
+ return String.fromCodePoint(cp);
439
+ }
440
+
441
+ function peg$literalExpectation(text, ignoreCase) {
442
+ return { type: "literal", text, ignoreCase };
443
+ }
444
+
445
+ function peg$classExpectation(parts, inverted, ignoreCase, unicode) {
446
+ return { type: "class", parts, inverted, ignoreCase, unicode };
447
+ }
448
+
449
+ function peg$anyExpectation() {
450
+ return { type: "any" };
451
+ }
452
+
453
+ function peg$endExpectation() {
454
+ return { type: "end" };
455
+ }
456
+
457
+ function peg$otherExpectation(description) {
458
+ return { type: "other", description };
459
+ }
460
+
461
+ function peg$computePosDetails(pos) {
462
+ let details = peg$posDetailsCache[pos];
463
+ let p;
464
+
465
+ if (details) {
466
+ return details;
467
+ } else {
468
+ if (pos >= peg$posDetailsCache.length) {
469
+ p = peg$posDetailsCache.length - 1;
470
+ } else {
471
+ p = pos;
472
+ while (!peg$posDetailsCache[--p]) {}
473
+ }
474
+
475
+ details = peg$posDetailsCache[p];
476
+ details = {
477
+ line: details.line,
478
+ column: details.column,
479
+ };
480
+
481
+ while (p < pos) {
482
+ if (input.charCodeAt(p) === 10) {
483
+ details.line++;
484
+ details.column = 1;
485
+ } else {
486
+ details.column++;
487
+ }
488
+
489
+ p++;
490
+ }
491
+
492
+ peg$posDetailsCache[pos] = details;
493
+
494
+ return details;
495
+ }
496
+ }
497
+
498
+ function peg$computeLocation(startPos, endPos, offset) {
499
+ const startPosDetails = peg$computePosDetails(startPos);
500
+ const endPosDetails = peg$computePosDetails(endPos);
501
+
502
+ const res = {
503
+ source: peg$source,
504
+ start: {
505
+ offset: startPos,
506
+ line: startPosDetails.line,
507
+ column: startPosDetails.column,
508
+ },
509
+ end: {
510
+ offset: endPos,
511
+ line: endPosDetails.line,
512
+ column: endPosDetails.column,
513
+ },
514
+ };
515
+ return res;
516
+ }
517
+
518
+ function peg$fail(expected) {
519
+ if (peg$currPos < peg$maxFailPos) { return; }
520
+
521
+ if (peg$currPos > peg$maxFailPos) {
522
+ peg$maxFailPos = peg$currPos;
523
+ peg$maxFailExpected = [];
524
+ }
525
+
526
+ peg$maxFailExpected.push(expected);
527
+ }
528
+
529
+ function peg$buildStructuredError(expected, found, location) {
530
+ return new peg$SyntaxError(
531
+ peg$SyntaxError.buildMessage(expected, found),
532
+ expected,
533
+ found,
534
+ location
535
+ );
536
+ }
537
+
538
+ function peg$parseTemplatedRoot() {
539
+ let s0, s1;
540
+
541
+ const key = peg$currPos * 40 + 0;
542
+ const cached = peg$resultsCache[key];
543
+
544
+ if (cached) {
545
+ peg$currPos = cached.nextPos;
546
+
547
+ return cached.result;
548
+ }
549
+
550
+ s0 = [];
551
+ s1 = peg$parseTemplatedExpression();
552
+ while (s1 !== peg$FAILED) {
553
+ s0.push(s1);
554
+ s1 = peg$parseTemplatedExpression();
555
+ }
556
+
557
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
558
+
559
+ return s0;
560
+ }
561
+
562
+ function peg$parseTemplatedExpression() {
563
+ let s0, s1, s2, s3, s4;
564
+
565
+ const key = peg$currPos * 40 + 1;
566
+ const cached = peg$resultsCache[key];
567
+
568
+ if (cached) {
569
+ peg$currPos = cached.nextPos;
570
+
571
+ return cached.result;
572
+ }
573
+
574
+ s0 = peg$currPos;
575
+ s1 = peg$currPos;
576
+ s2 = peg$parseBeginNode();
577
+ if (s2 !== peg$FAILED) {
578
+ s3 = peg$parseExpressionRoot();
579
+ if (s3 !== peg$FAILED) {
580
+ s4 = peg$parseEndNode();
581
+ if (s4 !== peg$FAILED) {
582
+ s1 = s3;
583
+ } else {
584
+ peg$currPos = s1;
585
+ s1 = peg$FAILED;
586
+ }
587
+ } else {
588
+ peg$currPos = s1;
589
+ s1 = peg$FAILED;
590
+ }
591
+ } else {
592
+ peg$currPos = s1;
593
+ s1 = peg$FAILED;
594
+ }
595
+ if (s1 !== peg$FAILED) {
596
+ s1 = peg$f0(s1);
597
+ }
598
+ s0 = s1;
599
+ if (s0 === peg$FAILED) {
600
+ s0 = peg$currPos;
601
+ s1 = peg$currPos;
602
+ s2 = peg$parseBeginHtml();
603
+ if (s2 !== peg$FAILED) {
604
+ s3 = peg$parseExpressionRoot();
605
+ if (s3 !== peg$FAILED) {
606
+ s4 = peg$parseEndHtml();
607
+ if (s4 !== peg$FAILED) {
608
+ s1 = s3;
609
+ } else {
610
+ peg$currPos = s1;
611
+ s1 = peg$FAILED;
612
+ }
613
+ } else {
614
+ peg$currPos = s1;
615
+ s1 = peg$FAILED;
616
+ }
617
+ } else {
618
+ peg$currPos = s1;
619
+ s1 = peg$FAILED;
620
+ }
621
+ if (s1 !== peg$FAILED) {
622
+ s1 = peg$f1(s1);
623
+ }
624
+ s0 = s1;
625
+ if (s0 === peg$FAILED) {
626
+ s0 = peg$currPos;
627
+ s1 = peg$currPos;
628
+ s2 = peg$parseBeginText();
629
+ if (s2 !== peg$FAILED) {
630
+ s3 = peg$parseExpressionRoot();
631
+ if (s3 !== peg$FAILED) {
632
+ s4 = peg$parseEndText();
633
+ if (s4 !== peg$FAILED) {
634
+ s1 = s3;
635
+ } else {
636
+ peg$currPos = s1;
637
+ s1 = peg$FAILED;
638
+ }
639
+ } else {
640
+ peg$currPos = s1;
641
+ s1 = peg$FAILED;
642
+ }
643
+ } else {
644
+ peg$currPos = s1;
645
+ s1 = peg$FAILED;
646
+ }
647
+ if (s1 !== peg$FAILED) {
648
+ s1 = peg$f2(s1);
649
+ }
650
+ s0 = s1;
651
+ if (s0 === peg$FAILED) {
652
+ s0 = peg$currPos;
653
+ s1 = peg$parseTemplatedText();
654
+ if (s1 !== peg$FAILED) {
655
+ s1 = peg$f3(s1);
656
+ }
657
+ s0 = s1;
658
+ }
659
+ }
660
+ }
661
+
662
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
663
+
664
+ return s0;
665
+ }
666
+
667
+ function peg$parseBeginNode() {
668
+ let s0;
669
+
670
+ const key = peg$currPos * 40 + 2;
671
+ const cached = peg$resultsCache[key];
672
+
673
+ if (cached) {
674
+ peg$currPos = cached.nextPos;
675
+
676
+ return cached.result;
677
+ }
678
+
679
+ if (input.substr(peg$currPos, 4) === peg$c1) {
680
+ s0 = peg$c1;
681
+ peg$currPos += 4;
682
+ } else {
683
+ s0 = peg$FAILED;
684
+ if (peg$silentFails === 0) { peg$fail(peg$e0); }
685
+ }
686
+
687
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
688
+
689
+ return s0;
690
+ }
691
+
692
+ function peg$parseEndNode() {
693
+ let s0;
694
+
695
+ const key = peg$currPos * 40 + 3;
696
+ const cached = peg$resultsCache[key];
697
+
698
+ if (cached) {
699
+ peg$currPos = cached.nextPos;
700
+
701
+ return cached.result;
702
+ }
703
+
704
+ if (input.substr(peg$currPos, 4) === peg$c2) {
705
+ s0 = peg$c2;
706
+ peg$currPos += 4;
707
+ } else {
708
+ s0 = peg$FAILED;
709
+ if (peg$silentFails === 0) { peg$fail(peg$e1); }
710
+ }
711
+
712
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
713
+
714
+ return s0;
715
+ }
716
+
717
+ function peg$parseBeginHtml() {
718
+ let s0;
719
+
720
+ const key = peg$currPos * 40 + 4;
721
+ const cached = peg$resultsCache[key];
722
+
723
+ if (cached) {
724
+ peg$currPos = cached.nextPos;
725
+
726
+ return cached.result;
727
+ }
728
+
729
+ if (input.substr(peg$currPos, 3) === peg$c3) {
730
+ s0 = peg$c3;
731
+ peg$currPos += 3;
732
+ } else {
733
+ s0 = peg$FAILED;
734
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
735
+ }
736
+
737
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
738
+
739
+ return s0;
740
+ }
741
+
742
+ function peg$parseEndHtml() {
743
+ let s0;
744
+
745
+ const key = peg$currPos * 40 + 5;
746
+ const cached = peg$resultsCache[key];
747
+
748
+ if (cached) {
749
+ peg$currPos = cached.nextPos;
750
+
751
+ return cached.result;
752
+ }
753
+
754
+ if (input.substr(peg$currPos, 3) === peg$c4) {
755
+ s0 = peg$c4;
756
+ peg$currPos += 3;
757
+ } else {
758
+ s0 = peg$FAILED;
759
+ if (peg$silentFails === 0) { peg$fail(peg$e3); }
760
+ }
761
+
762
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
763
+
764
+ return s0;
765
+ }
766
+
767
+ function peg$parseBeginText() {
768
+ let s0;
769
+
770
+ const key = peg$currPos * 40 + 6;
771
+ const cached = peg$resultsCache[key];
772
+
773
+ if (cached) {
774
+ peg$currPos = cached.nextPos;
775
+
776
+ return cached.result;
777
+ }
778
+
779
+ if (input.substr(peg$currPos, 2) === peg$c5) {
780
+ s0 = peg$c5;
781
+ peg$currPos += 2;
782
+ } else {
783
+ s0 = peg$FAILED;
784
+ if (peg$silentFails === 0) { peg$fail(peg$e4); }
785
+ }
786
+
787
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
788
+
789
+ return s0;
790
+ }
791
+
792
+ function peg$parseEndText() {
793
+ let s0;
794
+
795
+ const key = peg$currPos * 40 + 7;
796
+ const cached = peg$resultsCache[key];
797
+
798
+ if (cached) {
799
+ peg$currPos = cached.nextPos;
800
+
801
+ return cached.result;
802
+ }
803
+
804
+ if (input.substr(peg$currPos, 2) === peg$c6) {
805
+ s0 = peg$c6;
806
+ peg$currPos += 2;
807
+ } else {
808
+ s0 = peg$FAILED;
809
+ if (peg$silentFails === 0) { peg$fail(peg$e5); }
810
+ }
811
+
812
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
813
+
814
+ return s0;
815
+ }
816
+
817
+ function peg$parseTemplatedText() {
818
+ let s0, s1, s2, s3, s4, s5;
819
+
820
+ const key = peg$currPos * 40 + 8;
821
+ const cached = peg$resultsCache[key];
822
+
823
+ if (cached) {
824
+ peg$currPos = cached.nextPos;
825
+
826
+ return cached.result;
827
+ }
828
+
829
+ s0 = peg$currPos;
830
+ s1 = [];
831
+ s2 = peg$currPos;
832
+ s3 = [];
833
+ s4 = input.charAt(peg$currPos);
834
+ if (peg$r0.test(s4)) {
835
+ peg$currPos++;
836
+ } else {
837
+ s4 = peg$FAILED;
838
+ if (peg$silentFails === 0) { peg$fail(peg$e6); }
839
+ }
840
+ if (s4 !== peg$FAILED) {
841
+ while (s4 !== peg$FAILED) {
842
+ s3.push(s4);
843
+ s4 = input.charAt(peg$currPos);
844
+ if (peg$r0.test(s4)) {
845
+ peg$currPos++;
846
+ } else {
847
+ s4 = peg$FAILED;
848
+ if (peg$silentFails === 0) { peg$fail(peg$e6); }
849
+ }
850
+ }
851
+ } else {
852
+ s3 = peg$FAILED;
853
+ }
854
+ if (s3 !== peg$FAILED) {
855
+ s2 = input.substring(s2, peg$currPos);
856
+ } else {
857
+ s2 = s3;
858
+ }
859
+ if (s2 === peg$FAILED) {
860
+ s2 = peg$currPos;
861
+ if (input.charCodeAt(peg$currPos) === 92) {
862
+ s3 = peg$c7;
863
+ peg$currPos++;
864
+ } else {
865
+ s3 = peg$FAILED;
866
+ if (peg$silentFails === 0) { peg$fail(peg$e7); }
867
+ }
868
+ if (s3 !== peg$FAILED) {
869
+ if (input.length > peg$currPos) {
870
+ s4 = input.charAt(peg$currPos);
871
+ peg$currPos++;
872
+ } else {
873
+ s4 = peg$FAILED;
874
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
875
+ }
876
+ if (s4 !== peg$FAILED) {
877
+ s2 = peg$f4(s4);
878
+ } else {
879
+ peg$currPos = s2;
880
+ s2 = peg$FAILED;
881
+ }
882
+ } else {
883
+ peg$currPos = s2;
884
+ s2 = peg$FAILED;
885
+ }
886
+ if (s2 === peg$FAILED) {
887
+ s2 = peg$currPos;
888
+ if (input.charCodeAt(peg$currPos) === 123) {
889
+ s3 = peg$c9;
890
+ peg$currPos++;
891
+ } else {
892
+ s3 = peg$FAILED;
893
+ if (peg$silentFails === 0) { peg$fail(peg$e9); }
894
+ }
895
+ if (s3 !== peg$FAILED) {
896
+ s4 = peg$currPos;
897
+ peg$silentFails++;
898
+ if (input.charCodeAt(peg$currPos) === 123) {
899
+ s5 = peg$c9;
900
+ peg$currPos++;
901
+ } else {
902
+ s5 = peg$FAILED;
903
+ if (peg$silentFails === 0) { peg$fail(peg$e9); }
904
+ }
905
+ peg$silentFails--;
906
+ if (s5 === peg$FAILED) {
907
+ s4 = undefined;
908
+ } else {
909
+ peg$currPos = s4;
910
+ s4 = peg$FAILED;
911
+ }
912
+ if (s4 !== peg$FAILED) {
913
+ s3 = [s3, s4];
914
+ s2 = s3;
915
+ } else {
916
+ peg$currPos = s2;
917
+ s2 = peg$FAILED;
918
+ }
919
+ } else {
920
+ peg$currPos = s2;
921
+ s2 = peg$FAILED;
922
+ }
923
+ }
924
+ }
925
+ if (s2 !== peg$FAILED) {
926
+ while (s2 !== peg$FAILED) {
927
+ s1.push(s2);
928
+ s2 = peg$currPos;
929
+ s3 = [];
930
+ s4 = input.charAt(peg$currPos);
931
+ if (peg$r0.test(s4)) {
932
+ peg$currPos++;
933
+ } else {
934
+ s4 = peg$FAILED;
935
+ if (peg$silentFails === 0) { peg$fail(peg$e6); }
936
+ }
937
+ if (s4 !== peg$FAILED) {
938
+ while (s4 !== peg$FAILED) {
939
+ s3.push(s4);
940
+ s4 = input.charAt(peg$currPos);
941
+ if (peg$r0.test(s4)) {
942
+ peg$currPos++;
943
+ } else {
944
+ s4 = peg$FAILED;
945
+ if (peg$silentFails === 0) { peg$fail(peg$e6); }
946
+ }
947
+ }
948
+ } else {
949
+ s3 = peg$FAILED;
950
+ }
951
+ if (s3 !== peg$FAILED) {
952
+ s2 = input.substring(s2, peg$currPos);
953
+ } else {
954
+ s2 = s3;
955
+ }
956
+ if (s2 === peg$FAILED) {
957
+ s2 = peg$currPos;
958
+ if (input.charCodeAt(peg$currPos) === 92) {
959
+ s3 = peg$c7;
960
+ peg$currPos++;
961
+ } else {
962
+ s3 = peg$FAILED;
963
+ if (peg$silentFails === 0) { peg$fail(peg$e7); }
964
+ }
965
+ if (s3 !== peg$FAILED) {
966
+ if (input.length > peg$currPos) {
967
+ s4 = input.charAt(peg$currPos);
968
+ peg$currPos++;
969
+ } else {
970
+ s4 = peg$FAILED;
971
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
972
+ }
973
+ if (s4 !== peg$FAILED) {
974
+ s2 = peg$f4(s4);
975
+ } else {
976
+ peg$currPos = s2;
977
+ s2 = peg$FAILED;
978
+ }
979
+ } else {
980
+ peg$currPos = s2;
981
+ s2 = peg$FAILED;
982
+ }
983
+ if (s2 === peg$FAILED) {
984
+ s2 = peg$currPos;
985
+ if (input.charCodeAt(peg$currPos) === 123) {
986
+ s3 = peg$c9;
987
+ peg$currPos++;
988
+ } else {
989
+ s3 = peg$FAILED;
990
+ if (peg$silentFails === 0) { peg$fail(peg$e9); }
991
+ }
992
+ if (s3 !== peg$FAILED) {
993
+ s4 = peg$currPos;
994
+ peg$silentFails++;
995
+ if (input.charCodeAt(peg$currPos) === 123) {
996
+ s5 = peg$c9;
997
+ peg$currPos++;
998
+ } else {
999
+ s5 = peg$FAILED;
1000
+ if (peg$silentFails === 0) { peg$fail(peg$e9); }
1001
+ }
1002
+ peg$silentFails--;
1003
+ if (s5 === peg$FAILED) {
1004
+ s4 = undefined;
1005
+ } else {
1006
+ peg$currPos = s4;
1007
+ s4 = peg$FAILED;
1008
+ }
1009
+ if (s4 !== peg$FAILED) {
1010
+ s3 = [s3, s4];
1011
+ s2 = s3;
1012
+ } else {
1013
+ peg$currPos = s2;
1014
+ s2 = peg$FAILED;
1015
+ }
1016
+ } else {
1017
+ peg$currPos = s2;
1018
+ s2 = peg$FAILED;
1019
+ }
1020
+ }
1021
+ }
1022
+ }
1023
+ } else {
1024
+ s1 = peg$FAILED;
1025
+ }
1026
+ if (s1 !== peg$FAILED) {
1027
+ s1 = peg$f5(s1);
1028
+ }
1029
+ s0 = s1;
1030
+
1031
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1032
+
1033
+ return s0;
1034
+ }
1035
+
1036
+ function peg$parseExpressionRoot() {
1037
+ let s0, s2;
1038
+
1039
+ const key = peg$currPos * 40 + 9;
1040
+ const cached = peg$resultsCache[key];
1041
+
1042
+ if (cached) {
1043
+ peg$currPos = cached.nextPos;
1044
+
1045
+ return cached.result;
1046
+ }
1047
+
1048
+ s0 = peg$currPos;
1049
+ peg$parse_();
1050
+ s2 = peg$parseTernaryExpression();
1051
+ if (s2 !== peg$FAILED) {
1052
+ peg$parse_();
1053
+ s0 = peg$f6(s2);
1054
+ } else {
1055
+ peg$currPos = s0;
1056
+ s0 = peg$FAILED;
1057
+ }
1058
+
1059
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1060
+
1061
+ return s0;
1062
+ }
1063
+
1064
+ function peg$parseTernaryExpression() {
1065
+ let s0, s1, s3, s5, s7, s9;
1066
+
1067
+ const key = peg$currPos * 40 + 10;
1068
+ const cached = peg$resultsCache[key];
1069
+
1070
+ if (cached) {
1071
+ peg$currPos = cached.nextPos;
1072
+
1073
+ return cached.result;
1074
+ }
1075
+
1076
+ s0 = peg$currPos;
1077
+ s1 = peg$parseElvisExpression();
1078
+ if (s1 !== peg$FAILED) {
1079
+ peg$parse_();
1080
+ if (input.charCodeAt(peg$currPos) === 63) {
1081
+ s3 = peg$c13;
1082
+ peg$currPos++;
1083
+ } else {
1084
+ s3 = peg$FAILED;
1085
+ if (peg$silentFails === 0) { peg$fail(peg$e10); }
1086
+ }
1087
+ if (s3 !== peg$FAILED) {
1088
+ peg$parse_();
1089
+ s5 = peg$parseTernaryExpression();
1090
+ if (s5 !== peg$FAILED) {
1091
+ peg$parse_();
1092
+ if (input.charCodeAt(peg$currPos) === 58) {
1093
+ s7 = peg$c15;
1094
+ peg$currPos++;
1095
+ } else {
1096
+ s7 = peg$FAILED;
1097
+ if (peg$silentFails === 0) { peg$fail(peg$e11); }
1098
+ }
1099
+ if (s7 !== peg$FAILED) {
1100
+ peg$parse_();
1101
+ s9 = peg$parseTernaryExpression();
1102
+ if (s9 !== peg$FAILED) {
1103
+ s0 = peg$f7(s1, s5, s9);
1104
+ } else {
1105
+ peg$currPos = s0;
1106
+ s0 = peg$FAILED;
1107
+ }
1108
+ } else {
1109
+ peg$currPos = s0;
1110
+ s0 = peg$FAILED;
1111
+ }
1112
+ } else {
1113
+ peg$currPos = s0;
1114
+ s0 = peg$FAILED;
1115
+ }
1116
+ } else {
1117
+ peg$currPos = s0;
1118
+ s0 = peg$FAILED;
1119
+ }
1120
+ } else {
1121
+ peg$currPos = s0;
1122
+ s0 = peg$FAILED;
1123
+ }
1124
+ if (s0 === peg$FAILED) {
1125
+ s0 = peg$parseElvisExpression();
1126
+ }
1127
+
1128
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1129
+
1130
+ return s0;
1131
+ }
1132
+
1133
+ function peg$parseElvisExpression() {
1134
+ let s0, s1, s3, s5;
1135
+
1136
+ const key = peg$currPos * 40 + 11;
1137
+ const cached = peg$resultsCache[key];
1138
+
1139
+ if (cached) {
1140
+ peg$currPos = cached.nextPos;
1141
+
1142
+ return cached.result;
1143
+ }
1144
+
1145
+ s0 = peg$currPos;
1146
+ s1 = peg$parseNullCoalescingExpression();
1147
+ if (s1 !== peg$FAILED) {
1148
+ peg$parse_();
1149
+ if (input.substr(peg$currPos, 2) === peg$c17) {
1150
+ s3 = peg$c17;
1151
+ peg$currPos += 2;
1152
+ } else {
1153
+ s3 = peg$FAILED;
1154
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
1155
+ }
1156
+ if (s3 !== peg$FAILED) {
1157
+ peg$parse_();
1158
+ s5 = peg$parseElvisExpression();
1159
+ if (s5 !== peg$FAILED) {
1160
+ s0 = peg$f8(s1, s5);
1161
+ } else {
1162
+ peg$currPos = s0;
1163
+ s0 = peg$FAILED;
1164
+ }
1165
+ } else {
1166
+ peg$currPos = s0;
1167
+ s0 = peg$FAILED;
1168
+ }
1169
+ } else {
1170
+ peg$currPos = s0;
1171
+ s0 = peg$FAILED;
1172
+ }
1173
+ if (s0 === peg$FAILED) {
1174
+ s0 = peg$parseNullCoalescingExpression();
1175
+ }
1176
+
1177
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1178
+
1179
+ return s0;
1180
+ }
1181
+
1182
+ function peg$parseNullCoalescingExpression() {
1183
+ let s0, s1, s3, s5;
1184
+
1185
+ const key = peg$currPos * 40 + 12;
1186
+ const cached = peg$resultsCache[key];
1187
+
1188
+ if (cached) {
1189
+ peg$currPos = cached.nextPos;
1190
+
1191
+ return cached.result;
1192
+ }
1193
+
1194
+ s0 = peg$currPos;
1195
+ s1 = peg$parseOrExpression();
1196
+ if (s1 !== peg$FAILED) {
1197
+ peg$parse_();
1198
+ if (input.substr(peg$currPos, 2) === peg$c19) {
1199
+ s3 = peg$c19;
1200
+ peg$currPos += 2;
1201
+ } else {
1202
+ s3 = peg$FAILED;
1203
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
1204
+ }
1205
+ if (s3 !== peg$FAILED) {
1206
+ peg$parse_();
1207
+ s5 = peg$parseNullCoalescingExpression();
1208
+ if (s5 !== peg$FAILED) {
1209
+ s0 = peg$f9(s1, s5);
1210
+ } else {
1211
+ peg$currPos = s0;
1212
+ s0 = peg$FAILED;
1213
+ }
1214
+ } else {
1215
+ peg$currPos = s0;
1216
+ s0 = peg$FAILED;
1217
+ }
1218
+ } else {
1219
+ peg$currPos = s0;
1220
+ s0 = peg$FAILED;
1221
+ }
1222
+ if (s0 === peg$FAILED) {
1223
+ s0 = peg$parseOrExpression();
1224
+ }
1225
+
1226
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1227
+
1228
+ return s0;
1229
+ }
1230
+
1231
+ function peg$parseOrExpression() {
1232
+ let s0, s1, s2, s3, s5, s7;
1233
+
1234
+ const key = peg$currPos * 40 + 13;
1235
+ const cached = peg$resultsCache[key];
1236
+
1237
+ if (cached) {
1238
+ peg$currPos = cached.nextPos;
1239
+
1240
+ return cached.result;
1241
+ }
1242
+
1243
+ s0 = peg$currPos;
1244
+ s1 = peg$parseAndExpression();
1245
+ if (s1 !== peg$FAILED) {
1246
+ s2 = [];
1247
+ s3 = peg$currPos;
1248
+ peg$parse_();
1249
+ if (input.substr(peg$currPos, 2) === peg$c22) {
1250
+ s5 = peg$c22;
1251
+ peg$currPos += 2;
1252
+ } else {
1253
+ s5 = peg$FAILED;
1254
+ if (peg$silentFails === 0) { peg$fail(peg$e14); }
1255
+ }
1256
+ if (s5 !== peg$FAILED) {
1257
+ peg$parse_();
1258
+ s7 = peg$parseAndExpression();
1259
+ if (s7 !== peg$FAILED) {
1260
+ s3 = s7;
1261
+ } else {
1262
+ peg$currPos = s3;
1263
+ s3 = peg$FAILED;
1264
+ }
1265
+ } else {
1266
+ peg$currPos = s3;
1267
+ s3 = peg$FAILED;
1268
+ }
1269
+ while (s3 !== peg$FAILED) {
1270
+ s2.push(s3);
1271
+ s3 = peg$currPos;
1272
+ peg$parse_();
1273
+ if (input.substr(peg$currPos, 2) === peg$c22) {
1274
+ s5 = peg$c22;
1275
+ peg$currPos += 2;
1276
+ } else {
1277
+ s5 = peg$FAILED;
1278
+ if (peg$silentFails === 0) { peg$fail(peg$e14); }
1279
+ }
1280
+ if (s5 !== peg$FAILED) {
1281
+ peg$parse_();
1282
+ s7 = peg$parseAndExpression();
1283
+ if (s7 !== peg$FAILED) {
1284
+ s3 = s7;
1285
+ } else {
1286
+ peg$currPos = s3;
1287
+ s3 = peg$FAILED;
1288
+ }
1289
+ } else {
1290
+ peg$currPos = s3;
1291
+ s3 = peg$FAILED;
1292
+ }
1293
+ }
1294
+ s0 = peg$f10(s1, s2);
1295
+ } else {
1296
+ peg$currPos = s0;
1297
+ s0 = peg$FAILED;
1298
+ }
1299
+
1300
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1301
+
1302
+ return s0;
1303
+ }
1304
+
1305
+ function peg$parseAndExpression() {
1306
+ let s0, s1, s2, s3, s5, s7;
1307
+
1308
+ const key = peg$currPos * 40 + 14;
1309
+ const cached = peg$resultsCache[key];
1310
+
1311
+ if (cached) {
1312
+ peg$currPos = cached.nextPos;
1313
+
1314
+ return cached.result;
1315
+ }
1316
+
1317
+ s0 = peg$currPos;
1318
+ s1 = peg$parseEqExpression();
1319
+ if (s1 !== peg$FAILED) {
1320
+ s2 = [];
1321
+ s3 = peg$currPos;
1322
+ peg$parse_();
1323
+ if (input.substr(peg$currPos, 2) === peg$c24) {
1324
+ s5 = peg$c24;
1325
+ peg$currPos += 2;
1326
+ } else {
1327
+ s5 = peg$FAILED;
1328
+ if (peg$silentFails === 0) { peg$fail(peg$e15); }
1329
+ }
1330
+ if (s5 !== peg$FAILED) {
1331
+ peg$parse_();
1332
+ s7 = peg$parseEqExpression();
1333
+ if (s7 !== peg$FAILED) {
1334
+ s3 = s7;
1335
+ } else {
1336
+ peg$currPos = s3;
1337
+ s3 = peg$FAILED;
1338
+ }
1339
+ } else {
1340
+ peg$currPos = s3;
1341
+ s3 = peg$FAILED;
1342
+ }
1343
+ while (s3 !== peg$FAILED) {
1344
+ s2.push(s3);
1345
+ s3 = peg$currPos;
1346
+ peg$parse_();
1347
+ if (input.substr(peg$currPos, 2) === peg$c24) {
1348
+ s5 = peg$c24;
1349
+ peg$currPos += 2;
1350
+ } else {
1351
+ s5 = peg$FAILED;
1352
+ if (peg$silentFails === 0) { peg$fail(peg$e15); }
1353
+ }
1354
+ if (s5 !== peg$FAILED) {
1355
+ peg$parse_();
1356
+ s7 = peg$parseEqExpression();
1357
+ if (s7 !== peg$FAILED) {
1358
+ s3 = s7;
1359
+ } else {
1360
+ peg$currPos = s3;
1361
+ s3 = peg$FAILED;
1362
+ }
1363
+ } else {
1364
+ peg$currPos = s3;
1365
+ s3 = peg$FAILED;
1366
+ }
1367
+ }
1368
+ s0 = peg$f11(s1, s2);
1369
+ } else {
1370
+ peg$currPos = s0;
1371
+ s0 = peg$FAILED;
1372
+ }
1373
+
1374
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1375
+
1376
+ return s0;
1377
+ }
1378
+
1379
+ function peg$parseEqExpression() {
1380
+ let s0, s1, s2, s3, s5, s7;
1381
+
1382
+ const key = peg$currPos * 40 + 15;
1383
+ const cached = peg$resultsCache[key];
1384
+
1385
+ if (cached) {
1386
+ peg$currPos = cached.nextPos;
1387
+
1388
+ return cached.result;
1389
+ }
1390
+
1391
+ s0 = peg$currPos;
1392
+ s1 = peg$parseRelExpression();
1393
+ if (s1 !== peg$FAILED) {
1394
+ s2 = [];
1395
+ s3 = peg$currPos;
1396
+ peg$parse_();
1397
+ s5 = peg$parseEqualityOp();
1398
+ if (s5 !== peg$FAILED) {
1399
+ peg$parse_();
1400
+ s7 = peg$parseRelExpression();
1401
+ if (s7 !== peg$FAILED) {
1402
+ s3 = peg$f12(s1, s5, s7);
1403
+ } else {
1404
+ peg$currPos = s3;
1405
+ s3 = peg$FAILED;
1406
+ }
1407
+ } else {
1408
+ peg$currPos = s3;
1409
+ s3 = peg$FAILED;
1410
+ }
1411
+ while (s3 !== peg$FAILED) {
1412
+ s2.push(s3);
1413
+ s3 = peg$currPos;
1414
+ peg$parse_();
1415
+ s5 = peg$parseEqualityOp();
1416
+ if (s5 !== peg$FAILED) {
1417
+ peg$parse_();
1418
+ s7 = peg$parseRelExpression();
1419
+ if (s7 !== peg$FAILED) {
1420
+ s3 = peg$f12(s1, s5, s7);
1421
+ } else {
1422
+ peg$currPos = s3;
1423
+ s3 = peg$FAILED;
1424
+ }
1425
+ } else {
1426
+ peg$currPos = s3;
1427
+ s3 = peg$FAILED;
1428
+ }
1429
+ }
1430
+ s0 = peg$f13(s1, s2);
1431
+ } else {
1432
+ peg$currPos = s0;
1433
+ s0 = peg$FAILED;
1434
+ }
1435
+
1436
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1437
+
1438
+ return s0;
1439
+ }
1440
+
1441
+ function peg$parseRelExpression() {
1442
+ let s0, s1, s2, s3, s5, s7;
1443
+
1444
+ const key = peg$currPos * 40 + 16;
1445
+ const cached = peg$resultsCache[key];
1446
+
1447
+ if (cached) {
1448
+ peg$currPos = cached.nextPos;
1449
+
1450
+ return cached.result;
1451
+ }
1452
+
1453
+ s0 = peg$currPos;
1454
+ s1 = peg$parseNotExpression();
1455
+ if (s1 !== peg$FAILED) {
1456
+ s2 = [];
1457
+ s3 = peg$currPos;
1458
+ peg$parse_();
1459
+ s5 = peg$parseRelationalOp();
1460
+ if (s5 !== peg$FAILED) {
1461
+ peg$parse_();
1462
+ s7 = peg$parseNotExpression();
1463
+ if (s7 !== peg$FAILED) {
1464
+ s3 = peg$f14(s1, s5, s7);
1465
+ } else {
1466
+ peg$currPos = s3;
1467
+ s3 = peg$FAILED;
1468
+ }
1469
+ } else {
1470
+ peg$currPos = s3;
1471
+ s3 = peg$FAILED;
1472
+ }
1473
+ while (s3 !== peg$FAILED) {
1474
+ s2.push(s3);
1475
+ s3 = peg$currPos;
1476
+ peg$parse_();
1477
+ s5 = peg$parseRelationalOp();
1478
+ if (s5 !== peg$FAILED) {
1479
+ peg$parse_();
1480
+ s7 = peg$parseNotExpression();
1481
+ if (s7 !== peg$FAILED) {
1482
+ s3 = peg$f14(s1, s5, s7);
1483
+ } else {
1484
+ peg$currPos = s3;
1485
+ s3 = peg$FAILED;
1486
+ }
1487
+ } else {
1488
+ peg$currPos = s3;
1489
+ s3 = peg$FAILED;
1490
+ }
1491
+ }
1492
+ s0 = peg$f15(s1, s2);
1493
+ } else {
1494
+ peg$currPos = s0;
1495
+ s0 = peg$FAILED;
1496
+ }
1497
+
1498
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1499
+
1500
+ return s0;
1501
+ }
1502
+
1503
+ function peg$parseNotExpression() {
1504
+ let s0, s1, s3;
1505
+
1506
+ const key = peg$currPos * 40 + 17;
1507
+ const cached = peg$resultsCache[key];
1508
+
1509
+ if (cached) {
1510
+ peg$currPos = cached.nextPos;
1511
+
1512
+ return cached.result;
1513
+ }
1514
+
1515
+ s0 = peg$currPos;
1516
+ if (input.charCodeAt(peg$currPos) === 33) {
1517
+ s1 = peg$c26;
1518
+ peg$currPos++;
1519
+ } else {
1520
+ s1 = peg$FAILED;
1521
+ if (peg$silentFails === 0) { peg$fail(peg$e16); }
1522
+ }
1523
+ if (s1 !== peg$FAILED) {
1524
+ peg$parse_();
1525
+ s3 = peg$parseNotExpression();
1526
+ if (s3 !== peg$FAILED) {
1527
+ s0 = peg$f16(s3);
1528
+ } else {
1529
+ peg$currPos = s0;
1530
+ s0 = peg$FAILED;
1531
+ }
1532
+ } else {
1533
+ peg$currPos = s0;
1534
+ s0 = peg$FAILED;
1535
+ }
1536
+ if (s0 === peg$FAILED) {
1537
+ s0 = peg$parseAccess();
1538
+ }
1539
+
1540
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1541
+
1542
+ return s0;
1543
+ }
1544
+
1545
+ function peg$parseAccess() {
1546
+ let s0, s1, s3, s4, s5;
1547
+
1548
+ const key = peg$currPos * 40 + 18;
1549
+ const cached = peg$resultsCache[key];
1550
+
1551
+ if (cached) {
1552
+ peg$currPos = cached.nextPos;
1553
+
1554
+ return cached.result;
1555
+ }
1556
+
1557
+ s0 = peg$currPos;
1558
+ s1 = peg$parseGroupingExpression();
1559
+ if (s1 !== peg$FAILED) {
1560
+ peg$parse_();
1561
+ s3 = [];
1562
+ s4 = peg$currPos;
1563
+ s5 = peg$parseAccessExpression();
1564
+ if (s5 !== peg$FAILED) {
1565
+ peg$parse_();
1566
+ s4 = s5;
1567
+ } else {
1568
+ peg$currPos = s4;
1569
+ s4 = peg$FAILED;
1570
+ }
1571
+ if (s4 !== peg$FAILED) {
1572
+ while (s4 !== peg$FAILED) {
1573
+ s3.push(s4);
1574
+ s4 = peg$currPos;
1575
+ s5 = peg$parseAccessExpression();
1576
+ if (s5 !== peg$FAILED) {
1577
+ peg$parse_();
1578
+ s4 = s5;
1579
+ } else {
1580
+ peg$currPos = s4;
1581
+ s4 = peg$FAILED;
1582
+ }
1583
+ }
1584
+ } else {
1585
+ s3 = peg$FAILED;
1586
+ }
1587
+ if (s3 !== peg$FAILED) {
1588
+ s0 = peg$f17(s1, s3);
1589
+ } else {
1590
+ peg$currPos = s0;
1591
+ s0 = peg$FAILED;
1592
+ }
1593
+ } else {
1594
+ peg$currPos = s0;
1595
+ s0 = peg$FAILED;
1596
+ }
1597
+ if (s0 === peg$FAILED) {
1598
+ s0 = peg$parseGroupingExpression();
1599
+ }
1600
+
1601
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1602
+
1603
+ return s0;
1604
+ }
1605
+
1606
+ function peg$parseAccessExpression() {
1607
+ let s0;
1608
+
1609
+ const key = peg$currPos * 40 + 19;
1610
+ const cached = peg$resultsCache[key];
1611
+
1612
+ if (cached) {
1613
+ peg$currPos = cached.nextPos;
1614
+
1615
+ return cached.result;
1616
+ }
1617
+
1618
+ s0 = peg$parseAccessMember();
1619
+ if (s0 === peg$FAILED) {
1620
+ s0 = peg$parseAccessSubscript();
1621
+ if (s0 === peg$FAILED) {
1622
+ s0 = peg$parseAccessMethodCall();
1623
+ }
1624
+ }
1625
+
1626
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1627
+
1628
+ return s0;
1629
+ }
1630
+
1631
+ function peg$parseAccessMember() {
1632
+ let s0, s1, s3;
1633
+
1634
+ const key = peg$currPos * 40 + 20;
1635
+ const cached = peg$resultsCache[key];
1636
+
1637
+ if (cached) {
1638
+ peg$currPos = cached.nextPos;
1639
+
1640
+ return cached.result;
1641
+ }
1642
+
1643
+ peg$silentFails++;
1644
+ s0 = peg$currPos;
1645
+ if (input.substr(peg$currPos, 2) === peg$c28) {
1646
+ s1 = peg$c28;
1647
+ peg$currPos += 2;
1648
+ } else {
1649
+ s1 = peg$FAILED;
1650
+ if (peg$silentFails === 0) { peg$fail(peg$e18); }
1651
+ }
1652
+ if (s1 === peg$FAILED) {
1653
+ if (input.charCodeAt(peg$currPos) === 46) {
1654
+ s1 = peg$c29;
1655
+ peg$currPos++;
1656
+ } else {
1657
+ s1 = peg$FAILED;
1658
+ if (peg$silentFails === 0) { peg$fail(peg$e19); }
1659
+ }
1660
+ }
1661
+ if (s1 !== peg$FAILED) {
1662
+ peg$parse_();
1663
+ s3 = peg$parseSymbol();
1664
+ if (s3 !== peg$FAILED) {
1665
+ s0 = peg$f18(s1, s3);
1666
+ } else {
1667
+ peg$currPos = s0;
1668
+ s0 = peg$FAILED;
1669
+ }
1670
+ } else {
1671
+ peg$currPos = s0;
1672
+ s0 = peg$FAILED;
1673
+ }
1674
+ peg$silentFails--;
1675
+ if (s0 === peg$FAILED) {
1676
+ s1 = peg$FAILED;
1677
+ if (peg$silentFails === 0) { peg$fail(peg$e17); }
1678
+ }
1679
+
1680
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1681
+
1682
+ return s0;
1683
+ }
1684
+
1685
+ function peg$parseAccessSubscript() {
1686
+ let s0, s1, s2, s4, s6;
1687
+
1688
+ const key = peg$currPos * 40 + 21;
1689
+ const cached = peg$resultsCache[key];
1690
+
1691
+ if (cached) {
1692
+ peg$currPos = cached.nextPos;
1693
+
1694
+ return cached.result;
1695
+ }
1696
+
1697
+ peg$silentFails++;
1698
+ s0 = peg$currPos;
1699
+ if (input.substr(peg$currPos, 2) === peg$c28) {
1700
+ s1 = peg$c28;
1701
+ peg$currPos += 2;
1702
+ } else {
1703
+ s1 = peg$FAILED;
1704
+ if (peg$silentFails === 0) { peg$fail(peg$e18); }
1705
+ }
1706
+ if (s1 === peg$FAILED) {
1707
+ s1 = null;
1708
+ }
1709
+ if (input.charCodeAt(peg$currPos) === 91) {
1710
+ s2 = peg$c30;
1711
+ peg$currPos++;
1712
+ } else {
1713
+ s2 = peg$FAILED;
1714
+ if (peg$silentFails === 0) { peg$fail(peg$e21); }
1715
+ }
1716
+ if (s2 !== peg$FAILED) {
1717
+ peg$parse_();
1718
+ s4 = peg$parseTernaryExpression();
1719
+ if (s4 !== peg$FAILED) {
1720
+ peg$parse_();
1721
+ if (input.charCodeAt(peg$currPos) === 93) {
1722
+ s6 = peg$c31;
1723
+ peg$currPos++;
1724
+ } else {
1725
+ s6 = peg$FAILED;
1726
+ if (peg$silentFails === 0) { peg$fail(peg$e22); }
1727
+ }
1728
+ if (s6 !== peg$FAILED) {
1729
+ s0 = peg$f19(s1, s4);
1730
+ } else {
1731
+ peg$currPos = s0;
1732
+ s0 = peg$FAILED;
1733
+ }
1734
+ } else {
1735
+ peg$currPos = s0;
1736
+ s0 = peg$FAILED;
1737
+ }
1738
+ } else {
1739
+ peg$currPos = s0;
1740
+ s0 = peg$FAILED;
1741
+ }
1742
+ peg$silentFails--;
1743
+ if (s0 === peg$FAILED) {
1744
+ s1 = peg$FAILED;
1745
+ if (peg$silentFails === 0) { peg$fail(peg$e20); }
1746
+ }
1747
+
1748
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1749
+
1750
+ return s0;
1751
+ }
1752
+
1753
+ function peg$parseAccessMethodCall() {
1754
+ let s0, s1, s2, s4, s5, s6, s7, s9;
1755
+
1756
+ const key = peg$currPos * 40 + 22;
1757
+ const cached = peg$resultsCache[key];
1758
+
1759
+ if (cached) {
1760
+ peg$currPos = cached.nextPos;
1761
+
1762
+ return cached.result;
1763
+ }
1764
+
1765
+ peg$silentFails++;
1766
+ s0 = peg$currPos;
1767
+ if (input.substr(peg$currPos, 2) === peg$c28) {
1768
+ s1 = peg$c28;
1769
+ peg$currPos += 2;
1770
+ } else {
1771
+ s1 = peg$FAILED;
1772
+ if (peg$silentFails === 0) { peg$fail(peg$e18); }
1773
+ }
1774
+ if (s1 === peg$FAILED) {
1775
+ s1 = null;
1776
+ }
1777
+ if (input.charCodeAt(peg$currPos) === 40) {
1778
+ s2 = peg$c32;
1779
+ peg$currPos++;
1780
+ } else {
1781
+ s2 = peg$FAILED;
1782
+ if (peg$silentFails === 0) { peg$fail(peg$e24); }
1783
+ }
1784
+ if (s2 !== peg$FAILED) {
1785
+ peg$parse_();
1786
+ s4 = peg$currPos;
1787
+ s5 = peg$parseTernaryExpression();
1788
+ if (s5 !== peg$FAILED) {
1789
+ s6 = peg$parse_();
1790
+ s4 = s5;
1791
+ } else {
1792
+ peg$currPos = s4;
1793
+ s4 = peg$FAILED;
1794
+ }
1795
+ if (s4 === peg$FAILED) {
1796
+ s4 = null;
1797
+ }
1798
+ s5 = [];
1799
+ s6 = peg$currPos;
1800
+ if (input.charCodeAt(peg$currPos) === 44) {
1801
+ s7 = peg$c34;
1802
+ peg$currPos++;
1803
+ } else {
1804
+ s7 = peg$FAILED;
1805
+ if (peg$silentFails === 0) { peg$fail(peg$e25); }
1806
+ }
1807
+ if (s7 !== peg$FAILED) {
1808
+ peg$parse_();
1809
+ s9 = peg$parseTernaryExpression();
1810
+ if (s9 !== peg$FAILED) {
1811
+ peg$parse_();
1812
+ s6 = s9;
1813
+ } else {
1814
+ peg$currPos = s6;
1815
+ s6 = peg$FAILED;
1816
+ }
1817
+ } else {
1818
+ peg$currPos = s6;
1819
+ s6 = peg$FAILED;
1820
+ }
1821
+ while (s6 !== peg$FAILED) {
1822
+ s5.push(s6);
1823
+ s6 = peg$currPos;
1824
+ if (input.charCodeAt(peg$currPos) === 44) {
1825
+ s7 = peg$c34;
1826
+ peg$currPos++;
1827
+ } else {
1828
+ s7 = peg$FAILED;
1829
+ if (peg$silentFails === 0) { peg$fail(peg$e25); }
1830
+ }
1831
+ if (s7 !== peg$FAILED) {
1832
+ peg$parse_();
1833
+ s9 = peg$parseTernaryExpression();
1834
+ if (s9 !== peg$FAILED) {
1835
+ peg$parse_();
1836
+ s6 = s9;
1837
+ } else {
1838
+ peg$currPos = s6;
1839
+ s6 = peg$FAILED;
1840
+ }
1841
+ } else {
1842
+ peg$currPos = s6;
1843
+ s6 = peg$FAILED;
1844
+ }
1845
+ }
1846
+ if (input.charCodeAt(peg$currPos) === 41) {
1847
+ s6 = peg$c36;
1848
+ peg$currPos++;
1849
+ } else {
1850
+ s6 = peg$FAILED;
1851
+ if (peg$silentFails === 0) { peg$fail(peg$e26); }
1852
+ }
1853
+ if (s6 !== peg$FAILED) {
1854
+ s0 = peg$f20(s1, s4, s5);
1855
+ } else {
1856
+ peg$currPos = s0;
1857
+ s0 = peg$FAILED;
1858
+ }
1859
+ } else {
1860
+ peg$currPos = s0;
1861
+ s0 = peg$FAILED;
1862
+ }
1863
+ peg$silentFails--;
1864
+ if (s0 === peg$FAILED) {
1865
+ s1 = peg$FAILED;
1866
+ if (peg$silentFails === 0) { peg$fail(peg$e23); }
1867
+ }
1868
+
1869
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1870
+
1871
+ return s0;
1872
+ }
1873
+
1874
+ function peg$parseGroupingExpression() {
1875
+ let s0, s1, s3, s5;
1876
+
1877
+ const key = peg$currPos * 40 + 23;
1878
+ const cached = peg$resultsCache[key];
1879
+
1880
+ if (cached) {
1881
+ peg$currPos = cached.nextPos;
1882
+
1883
+ return cached.result;
1884
+ }
1885
+
1886
+ s0 = peg$currPos;
1887
+ if (input.charCodeAt(peg$currPos) === 40) {
1888
+ s1 = peg$c32;
1889
+ peg$currPos++;
1890
+ } else {
1891
+ s1 = peg$FAILED;
1892
+ if (peg$silentFails === 0) { peg$fail(peg$e24); }
1893
+ }
1894
+ if (s1 !== peg$FAILED) {
1895
+ peg$parse_();
1896
+ s3 = peg$parseTernaryExpression();
1897
+ if (s3 !== peg$FAILED) {
1898
+ peg$parse_();
1899
+ if (input.charCodeAt(peg$currPos) === 41) {
1900
+ s5 = peg$c36;
1901
+ peg$currPos++;
1902
+ } else {
1903
+ s5 = peg$FAILED;
1904
+ if (peg$silentFails === 0) { peg$fail(peg$e26); }
1905
+ }
1906
+ if (s5 !== peg$FAILED) {
1907
+ s0 = peg$f21(s3);
1908
+ } else {
1909
+ peg$currPos = s0;
1910
+ s0 = peg$FAILED;
1911
+ }
1912
+ } else {
1913
+ peg$currPos = s0;
1914
+ s0 = peg$FAILED;
1915
+ }
1916
+ } else {
1917
+ peg$currPos = s0;
1918
+ s0 = peg$FAILED;
1919
+ }
1920
+ if (s0 === peg$FAILED) {
1921
+ s0 = peg$parseModuleFunctionCall();
1922
+ if (s0 === peg$FAILED) {
1923
+ s0 = peg$parseAnyLiteral();
1924
+ if (s0 === peg$FAILED) {
1925
+ s0 = peg$parseSymbol();
1926
+ }
1927
+ }
1928
+ }
1929
+
1930
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1931
+
1932
+ return s0;
1933
+ }
1934
+
1935
+ function peg$parseModuleFunctionCall() {
1936
+ let s0, s1, s2, s4, s5, s6, s7, s9;
1937
+
1938
+ const key = peg$currPos * 40 + 24;
1939
+ const cached = peg$resultsCache[key];
1940
+
1941
+ if (cached) {
1942
+ peg$currPos = cached.nextPos;
1943
+
1944
+ return cached.result;
1945
+ }
1946
+
1947
+ peg$silentFails++;
1948
+ s0 = peg$currPos;
1949
+ s1 = peg$parseModuleFunction();
1950
+ if (s1 !== peg$FAILED) {
1951
+ if (input.charCodeAt(peg$currPos) === 40) {
1952
+ s2 = peg$c32;
1953
+ peg$currPos++;
1954
+ } else {
1955
+ s2 = peg$FAILED;
1956
+ if (peg$silentFails === 0) { peg$fail(peg$e24); }
1957
+ }
1958
+ if (s2 !== peg$FAILED) {
1959
+ peg$parse_();
1960
+ s4 = peg$currPos;
1961
+ s5 = peg$parseTernaryExpression();
1962
+ if (s5 !== peg$FAILED) {
1963
+ s6 = peg$parse_();
1964
+ s4 = s5;
1965
+ } else {
1966
+ peg$currPos = s4;
1967
+ s4 = peg$FAILED;
1968
+ }
1969
+ if (s4 === peg$FAILED) {
1970
+ s4 = null;
1971
+ }
1972
+ s5 = [];
1973
+ s6 = peg$currPos;
1974
+ if (input.charCodeAt(peg$currPos) === 44) {
1975
+ s7 = peg$c34;
1976
+ peg$currPos++;
1977
+ } else {
1978
+ s7 = peg$FAILED;
1979
+ if (peg$silentFails === 0) { peg$fail(peg$e25); }
1980
+ }
1981
+ if (s7 !== peg$FAILED) {
1982
+ peg$parse_();
1983
+ s9 = peg$parseTernaryExpression();
1984
+ if (s9 !== peg$FAILED) {
1985
+ peg$parse_();
1986
+ s6 = s9;
1987
+ } else {
1988
+ peg$currPos = s6;
1989
+ s6 = peg$FAILED;
1990
+ }
1991
+ } else {
1992
+ peg$currPos = s6;
1993
+ s6 = peg$FAILED;
1994
+ }
1995
+ while (s6 !== peg$FAILED) {
1996
+ s5.push(s6);
1997
+ s6 = peg$currPos;
1998
+ if (input.charCodeAt(peg$currPos) === 44) {
1999
+ s7 = peg$c34;
2000
+ peg$currPos++;
2001
+ } else {
2002
+ s7 = peg$FAILED;
2003
+ if (peg$silentFails === 0) { peg$fail(peg$e25); }
2004
+ }
2005
+ if (s7 !== peg$FAILED) {
2006
+ peg$parse_();
2007
+ s9 = peg$parseTernaryExpression();
2008
+ if (s9 !== peg$FAILED) {
2009
+ peg$parse_();
2010
+ s6 = s9;
2011
+ } else {
2012
+ peg$currPos = s6;
2013
+ s6 = peg$FAILED;
2014
+ }
2015
+ } else {
2016
+ peg$currPos = s6;
2017
+ s6 = peg$FAILED;
2018
+ }
2019
+ }
2020
+ if (input.charCodeAt(peg$currPos) === 41) {
2021
+ s6 = peg$c36;
2022
+ peg$currPos++;
2023
+ } else {
2024
+ s6 = peg$FAILED;
2025
+ if (peg$silentFails === 0) { peg$fail(peg$e26); }
2026
+ }
2027
+ if (s6 !== peg$FAILED) {
2028
+ s0 = peg$f22(s1, s4, s5);
2029
+ } else {
2030
+ peg$currPos = s0;
2031
+ s0 = peg$FAILED;
2032
+ }
2033
+ } else {
2034
+ peg$currPos = s0;
2035
+ s0 = peg$FAILED;
2036
+ }
2037
+ } else {
2038
+ peg$currPos = s0;
2039
+ s0 = peg$FAILED;
2040
+ }
2041
+ peg$silentFails--;
2042
+ if (s0 === peg$FAILED) {
2043
+ s1 = peg$FAILED;
2044
+ if (peg$silentFails === 0) { peg$fail(peg$e27); }
2045
+ }
2046
+
2047
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2048
+
2049
+ return s0;
2050
+ }
2051
+
2052
+ function peg$parseAnyLiteral() {
2053
+ let s0;
2054
+
2055
+ const key = peg$currPos * 40 + 25;
2056
+ const cached = peg$resultsCache[key];
2057
+
2058
+ if (cached) {
2059
+ peg$currPos = cached.nextPos;
2060
+
2061
+ return cached.result;
2062
+ }
2063
+
2064
+ s0 = peg$parseNumberLiteral();
2065
+ if (s0 === peg$FAILED) {
2066
+ s0 = peg$parseBooleanLiteral();
2067
+ if (s0 === peg$FAILED) {
2068
+ s0 = peg$parseNullLiteral();
2069
+ if (s0 === peg$FAILED) {
2070
+ s0 = peg$parseUndefinedLiteral();
2071
+ if (s0 === peg$FAILED) {
2072
+ s0 = peg$parseStringLiteral();
2073
+ if (s0 === peg$FAILED) {
2074
+ s0 = peg$parseArrayLiteral();
2075
+ if (s0 === peg$FAILED) {
2076
+ s0 = peg$parseDictLiteral();
2077
+ }
2078
+ }
2079
+ }
2080
+ }
2081
+ }
2082
+ }
2083
+
2084
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2085
+
2086
+ return s0;
2087
+ }
2088
+
2089
+ function peg$parseBooleanLiteral() {
2090
+ let s0, s1;
2091
+
2092
+ const key = peg$currPos * 40 + 26;
2093
+ const cached = peg$resultsCache[key];
2094
+
2095
+ if (cached) {
2096
+ peg$currPos = cached.nextPos;
2097
+
2098
+ return cached.result;
2099
+ }
2100
+
2101
+ peg$silentFails++;
2102
+ s0 = peg$currPos;
2103
+ if (input.substr(peg$currPos, 4) === peg$c39) {
2104
+ s1 = peg$c39;
2105
+ peg$currPos += 4;
2106
+ } else {
2107
+ s1 = peg$FAILED;
2108
+ if (peg$silentFails === 0) { peg$fail(peg$e29); }
2109
+ }
2110
+ if (s1 !== peg$FAILED) {
2111
+ s1 = peg$f23();
2112
+ }
2113
+ s0 = s1;
2114
+ if (s0 === peg$FAILED) {
2115
+ s0 = peg$currPos;
2116
+ if (input.substr(peg$currPos, 5) === peg$c40) {
2117
+ s1 = peg$c40;
2118
+ peg$currPos += 5;
2119
+ } else {
2120
+ s1 = peg$FAILED;
2121
+ if (peg$silentFails === 0) { peg$fail(peg$e30); }
2122
+ }
2123
+ if (s1 !== peg$FAILED) {
2124
+ s1 = peg$f24();
2125
+ }
2126
+ s0 = s1;
2127
+ }
2128
+ peg$silentFails--;
2129
+ if (s0 === peg$FAILED) {
2130
+ s1 = peg$FAILED;
2131
+ if (peg$silentFails === 0) { peg$fail(peg$e28); }
2132
+ }
2133
+
2134
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2135
+
2136
+ return s0;
2137
+ }
2138
+
2139
+ function peg$parseNullLiteral() {
2140
+ let s0, s1;
2141
+
2142
+ const key = peg$currPos * 40 + 27;
2143
+ const cached = peg$resultsCache[key];
2144
+
2145
+ if (cached) {
2146
+ peg$currPos = cached.nextPos;
2147
+
2148
+ return cached.result;
2149
+ }
2150
+
2151
+ peg$silentFails++;
2152
+ s0 = peg$currPos;
2153
+ if (input.substr(peg$currPos, 4) === peg$c41) {
2154
+ s1 = peg$c41;
2155
+ peg$currPos += 4;
2156
+ } else {
2157
+ s1 = peg$FAILED;
2158
+ if (peg$silentFails === 0) { peg$fail(peg$e32); }
2159
+ }
2160
+ if (s1 !== peg$FAILED) {
2161
+ s1 = peg$f25();
2162
+ }
2163
+ s0 = s1;
2164
+ peg$silentFails--;
2165
+ if (s0 === peg$FAILED) {
2166
+ s1 = peg$FAILED;
2167
+ if (peg$silentFails === 0) { peg$fail(peg$e31); }
2168
+ }
2169
+
2170
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2171
+
2172
+ return s0;
2173
+ }
2174
+
2175
+ function peg$parseUndefinedLiteral() {
2176
+ let s0, s1;
2177
+
2178
+ const key = peg$currPos * 40 + 28;
2179
+ const cached = peg$resultsCache[key];
2180
+
2181
+ if (cached) {
2182
+ peg$currPos = cached.nextPos;
2183
+
2184
+ return cached.result;
2185
+ }
2186
+
2187
+ peg$silentFails++;
2188
+ s0 = peg$currPos;
2189
+ if (input.substr(peg$currPos, 9) === peg$c42) {
2190
+ s1 = peg$c42;
2191
+ peg$currPos += 9;
2192
+ } else {
2193
+ s1 = peg$FAILED;
2194
+ if (peg$silentFails === 0) { peg$fail(peg$e34); }
2195
+ }
2196
+ if (s1 !== peg$FAILED) {
2197
+ s1 = peg$f26();
2198
+ }
2199
+ s0 = s1;
2200
+ peg$silentFails--;
2201
+ if (s0 === peg$FAILED) {
2202
+ s1 = peg$FAILED;
2203
+ if (peg$silentFails === 0) { peg$fail(peg$e33); }
2204
+ }
2205
+
2206
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2207
+
2208
+ return s0;
2209
+ }
2210
+
2211
+ function peg$parseNumberLiteral() {
2212
+ let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
2213
+
2214
+ const key = peg$currPos * 40 + 29;
2215
+ const cached = peg$resultsCache[key];
2216
+
2217
+ if (cached) {
2218
+ peg$currPos = cached.nextPos;
2219
+
2220
+ return cached.result;
2221
+ }
2222
+
2223
+ peg$silentFails++;
2224
+ s0 = peg$currPos;
2225
+ s1 = peg$currPos;
2226
+ s2 = peg$currPos;
2227
+ if (input.charCodeAt(peg$currPos) === 45) {
2228
+ s3 = peg$c43;
2229
+ peg$currPos++;
2230
+ } else {
2231
+ s3 = peg$FAILED;
2232
+ if (peg$silentFails === 0) { peg$fail(peg$e36); }
2233
+ }
2234
+ if (s3 === peg$FAILED) {
2235
+ s3 = null;
2236
+ }
2237
+ s4 = peg$currPos;
2238
+ s5 = [];
2239
+ s6 = input.charAt(peg$currPos);
2240
+ if (peg$r1.test(s6)) {
2241
+ peg$currPos++;
2242
+ } else {
2243
+ s6 = peg$FAILED;
2244
+ if (peg$silentFails === 0) { peg$fail(peg$e37); }
2245
+ }
2246
+ if (s6 !== peg$FAILED) {
2247
+ while (s6 !== peg$FAILED) {
2248
+ s5.push(s6);
2249
+ s6 = input.charAt(peg$currPos);
2250
+ if (peg$r1.test(s6)) {
2251
+ peg$currPos++;
2252
+ } else {
2253
+ s6 = peg$FAILED;
2254
+ if (peg$silentFails === 0) { peg$fail(peg$e37); }
2255
+ }
2256
+ }
2257
+ } else {
2258
+ s5 = peg$FAILED;
2259
+ }
2260
+ if (s5 !== peg$FAILED) {
2261
+ s6 = peg$currPos;
2262
+ if (input.charCodeAt(peg$currPos) === 46) {
2263
+ s7 = peg$c29;
2264
+ peg$currPos++;
2265
+ } else {
2266
+ s7 = peg$FAILED;
2267
+ if (peg$silentFails === 0) { peg$fail(peg$e19); }
2268
+ }
2269
+ if (s7 !== peg$FAILED) {
2270
+ s8 = [];
2271
+ s9 = input.charAt(peg$currPos);
2272
+ if (peg$r1.test(s9)) {
2273
+ peg$currPos++;
2274
+ } else {
2275
+ s9 = peg$FAILED;
2276
+ if (peg$silentFails === 0) { peg$fail(peg$e37); }
2277
+ }
2278
+ while (s9 !== peg$FAILED) {
2279
+ s8.push(s9);
2280
+ s9 = input.charAt(peg$currPos);
2281
+ if (peg$r1.test(s9)) {
2282
+ peg$currPos++;
2283
+ } else {
2284
+ s9 = peg$FAILED;
2285
+ if (peg$silentFails === 0) { peg$fail(peg$e37); }
2286
+ }
2287
+ }
2288
+ s7 = [s7, s8];
2289
+ s6 = s7;
2290
+ } else {
2291
+ peg$currPos = s6;
2292
+ s6 = peg$FAILED;
2293
+ }
2294
+ if (s6 === peg$FAILED) {
2295
+ s6 = null;
2296
+ }
2297
+ s5 = [s5, s6];
2298
+ s4 = s5;
2299
+ } else {
2300
+ peg$currPos = s4;
2301
+ s4 = peg$FAILED;
2302
+ }
2303
+ if (s4 === peg$FAILED) {
2304
+ s4 = peg$currPos;
2305
+ if (input.charCodeAt(peg$currPos) === 46) {
2306
+ s5 = peg$c29;
2307
+ peg$currPos++;
2308
+ } else {
2309
+ s5 = peg$FAILED;
2310
+ if (peg$silentFails === 0) { peg$fail(peg$e19); }
2311
+ }
2312
+ if (s5 !== peg$FAILED) {
2313
+ s6 = [];
2314
+ s7 = input.charAt(peg$currPos);
2315
+ if (peg$r1.test(s7)) {
2316
+ peg$currPos++;
2317
+ } else {
2318
+ s7 = peg$FAILED;
2319
+ if (peg$silentFails === 0) { peg$fail(peg$e37); }
2320
+ }
2321
+ if (s7 !== peg$FAILED) {
2322
+ while (s7 !== peg$FAILED) {
2323
+ s6.push(s7);
2324
+ s7 = input.charAt(peg$currPos);
2325
+ if (peg$r1.test(s7)) {
2326
+ peg$currPos++;
2327
+ } else {
2328
+ s7 = peg$FAILED;
2329
+ if (peg$silentFails === 0) { peg$fail(peg$e37); }
2330
+ }
2331
+ }
2332
+ } else {
2333
+ s6 = peg$FAILED;
2334
+ }
2335
+ if (s6 !== peg$FAILED) {
2336
+ s5 = [s5, s6];
2337
+ s4 = s5;
2338
+ } else {
2339
+ peg$currPos = s4;
2340
+ s4 = peg$FAILED;
2341
+ }
2342
+ } else {
2343
+ peg$currPos = s4;
2344
+ s4 = peg$FAILED;
2345
+ }
2346
+ }
2347
+ if (s4 !== peg$FAILED) {
2348
+ s3 = [s3, s4];
2349
+ s2 = s3;
2350
+ } else {
2351
+ peg$currPos = s2;
2352
+ s2 = peg$FAILED;
2353
+ }
2354
+ if (s2 !== peg$FAILED) {
2355
+ s1 = input.substring(s1, peg$currPos);
2356
+ } else {
2357
+ s1 = s2;
2358
+ }
2359
+ if (s1 !== peg$FAILED) {
2360
+ s1 = peg$f27(s1);
2361
+ }
2362
+ s0 = s1;
2363
+ peg$silentFails--;
2364
+ if (s0 === peg$FAILED) {
2365
+ s1 = peg$FAILED;
2366
+ if (peg$silentFails === 0) { peg$fail(peg$e35); }
2367
+ }
2368
+
2369
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2370
+
2371
+ return s0;
2372
+ }
2373
+
2374
+ function peg$parseStringLiteral() {
2375
+ let s0, s1, s2, s3, s4;
2376
+
2377
+ const key = peg$currPos * 40 + 30;
2378
+ const cached = peg$resultsCache[key];
2379
+
2380
+ if (cached) {
2381
+ peg$currPos = cached.nextPos;
2382
+
2383
+ return cached.result;
2384
+ }
2385
+
2386
+ peg$silentFails++;
2387
+ s0 = peg$currPos;
2388
+ if (input.charCodeAt(peg$currPos) === 39) {
2389
+ s1 = peg$c44;
2390
+ peg$currPos++;
2391
+ } else {
2392
+ s1 = peg$FAILED;
2393
+ if (peg$silentFails === 0) { peg$fail(peg$e39); }
2394
+ }
2395
+ if (s1 !== peg$FAILED) {
2396
+ s2 = peg$currPos;
2397
+ s3 = [];
2398
+ s4 = input.charAt(peg$currPos);
2399
+ if (peg$r2.test(s4)) {
2400
+ peg$currPos++;
2401
+ } else {
2402
+ s4 = peg$FAILED;
2403
+ if (peg$silentFails === 0) { peg$fail(peg$e40); }
2404
+ }
2405
+ while (s4 !== peg$FAILED) {
2406
+ s3.push(s4);
2407
+ s4 = input.charAt(peg$currPos);
2408
+ if (peg$r2.test(s4)) {
2409
+ peg$currPos++;
2410
+ } else {
2411
+ s4 = peg$FAILED;
2412
+ if (peg$silentFails === 0) { peg$fail(peg$e40); }
2413
+ }
2414
+ }
2415
+ s2 = input.substring(s2, peg$currPos);
2416
+ if (input.charCodeAt(peg$currPos) === 39) {
2417
+ s3 = peg$c44;
2418
+ peg$currPos++;
2419
+ } else {
2420
+ s3 = peg$FAILED;
2421
+ if (peg$silentFails === 0) { peg$fail(peg$e39); }
2422
+ }
2423
+ if (s3 !== peg$FAILED) {
2424
+ s0 = peg$f28(s2);
2425
+ } else {
2426
+ peg$currPos = s0;
2427
+ s0 = peg$FAILED;
2428
+ }
2429
+ } else {
2430
+ peg$currPos = s0;
2431
+ s0 = peg$FAILED;
2432
+ }
2433
+ if (s0 === peg$FAILED) {
2434
+ s0 = peg$currPos;
2435
+ if (input.charCodeAt(peg$currPos) === 34) {
2436
+ s1 = peg$c45;
2437
+ peg$currPos++;
2438
+ } else {
2439
+ s1 = peg$FAILED;
2440
+ if (peg$silentFails === 0) { peg$fail(peg$e41); }
2441
+ }
2442
+ if (s1 !== peg$FAILED) {
2443
+ s2 = peg$currPos;
2444
+ s3 = [];
2445
+ s4 = input.charAt(peg$currPos);
2446
+ if (peg$r3.test(s4)) {
2447
+ peg$currPos++;
2448
+ } else {
2449
+ s4 = peg$FAILED;
2450
+ if (peg$silentFails === 0) { peg$fail(peg$e42); }
2451
+ }
2452
+ while (s4 !== peg$FAILED) {
2453
+ s3.push(s4);
2454
+ s4 = input.charAt(peg$currPos);
2455
+ if (peg$r3.test(s4)) {
2456
+ peg$currPos++;
2457
+ } else {
2458
+ s4 = peg$FAILED;
2459
+ if (peg$silentFails === 0) { peg$fail(peg$e42); }
2460
+ }
2461
+ }
2462
+ s2 = input.substring(s2, peg$currPos);
2463
+ if (input.charCodeAt(peg$currPos) === 34) {
2464
+ s3 = peg$c45;
2465
+ peg$currPos++;
2466
+ } else {
2467
+ s3 = peg$FAILED;
2468
+ if (peg$silentFails === 0) { peg$fail(peg$e41); }
2469
+ }
2470
+ if (s3 !== peg$FAILED) {
2471
+ s0 = peg$f29(s2);
2472
+ } else {
2473
+ peg$currPos = s0;
2474
+ s0 = peg$FAILED;
2475
+ }
2476
+ } else {
2477
+ peg$currPos = s0;
2478
+ s0 = peg$FAILED;
2479
+ }
2480
+ if (s0 === peg$FAILED) {
2481
+ s0 = peg$currPos;
2482
+ if (input.charCodeAt(peg$currPos) === 96) {
2483
+ s1 = peg$c46;
2484
+ peg$currPos++;
2485
+ } else {
2486
+ s1 = peg$FAILED;
2487
+ if (peg$silentFails === 0) { peg$fail(peg$e43); }
2488
+ }
2489
+ if (s1 !== peg$FAILED) {
2490
+ s2 = [];
2491
+ s3 = peg$parseTemplateStringExpression();
2492
+ if (s3 === peg$FAILED) {
2493
+ s3 = peg$parseTemplateStringLiteral();
2494
+ }
2495
+ while (s3 !== peg$FAILED) {
2496
+ s2.push(s3);
2497
+ s3 = peg$parseTemplateStringExpression();
2498
+ if (s3 === peg$FAILED) {
2499
+ s3 = peg$parseTemplateStringLiteral();
2500
+ }
2501
+ }
2502
+ if (input.charCodeAt(peg$currPos) === 96) {
2503
+ s3 = peg$c46;
2504
+ peg$currPos++;
2505
+ } else {
2506
+ s3 = peg$FAILED;
2507
+ if (peg$silentFails === 0) { peg$fail(peg$e43); }
2508
+ }
2509
+ if (s3 !== peg$FAILED) {
2510
+ s0 = peg$f30(s2);
2511
+ } else {
2512
+ peg$currPos = s0;
2513
+ s0 = peg$FAILED;
2514
+ }
2515
+ } else {
2516
+ peg$currPos = s0;
2517
+ s0 = peg$FAILED;
2518
+ }
2519
+ }
2520
+ }
2521
+ peg$silentFails--;
2522
+ if (s0 === peg$FAILED) {
2523
+ s1 = peg$FAILED;
2524
+ if (peg$silentFails === 0) { peg$fail(peg$e38); }
2525
+ }
2526
+
2527
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2528
+
2529
+ return s0;
2530
+ }
2531
+
2532
+ function peg$parseTemplateStringExpression() {
2533
+ let s0, s1, s3, s5;
2534
+
2535
+ const key = peg$currPos * 40 + 31;
2536
+ const cached = peg$resultsCache[key];
2537
+
2538
+ if (cached) {
2539
+ peg$currPos = cached.nextPos;
2540
+
2541
+ return cached.result;
2542
+ }
2543
+
2544
+ peg$silentFails++;
2545
+ s0 = peg$currPos;
2546
+ if (input.charCodeAt(peg$currPos) === 123) {
2547
+ s1 = peg$c9;
2548
+ peg$currPos++;
2549
+ } else {
2550
+ s1 = peg$FAILED;
2551
+ if (peg$silentFails === 0) { peg$fail(peg$e9); }
2552
+ }
2553
+ if (s1 !== peg$FAILED) {
2554
+ peg$parse_();
2555
+ s3 = peg$parseTernaryExpression();
2556
+ if (s3 !== peg$FAILED) {
2557
+ peg$parse_();
2558
+ if (input.charCodeAt(peg$currPos) === 125) {
2559
+ s5 = peg$c47;
2560
+ peg$currPos++;
2561
+ } else {
2562
+ s5 = peg$FAILED;
2563
+ if (peg$silentFails === 0) { peg$fail(peg$e45); }
2564
+ }
2565
+ if (s5 !== peg$FAILED) {
2566
+ s0 = peg$f31(s3);
2567
+ } else {
2568
+ peg$currPos = s0;
2569
+ s0 = peg$FAILED;
2570
+ }
2571
+ } else {
2572
+ peg$currPos = s0;
2573
+ s0 = peg$FAILED;
2574
+ }
2575
+ } else {
2576
+ peg$currPos = s0;
2577
+ s0 = peg$FAILED;
2578
+ }
2579
+ peg$silentFails--;
2580
+ if (s0 === peg$FAILED) {
2581
+ s1 = peg$FAILED;
2582
+ if (peg$silentFails === 0) { peg$fail(peg$e44); }
2583
+ }
2584
+
2585
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2586
+
2587
+ return s0;
2588
+ }
2589
+
2590
+ function peg$parseTemplateStringLiteral() {
2591
+ let s0, s1, s2, s3, s4;
2592
+
2593
+ const key = peg$currPos * 40 + 32;
2594
+ const cached = peg$resultsCache[key];
2595
+
2596
+ if (cached) {
2597
+ peg$currPos = cached.nextPos;
2598
+
2599
+ return cached.result;
2600
+ }
2601
+
2602
+ peg$silentFails++;
2603
+ s0 = peg$currPos;
2604
+ s1 = [];
2605
+ s2 = peg$currPos;
2606
+ s3 = [];
2607
+ s4 = input.charAt(peg$currPos);
2608
+ if (peg$r4.test(s4)) {
2609
+ peg$currPos++;
2610
+ } else {
2611
+ s4 = peg$FAILED;
2612
+ if (peg$silentFails === 0) { peg$fail(peg$e47); }
2613
+ }
2614
+ if (s4 !== peg$FAILED) {
2615
+ while (s4 !== peg$FAILED) {
2616
+ s3.push(s4);
2617
+ s4 = input.charAt(peg$currPos);
2618
+ if (peg$r4.test(s4)) {
2619
+ peg$currPos++;
2620
+ } else {
2621
+ s4 = peg$FAILED;
2622
+ if (peg$silentFails === 0) { peg$fail(peg$e47); }
2623
+ }
2624
+ }
2625
+ } else {
2626
+ s3 = peg$FAILED;
2627
+ }
2628
+ if (s3 !== peg$FAILED) {
2629
+ s2 = input.substring(s2, peg$currPos);
2630
+ } else {
2631
+ s2 = s3;
2632
+ }
2633
+ if (s2 === peg$FAILED) {
2634
+ s2 = peg$currPos;
2635
+ if (input.charCodeAt(peg$currPos) === 92) {
2636
+ s3 = peg$c7;
2637
+ peg$currPos++;
2638
+ } else {
2639
+ s3 = peg$FAILED;
2640
+ if (peg$silentFails === 0) { peg$fail(peg$e7); }
2641
+ }
2642
+ if (s3 !== peg$FAILED) {
2643
+ if (input.length > peg$currPos) {
2644
+ s4 = input.charAt(peg$currPos);
2645
+ peg$currPos++;
2646
+ } else {
2647
+ s4 = peg$FAILED;
2648
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
2649
+ }
2650
+ if (s4 !== peg$FAILED) {
2651
+ s2 = peg$f32(s4);
2652
+ } else {
2653
+ peg$currPos = s2;
2654
+ s2 = peg$FAILED;
2655
+ }
2656
+ } else {
2657
+ peg$currPos = s2;
2658
+ s2 = peg$FAILED;
2659
+ }
2660
+ }
2661
+ if (s2 !== peg$FAILED) {
2662
+ while (s2 !== peg$FAILED) {
2663
+ s1.push(s2);
2664
+ s2 = peg$currPos;
2665
+ s3 = [];
2666
+ s4 = input.charAt(peg$currPos);
2667
+ if (peg$r4.test(s4)) {
2668
+ peg$currPos++;
2669
+ } else {
2670
+ s4 = peg$FAILED;
2671
+ if (peg$silentFails === 0) { peg$fail(peg$e47); }
2672
+ }
2673
+ if (s4 !== peg$FAILED) {
2674
+ while (s4 !== peg$FAILED) {
2675
+ s3.push(s4);
2676
+ s4 = input.charAt(peg$currPos);
2677
+ if (peg$r4.test(s4)) {
2678
+ peg$currPos++;
2679
+ } else {
2680
+ s4 = peg$FAILED;
2681
+ if (peg$silentFails === 0) { peg$fail(peg$e47); }
2682
+ }
2683
+ }
2684
+ } else {
2685
+ s3 = peg$FAILED;
2686
+ }
2687
+ if (s3 !== peg$FAILED) {
2688
+ s2 = input.substring(s2, peg$currPos);
2689
+ } else {
2690
+ s2 = s3;
2691
+ }
2692
+ if (s2 === peg$FAILED) {
2693
+ s2 = peg$currPos;
2694
+ if (input.charCodeAt(peg$currPos) === 92) {
2695
+ s3 = peg$c7;
2696
+ peg$currPos++;
2697
+ } else {
2698
+ s3 = peg$FAILED;
2699
+ if (peg$silentFails === 0) { peg$fail(peg$e7); }
2700
+ }
2701
+ if (s3 !== peg$FAILED) {
2702
+ if (input.length > peg$currPos) {
2703
+ s4 = input.charAt(peg$currPos);
2704
+ peg$currPos++;
2705
+ } else {
2706
+ s4 = peg$FAILED;
2707
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
2708
+ }
2709
+ if (s4 !== peg$FAILED) {
2710
+ s2 = peg$f32(s4);
2711
+ } else {
2712
+ peg$currPos = s2;
2713
+ s2 = peg$FAILED;
2714
+ }
2715
+ } else {
2716
+ peg$currPos = s2;
2717
+ s2 = peg$FAILED;
2718
+ }
2719
+ }
2720
+ }
2721
+ } else {
2722
+ s1 = peg$FAILED;
2723
+ }
2724
+ if (s1 !== peg$FAILED) {
2725
+ s1 = peg$f33(s1);
2726
+ }
2727
+ s0 = s1;
2728
+ if (s0 === peg$FAILED) {
2729
+ s0 = peg$currPos;
2730
+ if (input.charCodeAt(peg$currPos) === 123) {
2731
+ s1 = peg$c9;
2732
+ peg$currPos++;
2733
+ } else {
2734
+ s1 = peg$FAILED;
2735
+ if (peg$silentFails === 0) { peg$fail(peg$e9); }
2736
+ }
2737
+ if (s1 !== peg$FAILED) {
2738
+ s1 = peg$f34(s1);
2739
+ }
2740
+ s0 = s1;
2741
+ }
2742
+ peg$silentFails--;
2743
+ if (s0 === peg$FAILED) {
2744
+ s1 = peg$FAILED;
2745
+ if (peg$silentFails === 0) { peg$fail(peg$e46); }
2746
+ }
2747
+
2748
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2749
+
2750
+ return s0;
2751
+ }
2752
+
2753
+ function peg$parseArrayLiteral() {
2754
+ let s0, s1, s3, s5, s6, s7, s9;
2755
+
2756
+ const key = peg$currPos * 40 + 33;
2757
+ const cached = peg$resultsCache[key];
2758
+
2759
+ if (cached) {
2760
+ peg$currPos = cached.nextPos;
2761
+
2762
+ return cached.result;
2763
+ }
2764
+
2765
+ peg$silentFails++;
2766
+ s0 = peg$currPos;
2767
+ if (input.charCodeAt(peg$currPos) === 91) {
2768
+ s1 = peg$c30;
2769
+ peg$currPos++;
2770
+ } else {
2771
+ s1 = peg$FAILED;
2772
+ if (peg$silentFails === 0) { peg$fail(peg$e21); }
2773
+ }
2774
+ if (s1 !== peg$FAILED) {
2775
+ peg$parse_();
2776
+ s3 = peg$parseTernaryExpression();
2777
+ if (s3 === peg$FAILED) {
2778
+ s3 = null;
2779
+ }
2780
+ peg$parse_();
2781
+ s5 = [];
2782
+ s6 = peg$currPos;
2783
+ if (input.charCodeAt(peg$currPos) === 44) {
2784
+ s7 = peg$c34;
2785
+ peg$currPos++;
2786
+ } else {
2787
+ s7 = peg$FAILED;
2788
+ if (peg$silentFails === 0) { peg$fail(peg$e25); }
2789
+ }
2790
+ if (s7 !== peg$FAILED) {
2791
+ peg$parse_();
2792
+ s9 = peg$parseTernaryExpression();
2793
+ if (s9 !== peg$FAILED) {
2794
+ peg$parse_();
2795
+ s6 = s9;
2796
+ } else {
2797
+ peg$currPos = s6;
2798
+ s6 = peg$FAILED;
2799
+ }
2800
+ } else {
2801
+ peg$currPos = s6;
2802
+ s6 = peg$FAILED;
2803
+ }
2804
+ while (s6 !== peg$FAILED) {
2805
+ s5.push(s6);
2806
+ s6 = peg$currPos;
2807
+ if (input.charCodeAt(peg$currPos) === 44) {
2808
+ s7 = peg$c34;
2809
+ peg$currPos++;
2810
+ } else {
2811
+ s7 = peg$FAILED;
2812
+ if (peg$silentFails === 0) { peg$fail(peg$e25); }
2813
+ }
2814
+ if (s7 !== peg$FAILED) {
2815
+ peg$parse_();
2816
+ s9 = peg$parseTernaryExpression();
2817
+ if (s9 !== peg$FAILED) {
2818
+ peg$parse_();
2819
+ s6 = s9;
2820
+ } else {
2821
+ peg$currPos = s6;
2822
+ s6 = peg$FAILED;
2823
+ }
2824
+ } else {
2825
+ peg$currPos = s6;
2826
+ s6 = peg$FAILED;
2827
+ }
2828
+ }
2829
+ if (input.charCodeAt(peg$currPos) === 93) {
2830
+ s6 = peg$c31;
2831
+ peg$currPos++;
2832
+ } else {
2833
+ s6 = peg$FAILED;
2834
+ if (peg$silentFails === 0) { peg$fail(peg$e22); }
2835
+ }
2836
+ if (s6 !== peg$FAILED) {
2837
+ s0 = peg$f35(s3, s5);
2838
+ } else {
2839
+ peg$currPos = s0;
2840
+ s0 = peg$FAILED;
2841
+ }
2842
+ } else {
2843
+ peg$currPos = s0;
2844
+ s0 = peg$FAILED;
2845
+ }
2846
+ peg$silentFails--;
2847
+ if (s0 === peg$FAILED) {
2848
+ s1 = peg$FAILED;
2849
+ if (peg$silentFails === 0) { peg$fail(peg$e48); }
2850
+ }
2851
+
2852
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
2853
+
2854
+ return s0;
2855
+ }
2856
+
2857
+ function peg$parseDictLiteral() {
2858
+ let s0, s1, s3, s4, s5, s6, s7, s8, s9, s11, s13;
2859
+
2860
+ const key = peg$currPos * 40 + 34;
2861
+ const cached = peg$resultsCache[key];
2862
+
2863
+ if (cached) {
2864
+ peg$currPos = cached.nextPos;
2865
+
2866
+ return cached.result;
2867
+ }
2868
+
2869
+ peg$silentFails++;
2870
+ s0 = peg$currPos;
2871
+ if (input.charCodeAt(peg$currPos) === 123) {
2872
+ s1 = peg$c9;
2873
+ peg$currPos++;
2874
+ } else {
2875
+ s1 = peg$FAILED;
2876
+ if (peg$silentFails === 0) { peg$fail(peg$e9); }
2877
+ }
2878
+ if (s1 !== peg$FAILED) {
2879
+ peg$parse_();
2880
+ s3 = peg$currPos;
2881
+ s4 = peg$parseStringLiteral();
2882
+ if (s4 !== peg$FAILED) {
2883
+ s5 = peg$parse_();
2884
+ if (input.charCodeAt(peg$currPos) === 58) {
2885
+ s6 = peg$c15;
2886
+ peg$currPos++;
2887
+ } else {
2888
+ s6 = peg$FAILED;
2889
+ if (peg$silentFails === 0) { peg$fail(peg$e11); }
2890
+ }
2891
+ if (s6 !== peg$FAILED) {
2892
+ s7 = peg$parse_();
2893
+ s8 = peg$parseTernaryExpression();
2894
+ if (s8 !== peg$FAILED) {
2895
+ s3 = [ s4, s8 ];
2896
+ } else {
2897
+ peg$currPos = s3;
2898
+ s3 = peg$FAILED;
2899
+ }
2900
+ } else {
2901
+ peg$currPos = s3;
2902
+ s3 = peg$FAILED;
2903
+ }
2904
+ } else {
2905
+ peg$currPos = s3;
2906
+ s3 = peg$FAILED;
2907
+ }
2908
+ if (s3 === peg$FAILED) {
2909
+ s3 = null;
2910
+ }
2911
+ s4 = peg$parse_();
2912
+ s5 = [];
2913
+ s6 = peg$currPos;
2914
+ if (input.charCodeAt(peg$currPos) === 44) {
2915
+ s7 = peg$c34;
2916
+ peg$currPos++;
2917
+ } else {
2918
+ s7 = peg$FAILED;
2919
+ if (peg$silentFails === 0) { peg$fail(peg$e25); }
2920
+ }
2921
+ if (s7 !== peg$FAILED) {
2922
+ s8 = peg$parse_();
2923
+ s9 = peg$parseStringLiteral();
2924
+ if (s9 !== peg$FAILED) {
2925
+ peg$parse_();
2926
+ if (input.charCodeAt(peg$currPos) === 58) {
2927
+ s11 = peg$c15;
2928
+ peg$currPos++;
2929
+ } else {
2930
+ s11 = peg$FAILED;
2931
+ if (peg$silentFails === 0) { peg$fail(peg$e11); }
2932
+ }
2933
+ if (s11 !== peg$FAILED) {
2934
+ peg$parse_();
2935
+ s13 = peg$parseTernaryExpression();
2936
+ if (s13 !== peg$FAILED) {
2937
+ peg$parse_();
2938
+ s6 = [ s9, s13 ];
2939
+ } else {
2940
+ peg$currPos = s6;
2941
+ s6 = peg$FAILED;
2942
+ }
2943
+ } else {
2944
+ peg$currPos = s6;
2945
+ s6 = peg$FAILED;
2946
+ }
2947
+ } else {
2948
+ peg$currPos = s6;
2949
+ s6 = peg$FAILED;
2950
+ }
2951
+ } else {
2952
+ peg$currPos = s6;
2953
+ s6 = peg$FAILED;
2954
+ }
2955
+ while (s6 !== peg$FAILED) {
2956
+ s5.push(s6);
2957
+ s6 = peg$currPos;
2958
+ if (input.charCodeAt(peg$currPos) === 44) {
2959
+ s7 = peg$c34;
2960
+ peg$currPos++;
2961
+ } else {
2962
+ s7 = peg$FAILED;
2963
+ if (peg$silentFails === 0) { peg$fail(peg$e25); }
2964
+ }
2965
+ if (s7 !== peg$FAILED) {
2966
+ s8 = peg$parse_();
2967
+ s9 = peg$parseStringLiteral();
2968
+ if (s9 !== peg$FAILED) {
2969
+ peg$parse_();
2970
+ if (input.charCodeAt(peg$currPos) === 58) {
2971
+ s11 = peg$c15;
2972
+ peg$currPos++;
2973
+ } else {
2974
+ s11 = peg$FAILED;
2975
+ if (peg$silentFails === 0) { peg$fail(peg$e11); }
2976
+ }
2977
+ if (s11 !== peg$FAILED) {
2978
+ peg$parse_();
2979
+ s13 = peg$parseTernaryExpression();
2980
+ if (s13 !== peg$FAILED) {
2981
+ peg$parse_();
2982
+ s6 = [ s9, s13 ];
2983
+ } else {
2984
+ peg$currPos = s6;
2985
+ s6 = peg$FAILED;
2986
+ }
2987
+ } else {
2988
+ peg$currPos = s6;
2989
+ s6 = peg$FAILED;
2990
+ }
2991
+ } else {
2992
+ peg$currPos = s6;
2993
+ s6 = peg$FAILED;
2994
+ }
2995
+ } else {
2996
+ peg$currPos = s6;
2997
+ s6 = peg$FAILED;
2998
+ }
2999
+ }
3000
+ if (input.charCodeAt(peg$currPos) === 125) {
3001
+ s6 = peg$c47;
3002
+ peg$currPos++;
3003
+ } else {
3004
+ s6 = peg$FAILED;
3005
+ if (peg$silentFails === 0) { peg$fail(peg$e45); }
3006
+ }
3007
+ if (s6 !== peg$FAILED) {
3008
+ s0 = peg$f36(s3, s5);
3009
+ } else {
3010
+ peg$currPos = s0;
3011
+ s0 = peg$FAILED;
3012
+ }
3013
+ } else {
3014
+ peg$currPos = s0;
3015
+ s0 = peg$FAILED;
3016
+ }
3017
+ peg$silentFails--;
3018
+ if (s0 === peg$FAILED) {
3019
+ s1 = peg$FAILED;
3020
+ if (peg$silentFails === 0) { peg$fail(peg$e49); }
3021
+ }
3022
+
3023
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
3024
+
3025
+ return s0;
3026
+ }
3027
+
3028
+ function peg$parseModuleFunction() {
3029
+ let s0, s1, s2, s3, s4, s5, s6, s7;
3030
+
3031
+ const key = peg$currPos * 40 + 35;
3032
+ const cached = peg$resultsCache[key];
3033
+
3034
+ if (cached) {
3035
+ peg$currPos = cached.nextPos;
3036
+
3037
+ return cached.result;
3038
+ }
3039
+
3040
+ peg$silentFails++;
3041
+ s0 = peg$currPos;
3042
+ if (input.charCodeAt(peg$currPos) === 35) {
3043
+ s1 = peg$c49;
3044
+ peg$currPos++;
3045
+ } else {
3046
+ s1 = peg$FAILED;
3047
+ if (peg$silentFails === 0) { peg$fail(peg$e51); }
3048
+ }
3049
+ if (s1 !== peg$FAILED) {
3050
+ s2 = peg$currPos;
3051
+ s3 = peg$currPos;
3052
+ s4 = peg$currPos;
3053
+ s5 = input.charAt(peg$currPos);
3054
+ if (peg$r5.test(s5)) {
3055
+ peg$currPos++;
3056
+ } else {
3057
+ s5 = peg$FAILED;
3058
+ if (peg$silentFails === 0) { peg$fail(peg$e52); }
3059
+ }
3060
+ if (s5 !== peg$FAILED) {
3061
+ s6 = [];
3062
+ s7 = input.charAt(peg$currPos);
3063
+ if (peg$r6.test(s7)) {
3064
+ peg$currPos++;
3065
+ } else {
3066
+ s7 = peg$FAILED;
3067
+ if (peg$silentFails === 0) { peg$fail(peg$e53); }
3068
+ }
3069
+ while (s7 !== peg$FAILED) {
3070
+ s6.push(s7);
3071
+ s7 = input.charAt(peg$currPos);
3072
+ if (peg$r6.test(s7)) {
3073
+ peg$currPos++;
3074
+ } else {
3075
+ s7 = peg$FAILED;
3076
+ if (peg$silentFails === 0) { peg$fail(peg$e53); }
3077
+ }
3078
+ }
3079
+ s5 = [s5, s6];
3080
+ s4 = s5;
3081
+ } else {
3082
+ peg$currPos = s4;
3083
+ s4 = peg$FAILED;
3084
+ }
3085
+ if (s4 !== peg$FAILED) {
3086
+ s3 = input.substring(s3, peg$currPos);
3087
+ } else {
3088
+ s3 = s4;
3089
+ }
3090
+ if (s3 !== peg$FAILED) {
3091
+ if (input.charCodeAt(peg$currPos) === 58) {
3092
+ s4 = peg$c15;
3093
+ peg$currPos++;
3094
+ } else {
3095
+ s4 = peg$FAILED;
3096
+ if (peg$silentFails === 0) { peg$fail(peg$e11); }
3097
+ }
3098
+ if (s4 !== peg$FAILED) {
3099
+ s2 = s3;
3100
+ } else {
3101
+ peg$currPos = s2;
3102
+ s2 = peg$FAILED;
3103
+ }
3104
+ } else {
3105
+ peg$currPos = s2;
3106
+ s2 = peg$FAILED;
3107
+ }
3108
+ if (s2 === peg$FAILED) {
3109
+ s2 = null;
3110
+ }
3111
+ s3 = peg$currPos;
3112
+ s4 = peg$currPos;
3113
+ s5 = input.charAt(peg$currPos);
3114
+ if (peg$r5.test(s5)) {
3115
+ peg$currPos++;
3116
+ } else {
3117
+ s5 = peg$FAILED;
3118
+ if (peg$silentFails === 0) { peg$fail(peg$e52); }
3119
+ }
3120
+ if (s5 !== peg$FAILED) {
3121
+ s6 = [];
3122
+ s7 = input.charAt(peg$currPos);
3123
+ if (peg$r6.test(s7)) {
3124
+ peg$currPos++;
3125
+ } else {
3126
+ s7 = peg$FAILED;
3127
+ if (peg$silentFails === 0) { peg$fail(peg$e53); }
3128
+ }
3129
+ while (s7 !== peg$FAILED) {
3130
+ s6.push(s7);
3131
+ s7 = input.charAt(peg$currPos);
3132
+ if (peg$r6.test(s7)) {
3133
+ peg$currPos++;
3134
+ } else {
3135
+ s7 = peg$FAILED;
3136
+ if (peg$silentFails === 0) { peg$fail(peg$e53); }
3137
+ }
3138
+ }
3139
+ s5 = [s5, s6];
3140
+ s4 = s5;
3141
+ } else {
3142
+ peg$currPos = s4;
3143
+ s4 = peg$FAILED;
3144
+ }
3145
+ if (s4 !== peg$FAILED) {
3146
+ s3 = input.substring(s3, peg$currPos);
3147
+ } else {
3148
+ s3 = s4;
3149
+ }
3150
+ if (s3 !== peg$FAILED) {
3151
+ s0 = peg$f37(s2, s3);
3152
+ } else {
3153
+ peg$currPos = s0;
3154
+ s0 = peg$FAILED;
3155
+ }
3156
+ } else {
3157
+ peg$currPos = s0;
3158
+ s0 = peg$FAILED;
3159
+ }
3160
+ peg$silentFails--;
3161
+ if (s0 === peg$FAILED) {
3162
+ s1 = peg$FAILED;
3163
+ if (peg$silentFails === 0) { peg$fail(peg$e50); }
3164
+ }
3165
+
3166
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
3167
+
3168
+ return s0;
3169
+ }
3170
+
3171
+ function peg$parseSymbol() {
3172
+ let s0, s1, s2, s3, s4, s5;
3173
+
3174
+ const key = peg$currPos * 40 + 36;
3175
+ const cached = peg$resultsCache[key];
3176
+
3177
+ if (cached) {
3178
+ peg$currPos = cached.nextPos;
3179
+
3180
+ return cached.result;
3181
+ }
3182
+
3183
+ peg$silentFails++;
3184
+ s0 = peg$currPos;
3185
+ s1 = peg$currPos;
3186
+ s2 = peg$currPos;
3187
+ s3 = input.charAt(peg$currPos);
3188
+ if (peg$r5.test(s3)) {
3189
+ peg$currPos++;
3190
+ } else {
3191
+ s3 = peg$FAILED;
3192
+ if (peg$silentFails === 0) { peg$fail(peg$e52); }
3193
+ }
3194
+ if (s3 !== peg$FAILED) {
3195
+ s4 = [];
3196
+ s5 = input.charAt(peg$currPos);
3197
+ if (peg$r6.test(s5)) {
3198
+ peg$currPos++;
3199
+ } else {
3200
+ s5 = peg$FAILED;
3201
+ if (peg$silentFails === 0) { peg$fail(peg$e53); }
3202
+ }
3203
+ while (s5 !== peg$FAILED) {
3204
+ s4.push(s5);
3205
+ s5 = input.charAt(peg$currPos);
3206
+ if (peg$r6.test(s5)) {
3207
+ peg$currPos++;
3208
+ } else {
3209
+ s5 = peg$FAILED;
3210
+ if (peg$silentFails === 0) { peg$fail(peg$e53); }
3211
+ }
3212
+ }
3213
+ s3 = [s3, s4];
3214
+ s2 = s3;
3215
+ } else {
3216
+ peg$currPos = s2;
3217
+ s2 = peg$FAILED;
3218
+ }
3219
+ if (s2 !== peg$FAILED) {
3220
+ s1 = input.substring(s1, peg$currPos);
3221
+ } else {
3222
+ s1 = s2;
3223
+ }
3224
+ if (s1 !== peg$FAILED) {
3225
+ s1 = peg$f38(s1);
3226
+ }
3227
+ s0 = s1;
3228
+ peg$silentFails--;
3229
+ if (s0 === peg$FAILED) {
3230
+ s1 = peg$FAILED;
3231
+ if (peg$silentFails === 0) { peg$fail(peg$e54); }
3232
+ }
3233
+
3234
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
3235
+
3236
+ return s0;
3237
+ }
3238
+
3239
+ function peg$parseEqualityOp() {
3240
+ let s0;
3241
+
3242
+ const key = peg$currPos * 40 + 37;
3243
+ const cached = peg$resultsCache[key];
3244
+
3245
+ if (cached) {
3246
+ peg$currPos = cached.nextPos;
3247
+
3248
+ return cached.result;
3249
+ }
3250
+
3251
+ if (input.substr(peg$currPos, 2) === peg$c53) {
3252
+ s0 = peg$c53;
3253
+ peg$currPos += 2;
3254
+ } else {
3255
+ s0 = peg$FAILED;
3256
+ if (peg$silentFails === 0) { peg$fail(peg$e55); }
3257
+ }
3258
+ if (s0 === peg$FAILED) {
3259
+ if (input.substr(peg$currPos, 2) === peg$c54) {
3260
+ s0 = peg$c54;
3261
+ peg$currPos += 2;
3262
+ } else {
3263
+ s0 = peg$FAILED;
3264
+ if (peg$silentFails === 0) { peg$fail(peg$e56); }
3265
+ }
3266
+ }
3267
+
3268
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
3269
+
3270
+ return s0;
3271
+ }
3272
+
3273
+ function peg$parseRelationalOp() {
3274
+ let s0;
3275
+
3276
+ const key = peg$currPos * 40 + 38;
3277
+ const cached = peg$resultsCache[key];
3278
+
3279
+ if (cached) {
3280
+ peg$currPos = cached.nextPos;
3281
+
3282
+ return cached.result;
3283
+ }
3284
+
3285
+ if (input.substr(peg$currPos, 2) === peg$c55) {
3286
+ s0 = peg$c55;
3287
+ peg$currPos += 2;
3288
+ } else {
3289
+ s0 = peg$FAILED;
3290
+ if (peg$silentFails === 0) { peg$fail(peg$e57); }
3291
+ }
3292
+ if (s0 === peg$FAILED) {
3293
+ if (input.charCodeAt(peg$currPos) === 62) {
3294
+ s0 = peg$c56;
3295
+ peg$currPos++;
3296
+ } else {
3297
+ s0 = peg$FAILED;
3298
+ if (peg$silentFails === 0) { peg$fail(peg$e58); }
3299
+ }
3300
+ if (s0 === peg$FAILED) {
3301
+ if (input.substr(peg$currPos, 2) === peg$c57) {
3302
+ s0 = peg$c57;
3303
+ peg$currPos += 2;
3304
+ } else {
3305
+ s0 = peg$FAILED;
3306
+ if (peg$silentFails === 0) { peg$fail(peg$e59); }
3307
+ }
3308
+ if (s0 === peg$FAILED) {
3309
+ if (input.charCodeAt(peg$currPos) === 60) {
3310
+ s0 = peg$c58;
3311
+ peg$currPos++;
3312
+ } else {
3313
+ s0 = peg$FAILED;
3314
+ if (peg$silentFails === 0) { peg$fail(peg$e60); }
3315
+ }
3316
+ }
3317
+ }
3318
+ }
3319
+
3320
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
3321
+
3322
+ return s0;
3323
+ }
3324
+
3325
+ function peg$parse_() {
3326
+ let s0, s1;
3327
+
3328
+ const key = peg$currPos * 40 + 39;
3329
+ const cached = peg$resultsCache[key];
3330
+
3331
+ if (cached) {
3332
+ peg$currPos = cached.nextPos;
3333
+
3334
+ return cached.result;
3335
+ }
3336
+
3337
+ peg$silentFails++;
3338
+ s0 = [];
3339
+ s1 = input.charAt(peg$currPos);
3340
+ if (peg$r7.test(s1)) {
3341
+ peg$currPos++;
3342
+ } else {
3343
+ s1 = peg$FAILED;
3344
+ if (peg$silentFails === 0) { peg$fail(peg$e61); }
3345
+ }
3346
+ while (s1 !== peg$FAILED) {
3347
+ s0.push(s1);
3348
+ s1 = input.charAt(peg$currPos);
3349
+ if (peg$r7.test(s1)) {
3350
+ peg$currPos++;
3351
+ } else {
3352
+ s1 = peg$FAILED;
3353
+ if (peg$silentFails === 0) { peg$fail(peg$e61); }
3354
+ }
3355
+ }
3356
+ peg$silentFails--;
3357
+
3358
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
3359
+
3360
+ return s0;
3361
+ }
3362
+
3363
+ peg$result = peg$startRuleFunction();
3364
+
3365
+ const peg$success = (peg$result !== peg$FAILED && peg$currPos === input.length);
3366
+ function peg$throw() {
3367
+ if (peg$result !== peg$FAILED && peg$currPos < input.length) {
3368
+ peg$fail(peg$endExpectation());
3369
+ }
3370
+
3371
+ throw peg$buildStructuredError(
3372
+ peg$maxFailExpected,
3373
+ peg$maxFailPos < input.length ? peg$getUnicode(peg$maxFailPos) : null,
3374
+ peg$maxFailPos < input.length
3375
+ ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
3376
+ : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
3377
+ );
3378
+ }
3379
+ if (options.peg$library) {
3380
+ return /** @type {any} */ ({
3381
+ peg$result,
3382
+ peg$currPos,
3383
+ peg$FAILED,
3384
+ peg$maxFailExpected,
3385
+ peg$maxFailPos,
3386
+ peg$success,
3387
+ peg$throw: peg$success ? undefined : peg$throw,
3388
+ });
3389
+ }
3390
+ if (peg$success) {
3391
+ return peg$result;
3392
+ } else {
3393
+ peg$throw();
3394
+ }
3395
+ }
3396
+
3397
+ class EvaluatingVisitor {
3398
+ #modules;
3399
+ #dataStack;
3400
+ constructor(modules, dataStack) {
3401
+ this.#modules = modules;
3402
+ this.#dataStack = dataStack;
3403
+ }
3404
+ #resolve(prop) {
3405
+ if (prop === 'self') {
3406
+ return this.#dataStack[this.#dataStack.length - 1];
3407
+ }
3408
+ for (let i = this.#dataStack.length - 1; i >= 0; i--) {
3409
+ const overlay = this.#dataStack[i];
3410
+ if (overlay != null && (typeof overlay === 'object' || typeof overlay === 'function')) {
3411
+ if (prop in overlay) {
3412
+ return overlay[prop];
3413
+ }
3414
+ }
3415
+ }
3416
+ return undefined;
3417
+ }
3418
+
3419
+ #cached_resolve_proxy;
3420
+ #resolve_proxy() {
3421
+ if (!this.#cached_resolve_proxy) {
3422
+ this.#cached_resolve_proxy = new Proxy(this.#dataStack, {
3423
+ get: (target, prop) => this.#resolve(prop)
3424
+ });
3425
+ }
3426
+ return this.#cached_resolve_proxy;
3427
+ }
3428
+ [nodes.and](node) {
3429
+ return this.visit(node.lhs) && this.visit(node.rhs);
3430
+ }
3431
+ [nodes.or](node) {
3432
+ return this.visit(node.lhs) || this.visit(node.rhs);
3433
+ }
3434
+ [nodes.nullc](node) {
3435
+ const lhs = this.visit(node.lhs);
3436
+ return lhs !== null && lhs !== undefined ? lhs : this.visit(node.rhs);
3437
+ }
3438
+ [nodes.not](node) {
3439
+ return !this.visit(node.expr);
3440
+ }
3441
+ [nodes.eq](node) {
3442
+ const lhs = this.visit(node.lhs);
3443
+ const rhs = this.visit(node.rhs);
3444
+ const eq = lhs === rhs;
3445
+ return node.op === '==' ? eq : !eq;
3446
+ }
3447
+ [nodes.cmp](node) {
3448
+ const lhs = this.visit(node.lhs);
3449
+ const rhs = this.visit(node.rhs);
3450
+ switch (node.op) {
3451
+ case '>':
3452
+ return lhs > rhs;
3453
+ case '<':
3454
+ return lhs < rhs;
3455
+ case '>=':
3456
+ return lhs >= rhs;
3457
+ case '<=':
3458
+ return lhs <= rhs;
3459
+ default:
3460
+ throw new Error('unknown cmp op ' + node.op);
3461
+ }
3462
+ }
3463
+ [nodes.call](node) {
3464
+ const fnRef = node.value;
3465
+ const module = fnRef.module === null ? this.#modules : this.#modules?.[fnRef.module];
3466
+ if (!module) {
3467
+ throw new Error(`Module "${fnRef.module}" not found`);
3468
+ }
3469
+ const fn = module[fnRef.value];
3470
+ if (!fn) {
3471
+ throw new Error(`Function "#${fnRef.module === null ? '' : fnRef.module + ':'}${fnRef.value}" not found`);
3472
+ }
3473
+ const args = node.args.map((arg) => this.visit(arg));
3474
+ return fn.apply(this.#resolve_proxy(), args);
3475
+ }
3476
+ [nodes.literal](node) {
3477
+ return node.value;
3478
+ }
3479
+ [nodes.tstring](node) {
3480
+ let result = '';
3481
+ const parts = node.parts;
3482
+ for (let i = 0, len = parts.length; i < len; i++) {
3483
+ const evaluated = this.visit(parts[i]);
3484
+ if (evaluated !== null && evaluated !== undefined) {
3485
+ result += evaluated;
3486
+ }
3487
+ }
3488
+ return result;
3489
+ }
3490
+ [nodes.symbol](node) {
3491
+ return this.#resolve(node.value);
3492
+ }
3493
+ [nodes.dict](node) {
3494
+ return Object.fromEntries(node.value.map((entry) => [entry[0].value, this.visit(entry[1])]));
3495
+ }
3496
+ [nodes.array](node) {
3497
+ return node.value.map((v) => this.visit(v));
3498
+ }
3499
+ [nodes.ter](node) {
3500
+ return this.visit(node.cond) ? this.visit(node.ifTrue) : this.visit(node.ifFalse);
3501
+ }
3502
+ [nodes.elv](node) {
3503
+ const cond = this.visit(node.cond);
3504
+ return cond ? cond : this.visit(node.ifFalse);
3505
+ }
3506
+ [nodes.access](node) {
3507
+ let prev = undefined;
3508
+ let cur = this.visit(node.lhs);
3509
+ for (let i = 0; i !== node.rhs.length; ++i) {
3510
+ const rhs = node.rhs[i];
3511
+ if (rhs.ns && cur == null) {
3512
+ return undefined;
3513
+ }
3514
+ let value = undefined;
3515
+ switch (rhs.type) {
3516
+ case nodes.member: {
3517
+ value = cur[rhs.rhs];
3518
+ break;
3519
+ }
3520
+ case nodes.subscript: {
3521
+ value = cur[this.visit(rhs.rhs)];
3522
+ break;
3523
+ }
3524
+ case nodes.method: {
3525
+ if (!cur) {
3526
+ throw new Error(`Method missing "${node.rhs[i - 1].rhs}"`);
3527
+ }
3528
+ const args = rhs.args.map((arg) => this.visit(arg));
3529
+ value = cur.apply(prev, args);
3530
+ break;
3531
+ }
3532
+ }
3533
+ prev = cur;
3534
+ cur = value;
3535
+ }
3536
+ return cur;
3537
+ }
3538
+ visit(node, ...args) {
3539
+ return this[node.type](node, ...args);
3540
+ }
3541
+ visitRoot(ast, templated) {
3542
+ return !templated
3543
+ ? this.visit(ast)
3544
+ : ast.map((node) => {
3545
+ switch (node.type) {
3546
+ case nodes.templated.tel:
3547
+ return { type: nodes.dom.t, value: node.value };
3548
+ case nodes.templated.tet:
3549
+ return { type: nodes.dom.t, value: this.visit(node.value) };
3550
+ case nodes.templated.teh:
3551
+ return { type: nodes.dom.h, value: this.visit(node.value) };
3552
+ case nodes.templated.ten:
3553
+ return { type: nodes.dom.n, value: this.visit(node.value) };
3554
+ default:
3555
+ throw new Error('unknown node type ' + node.type.toString());
3556
+ }
3557
+ });
3558
+ }
3559
+ }
3560
+
3561
+ class Expressions {
3562
+ static MODE_EXPRESSION = Symbol('MODE_EXPRESSION');
3563
+ static MODE_TEMPLATED = Symbol('MODE_TEMPLATED');
3564
+
3565
+ static #astCache = new Map();
3566
+ static #MAX_CACHE_SIZE = 1000;
3567
+
3568
+ /**
3569
+ * Parses an expression.
3570
+ * @param {string} expression
3571
+ * @param {(typeof Expressions.MODE_EXPRESSION | typeof Expressions.MODE_TEMPLATED)?} [mode]
3572
+ * @returns the ast
3573
+ */
3574
+ static parse(expression, mode) {
3575
+ const key = mode?.toString() + expression;
3576
+
3577
+ if (!this.#astCache.has(key)) {
3578
+ if (this.#astCache.size >= this.#MAX_CACHE_SIZE) {
3579
+ const oldestKey = this.#astCache.keys().next().value;
3580
+ this.#astCache.delete(oldestKey);
3581
+ }
3582
+ this.#astCache.set(key, peg$parse(expression, {
3583
+ startRule: mode === Expressions.MODE_TEMPLATED ? 'TemplatedRoot' : 'ExpressionRoot',
3584
+ }));
3585
+ }
3586
+
3587
+ return this.#astCache.get(key);
3588
+ }
3589
+ /**
3590
+ * Evaluates an expression.
3591
+ * @param {{[k: string]: any } | null | undefined } modules
3592
+ * @param {any[]} dataStack
3593
+ * @param {any} ast
3594
+ * @param {(typeof Expressions.MODE_EXPRESSION | typeof Expressions.MODE_TEMPLATED)?} [mode]
3595
+ * @returns the result
3596
+ */
3597
+ static evaluate(modules, dataStack, ast, mode) {
3598
+ return new EvaluatingVisitor(modules, dataStack).visitRoot(ast, mode === Expressions.MODE_TEMPLATED);
3599
+ }
3600
+ /**
3601
+ * Parses and evaluates an expression.
3602
+ * @param {{ [x: string]: any; } | null | undefined} modules
3603
+ * @param {any[]} dataStack
3604
+ * @param {string} expression
3605
+ * @param {(typeof Expressions.MODE_EXPRESSION | typeof Expressions.MODE_TEMPLATED)?} [mode]
3606
+ * @returns the result
3607
+ */
3608
+ static interpret(modules, dataStack, expression, mode) {
3609
+ return Expressions.evaluate(modules, dataStack, Expressions.parse(expression, mode), mode);
3610
+ }
3611
+ }
3612
+
3613
+ class ExpressionEvaluator {
3614
+ #modules;
3615
+ #dataStack;
3616
+ constructor(modules, dataStack) {
3617
+ this.#modules = modules;
3618
+ this.#dataStack = dataStack;
3619
+ }
3620
+ withModule(name, value) {
3621
+ const module = name ? { [name]: value } : value;
3622
+ return new ExpressionEvaluator({ ...this.#modules, ...module }, this.#dataStack);
3623
+ }
3624
+ withOverlay(...data) {
3625
+ return new ExpressionEvaluator(
3626
+ this.#modules,
3627
+ data.length === 0 ? this.#dataStack : [...this.#dataStack, ...data],
3628
+ );
3629
+ }
3630
+ evaluate(expression, mode) {
3631
+ return Expressions.interpret(this.#modules, this.#dataStack, expression, mode);
3632
+ }
3633
+ evaluateExpression(expression) {
3634
+ return this.evaluate(expression, Expressions.MODE_EXPRESSION);
3635
+ }
3636
+ evaluateTemplated(expression) {
3637
+ return this.evaluate(expression, Expressions.MODE_TEMPLATED);
3638
+ }
3639
+ }
3640
+
3641
+ class Fragments {
3642
+ /**
3643
+ * Creates a DocumentFragment from an string.
3644
+ * @param {...string} html
3645
+ * @returns {DocumentFragment} the fragment
3646
+ */
3647
+ static fromHtml(...html) {
3648
+ const el = document.createElement('template');
3649
+ el.innerHTML = html.map((h) => h.trim()).join('');
3650
+ return document.adoptNode(el.content);
3651
+ }
3652
+ /**
3653
+ * Creates a string representation (HTML) of a DocumentFragment.
3654
+ * @param {DocumentFragment} fragment
3655
+ * @returns {string} the html
3656
+ */
3657
+ static toHtml(fragment) {
3658
+ var el = document.createElement('template');
3659
+ el.content.appendChild(fragment);
3660
+ return el.innerHTML;
3661
+ }
3662
+ /**
3663
+ * Checks if a fragment contains only blank text nodes
3664
+ * @param {DocumentFragment} fragment
3665
+ * @returns {boolean} true if the fragment is blank
3666
+ */
3667
+ static isBlank(fragment) {
3668
+ return fragment.childElementCount === 0 && fragment.textContent.trim() === '';
3669
+ }
3670
+ /**
3671
+ * Creates a DocumentFragment from nodes.
3672
+ * @param {...Node} nodes
3673
+ * @returns {DocumentFragment} the fragment
3674
+ */
3675
+ static from(...nodes) {
3676
+ const fragment = new DocumentFragment();
3677
+ for (const node of nodes) {
3678
+ fragment.appendChild(node);
3679
+ }
3680
+ return fragment;
3681
+ }
3682
+ /**
3683
+ * Creates a DocumentFragment from childNodes of an element.
3684
+ * @param {Node} el
3685
+ * @returns {DocumentFragment} the fragment
3686
+ */
3687
+ static fromChildNodes(el) {
3688
+ const fragment = new DocumentFragment();
3689
+ while (el.firstChild) {
3690
+ fragment.appendChild(el.firstChild);
3691
+ }
3692
+ return fragment;
3693
+ }
3694
+ }
3695
+
3696
+ class Attributes {
3697
+ static id = 0;
3698
+ /**
3699
+ * Creates a unique id with the given prefix.
3700
+ * @param {string} prefix
3701
+ * @returns
3702
+ */
3703
+ static uid(prefix) {
3704
+ return `${prefix}-${++Attributes.id}`;
3705
+ }
3706
+ /**
3707
+ * Sets an attribute if not present.
3708
+ * @param {Element} el
3709
+ * @param {string} k
3710
+ * @param {string} v
3711
+ * @returns
3712
+ */
3713
+ static defaultValue(el, k, v) {
3714
+ if (!el.hasAttribute(k)) {
3715
+ el.setAttribute(k, v);
3716
+ }
3717
+ return el.getAttribute(k);
3718
+ }
3719
+ /**
3720
+ * Forwards prefixed attributes from an element to another (removing the prefix).
3721
+ * @param {string} prefix
3722
+ * @param {Element} from
3723
+ * @param {Element} to
3724
+ */
3725
+ static forward(prefix, from, to) {
3726
+ from.getAttributeNames()
3727
+ .filter((a) => a.startsWith(prefix))
3728
+ .forEach((a) => {
3729
+ const target = a.substring(prefix.length);
3730
+ if (target === 'class') {
3731
+ const classes = from.getAttribute(prefix + 'class')?.split(/\s+/).filter((a) => a.length) ?? [];
3732
+ to.classList.add(...classes);
3733
+ return;
3734
+ }
3735
+ to.setAttribute(target, /** @type {string} */(from.getAttribute(a)));
3736
+ });
3737
+ }
3738
+ /**
3739
+ * Changes the presence of an attribute.
3740
+ * @param {Element} el
3741
+ * @param {string} attr
3742
+ * @param {boolean} value
3743
+ */
3744
+ static toggle(el, attr, value) {
3745
+ if (value) {
3746
+ el.setAttribute(attr, '');
3747
+ } else {
3748
+ el.removeAttribute(attr);
3749
+ }
3750
+ }
3751
+ /**
3752
+ * Changes the presence of an attribute based on its current state.
3753
+ * @param {Element} el
3754
+ * @param {string} attr
3755
+ */
3756
+ static flip(el, attr) {
3757
+ if (el.hasAttribute(attr)) {
3758
+ el.removeAttribute(attr);
3759
+ } else {
3760
+ el.setAttribute(attr, '');
3761
+ }
3762
+ }
3763
+ /**
3764
+ * Sets the value of an attribute. nullish values remove the attribute.
3765
+ * @param {Element} el
3766
+ * @param {string} attr
3767
+ * @param {string | null | undefined} value
3768
+ */
3769
+ static set(el, attr, value) {
3770
+ if (value == null) {
3771
+ el.removeAttribute(attr);
3772
+ } else {
3773
+ el.setAttribute(attr, value);
3774
+ }
3775
+ }
3776
+ }
3777
+
3778
+ class LightSlots {
3779
+ /**
3780
+ * Extracts light slots from an element. For non default slots in a template tag, the content is extracted.
3781
+ * @param {Element} el
3782
+ * @returns the slots
3783
+ */
3784
+ static from(el) {
3785
+ /** @type [string, Element|DocumentFragment][] */
3786
+ const namedSlots = Array.from(el.children)
3787
+ .filter((el) => el.matches('[slot]'))
3788
+ .map((el) => {
3789
+ el.remove();
3790
+ const slot = el.getAttribute('slot') || 'unnamed';
3791
+ el.removeAttribute('slot');
3792
+ return [slot, LightSlots.slotFromNode(el)];
3793
+ });
3794
+ const slots = {};
3795
+ slots.default = new DocumentFragment();
3796
+ slots.default.append(...el.childNodes);
3797
+ for (const [name, el] of namedSlots) {
3798
+ if (!(name in slots)) {
3799
+ slots[name] = new DocumentFragment();
3800
+ }
3801
+ slots[name].append(el);
3802
+ }
3803
+ return slots;
3804
+ }
3805
+ static slotFromNode(el) {
3806
+ if (el instanceof HTMLTemplateElement) {
3807
+ return document.adoptNode(el.content);
3808
+ }
3809
+ if (el instanceof HTMLScriptElement && el.type !== '' && el.type !== 'text/javascript') {
3810
+ return Fragments.fromHtml(el.innerHTML);
3811
+ }
3812
+ return el;
3813
+ }
3814
+ }
3815
+
3816
+ class Nodes {
3817
+ /**
3818
+ * Checks if an element is already parsed.
3819
+ * @param {Element} el
3820
+ * @returns
3821
+ */
3822
+ static isParsed(el) {
3823
+ //@ts-ignore
3824
+ for (let c = el; c; c = c.parentNode) {
3825
+ if (c.nextSibling) {
3826
+ return true;
3827
+ }
3828
+ }
3829
+ return false;
3830
+ }
3831
+
3832
+ static waitParsed(el) {
3833
+ if (el.ownerDocument.readyState === 'complete' || Nodes.isParsed(el)) {
3834
+ return Promise.resolve(el);
3835
+ }
3836
+ return new Promise((resolve) => {
3837
+ const ac = new AbortController();
3838
+ const clearAndQueue = () => {
3839
+ ac.abort();
3840
+ observer.disconnect();
3841
+ resolve(el);
3842
+ };
3843
+ el.ownerDocument.addEventListener('DOMContentLoaded', clearAndQueue, { signal: ac.signal });
3844
+ const observer = new MutationObserver(() => {
3845
+ if (!Nodes.isParsed(el)) {
3846
+ return;
3847
+ }
3848
+ clearAndQueue();
3849
+ });
3850
+ const parent = /** @type {Node} */ (el.parentNode);
3851
+ observer.observe(parent, { childList: true });
3852
+ });
3853
+ }
3854
+
3855
+ /**
3856
+ * Returns the first child of the element element (if exists) matching the selector.
3857
+ * @param {Element} el
3858
+ * @param {string} selector
3859
+ * @returns
3860
+ */
3861
+ static queryChildren(el, selector) {
3862
+ for (const c of el.children) {
3863
+ if (c.matches(selector)) {
3864
+ return c;
3865
+ }
3866
+ }
3867
+ return null;
3868
+ }
3869
+ /**
3870
+ * Returns all children of the element matching the selector.
3871
+ * @param {Element} el
3872
+ * @param {string} selector
3873
+ * @returns
3874
+ */
3875
+ static queryChildrenAll(el, selector) {
3876
+ const r = [];
3877
+ for (const c of el.children) {
3878
+ if (c.matches(selector)) {
3879
+ r.push(c);
3880
+ }
3881
+ }
3882
+ return r;
3883
+ }
3884
+ }
3885
+
3886
+ class NodeOperations {
3887
+ #forRemoval;
3888
+ constructor() {
3889
+ this.#forRemoval = [];
3890
+ }
3891
+ removed(node) {
3892
+ return this.#forRemoval.includes(node);
3893
+ }
3894
+ remove(node) {
3895
+ node.replaceChildren?.();
3896
+ Object.keys(node.dataset || {})
3897
+ .filter((k) => k.startsWith('tpl'))
3898
+ .forEach((k) => delete node.dataset[k]);
3899
+ this.#forRemoval.push(node);
3900
+ }
3901
+ popData(node, key) {
3902
+ const v = node.dataset[key];
3903
+ delete node.dataset[key];
3904
+ return v;
3905
+ }
3906
+ prepend(ref, node) {
3907
+ ref.parentNode.insertBefore(node, ref);
3908
+ }
3909
+ append(ref, node) {
3910
+ ref.parentNode.insertBefore(node, ref.nextSibling);
3911
+ }
3912
+ replace(ref, node) {
3913
+ this.prepend(ref, node);
3914
+ this.remove(ref);
3915
+ }
3916
+ cleanup() {
3917
+ while (this.#forRemoval.length) {
3918
+ this.#forRemoval.pop().remove();
3919
+ }
3920
+ }
3921
+ }
3922
+
3923
+ class CommandsHandler {
3924
+ static ORDERED_COMMANDS = [
3925
+ 'tplIf',
3926
+ 'tplWith',
3927
+ 'tplEach',
3928
+ 'tplWhen',
3929
+ 'tplClassAppend',
3930
+ 'tplAttrAppend',
3931
+ 'tplText',
3932
+ 'tplHtml',
3933
+ 'tplRemove',
3934
+ 'tplVerbatim',
3935
+ ];
3936
+ static tplIf(node, expression, ops, modules, dataStack) {
3937
+ const accept = Expressions.interpret(modules, dataStack, expression);
3938
+ if (!accept) {
3939
+ ops.remove(node);
3940
+ }
3941
+ }
3942
+ static tplWith(node, expression, ops, modules, dataStack) {
3943
+ const evaluated = Expressions.interpret(modules, dataStack, expression);
3944
+ const varName = ops.popData(node, 'tplVar');
3945
+ const newNode = new Template(node, modules, dataStack)
3946
+ .withOverlay(varName ? { [varName]: evaluated } : evaluated)
3947
+ .render();
3948
+ ops.replace(node, newNode);
3949
+ }
3950
+ static tplEach(node, expression, ops, modules, dataStack) {
3951
+ const varName = ops.popData(node, 'tplVar');
3952
+ const template = new Template(node, modules, dataStack);
3953
+ const evaluated = Expressions.interpret(modules, dataStack, expression);
3954
+ if (!evaluated?.[Symbol.iterator]) {
3955
+ throw new Error(`Expected an iterable got '${evaluated}'`);
3956
+ }
3957
+ for (const v of evaluated) {
3958
+ ops.prepend(node, template.withOverlay(varName ? { [varName]: v } : v).render());
3959
+ }
3960
+ ops.remove(node);
3961
+ }
3962
+ static tplWhen(node, expression, ops, modules, dataStack) {
3963
+ const accept = Expressions.interpret(modules, dataStack, expression);
3964
+ if (!accept) {
3965
+ ops.remove(node);
3966
+ }
3967
+ }
3968
+ static tplVerbatim(node, expression, ops, modules, dataStack) {
3969
+ const newNode = node.cloneNode(true);
3970
+ ops.replace(node, newNode);
3971
+ }
3972
+ static tplRemove(node, value, ops, modules, dataStack) {
3973
+ switch (value.toLowerCase()) {
3974
+ case 'tag':
3975
+ const fragment = new DocumentFragment();
3976
+ while (node.firstChild) {
3977
+ fragment.appendChild(node.firstChild);
3978
+ }
3979
+ if ('tplVerbatim' in node.dataset) {
3980
+ //we are removing the parent element so we have to handle the lower priority commands
3981
+ ops.popData(node, 'tplVerbatim');
3982
+ ops.replace(node, fragment);
3983
+ } else {
3984
+ ops.append(node, fragment);
3985
+ ops.remove(node);
3986
+ }
3987
+ break;
3988
+ case 'body':
3989
+ node.replaceChildren();
3990
+ break;
3991
+ case 'all':
3992
+ ops.remove(node);
3993
+ break;
3994
+ }
3995
+ }
3996
+ static tplText(node, expression, ops, modules, dataStack) {
3997
+ const text = Expressions.interpret(modules, dataStack, expression);
3998
+ const newNode = node.cloneNode();
3999
+ newNode.replaceChildren(text == null ? '' : text);
4000
+ ops.replace(node, newNode);
4001
+ }
4002
+ static tplHtml(node, expression, ops, modules, dataStack) {
4003
+ const html = Expressions.interpret(modules, dataStack, expression);
4004
+ const newNode = node.cloneNode();
4005
+ newNode.innerHTML = html == null ? '' : html;
4006
+ ops.replace(node, newNode);
4007
+ }
4008
+ static tplClassAppend(node, expression, ops, modules, dataStack) {
4009
+ const classes = Expressions.interpret(modules, dataStack, expression);
4010
+ if (!classes) {
4011
+ return;
4012
+ }
4013
+ const classesAsArray = Array.isArray(classes) ? classes : [classes];
4014
+ const cleanClasses = classesAsArray
4015
+ .flatMap(c => typeof c === 'string' ? c.split(' ') : c)
4016
+ .filter(Boolean);
4017
+ if (cleanClasses.length === 0) {
4018
+ return;
4019
+ }
4020
+ node.classList.add(...cleanClasses);
4021
+ }
4022
+ static tplAttrAppend(node, expression, ops, modules, dataStack) {
4023
+ const attributesAndValues = Expressions.interpret(modules, dataStack, expression);
4024
+ if (!attributesAndValues || attributesAndValues.length === 0) {
4025
+ return;
4026
+ }
4027
+ const tuples = Array.isArray(attributesAndValues[0]) ? attributesAndValues : [attributesAndValues];
4028
+ tuples.forEach(([k, v]) => {
4029
+ node.setAttribute(k, v);
4030
+ });
4031
+ }
4032
+ static textNode(node, expression, ops, modules, dataStack) {
4033
+ for (const v of Expressions.interpret(modules, dataStack, expression, Expressions.MODE_TEMPLATED)) {
4034
+ if (v.value == null) {
4035
+ continue;
4036
+ }
4037
+ switch (v.type) {
4038
+ case nodes.dom.t:
4039
+ ops.prepend(node, document.createTextNode(v.value));
4040
+ break;
4041
+ case nodes.dom.h:
4042
+ ops.prepend(node, Fragments.fromHtml(v.value));
4043
+ break;
4044
+ case nodes.dom.n:
4045
+ ops.prepend(node, v.value);
4046
+ break;
4047
+ }
4048
+ }
4049
+ ops.remove(node);
4050
+ }
4051
+ }
4052
+
4053
+ // Module-isolated string cache for dataset-to-attribute conversions
4054
+ const attributeCache = new Map();
4055
+
4056
+ /**
4057
+ * Converts a tpl camelCase dataset key into a kebab-case attribute name.
4058
+ * Uses a cache lookup to avoid repetitive regex/string splitting.
4059
+ * @param {string} dataSetKey
4060
+ * @returns {string}
4061
+ */
4062
+ function toAttr(dataSetKey) {
4063
+ let cached = attributeCache.get(dataSetKey);
4064
+ if (!cached) {
4065
+ cached = dataSetKey
4066
+ .substring(3)
4067
+ .split(/(?=[A-Z])/)
4068
+ .join('-')
4069
+ .toLowerCase();
4070
+ attributeCache.set(dataSetKey, cached);
4071
+ }
4072
+ return cached;
4073
+ }
4074
+
4075
+ class Template {
4076
+ /**
4077
+ * Creates a template from a string.
4078
+ * @param {string} html
4079
+ * @param {{ [k: string] : any }?} [modules]
4080
+ * @param {...*} data
4081
+ * @returns the template
4082
+ */
4083
+ static fromHtml(html, modules, ...data) {
4084
+ return new Template(Fragments.fromHtml(html), modules, data);
4085
+ }
4086
+
4087
+ /**
4088
+ * Creates a template from the content of the first template element matching the selector.
4089
+ * @param {string} selector for an HTMLTemplateElement
4090
+ * @param {{ [k: string] : any }?} [modules]
4091
+ * @param {...*} data
4092
+ * @returns the template
4093
+ */
4094
+ static fromSelector(selector, modules, ...data) {
4095
+ const templateEl = document.querySelector(selector);
4096
+ if (!(templateEl instanceof HTMLTemplateElement)) {
4097
+ throw new Error('template selector does not match any template tag');
4098
+ }
4099
+ const fragment = document.adoptNode(templateEl.content);
4100
+ return new Template(fragment, modules, data);
4101
+ }
4102
+
4103
+ /**
4104
+ * Creates a template from the content of an HTMLTemplateElement.
4105
+ * @param {HTMLTemplateElement} templateEl
4106
+ * @param {{ [k: string] : any }?} [modules]
4107
+ * @param {...*} data
4108
+ * @returns the template
4109
+ */
4110
+ static fromTemplate(templateEl, modules, ...data) {
4111
+ const fragment = document.adoptNode(templateEl.content);
4112
+ return new Template(fragment, modules, data);
4113
+ }
4114
+
4115
+ /**
4116
+ * Creates a template from a DocumentFragment.
4117
+ * @param {DocumentFragment} fragment
4118
+ * @param { { [k: string] : any }? } [modules]
4119
+ * @param {...*} data
4120
+ * @returns the template
4121
+ */
4122
+ static fromFragment(fragment, modules, ...data) {
4123
+ return new Template(fragment, modules, data);
4124
+ }
4125
+ #fragment;
4126
+ #modules;
4127
+ #dataStack;
4128
+ /**
4129
+ * Creates a template.
4130
+ * @param {DocumentFragment} fragment
4131
+ * @param {{ [x: string]: any; } | null | undefined} modules
4132
+ * @param {any[]} dataStack
4133
+ */
4134
+ constructor(fragment, modules, dataStack) {
4135
+ this.#fragment = fragment;
4136
+ this.#modules = modules;
4137
+ this.#dataStack = dataStack;
4138
+ }
4139
+ /**
4140
+ * Creates a new Template replacing the modules and dataStack from a context.
4141
+ * @param {{modules: { [x: string]: any; } | null | undefined, data: any[]}} context
4142
+ */
4143
+ withContext({ modules, data }) {
4144
+ return new Template(this.#fragment, modules, data);
4145
+ }
4146
+ /**
4147
+ * Creates a new Template replacing the modules and dataStack from a registry.
4148
+ * @param any registry
4149
+ */
4150
+ withContextFrom(registry) {
4151
+ return this.withContext(registry.context());
4152
+ }
4153
+ /**
4154
+ * Creates a new Template replacing the fragment.
4155
+ * @param {DocumentFragment} fragment
4156
+ */
4157
+ withFragment(fragment) {
4158
+ return new Template(fragment, this.#modules, this.#dataStack);
4159
+ }
4160
+ /**
4161
+ * Creates a new Template with a new module added.
4162
+ * @param {string?} name
4163
+ * @param {{[k: string]: any}} value
4164
+ */
4165
+ withModule(name, value) {
4166
+ const module = name ? { [name]: value } : value;
4167
+ return new Template(this.#fragment, { ...this.#modules, ...module }, this.#dataStack);
4168
+ }
4169
+ /**
4170
+ * Creates a new Template replacing the modules.
4171
+ * @param {{ [x: string]: any; }?} modules
4172
+ */
4173
+ withModules(modules) {
4174
+ return new Template(this.#fragment, modules, this.#dataStack);
4175
+ }
4176
+ /**
4177
+ * Creates a new Template replacing the data stack.
4178
+ * @param {any[]} dataStack the dataStack
4179
+ */
4180
+ withData(dataStack) {
4181
+ return new Template(this.#fragment, this.#modules, dataStack);
4182
+ }
4183
+ /**
4184
+ * Creates a new Template with new a data overlay added to the stack.
4185
+ * @param {...*} data
4186
+ */
4187
+ withOverlay(...data) {
4188
+ return new Template(
4189
+ this.#fragment,
4190
+ this.#modules,
4191
+ data.length === 0 ? this.#dataStack : [...this.#dataStack, ...data],
4192
+ );
4193
+ }
4194
+ /**
4195
+ * Evaluates an expression using the configured modules and data.
4196
+ * @param {string} expression
4197
+ * @param {(typeof Expressions.MODE_EXPRESSION | typeof Expressions.MODE_TEMPLATED)?} [mode]
4198
+ * @param {...*} data
4199
+ */
4200
+ evaluate(expression, mode, ...data) {
4201
+ new ExpressionEvaluator(this.#modules, this.#dataStack).withOverlay(...data).evaluate(expression, mode);
4202
+ }
4203
+ /**
4204
+ * Returns an expression evaluator with bound modules and dataStack.
4205
+ */
4206
+ evaluator() {
4207
+ return new ExpressionEvaluator(this.#modules, this.#dataStack);
4208
+ }
4209
+ /**
4210
+ * Renders the template.
4211
+ * @returns a DocumentFragment
4212
+ */
4213
+ render() {
4214
+ try {
4215
+ const ops = new NodeOperations();
4216
+ const imported = document.importNode(this.#fragment, true);
4217
+ const fragment =
4218
+ imported.nodeType === Node.DOCUMENT_FRAGMENT_NODE
4219
+ ? imported
4220
+ : (() => {
4221
+ const d = new DocumentFragment();
4222
+ d.appendChild(imported);
4223
+ return d;
4224
+ })();
4225
+ const iterator = document.createNodeIterator(
4226
+ fragment,
4227
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,
4228
+ Template.#NODE_FILTER,
4229
+ );
4230
+ let node;
4231
+ while ((node = iterator.nextNode()) !== null) {
4232
+ ops.cleanup();
4233
+ if (node.nodeType === Node.TEXT_NODE) {
4234
+ try {
4235
+ CommandsHandler.textNode(node, node.nodeValue, ops, this.#modules, this.#dataStack);
4236
+ } catch (ex) {
4237
+ throw new RenderError('Error evaluating text node', node, ex);
4238
+ }
4239
+ continue;
4240
+ }
4241
+ const el = /** @type {HTMLElement} */ (node);
4242
+ for (const command of CommandsHandler.ORDERED_COMMANDS) {
4243
+ if (!(command in el.dataset)) {
4244
+ continue;
4245
+ }
4246
+ const value = ops.popData(el, command);
4247
+ try {
4248
+ CommandsHandler[command](el, value, ops, this.#modules, this.#dataStack);
4249
+ } catch (ex) {
4250
+ throw new RenderError(`Error evaluating command ${command}`, el, ex);
4251
+ }
4252
+ if (ops.removed(el)) {
4253
+ break;
4254
+ }
4255
+ }
4256
+ for (const dataSetKey of Object.keys(el.dataset || {})) {
4257
+ if (!dataSetKey.startsWith('tpl')) {
4258
+ continue;
4259
+ }
4260
+ const attributeName = toAttr(dataSetKey);
4261
+ try {
4262
+ const expression = ops.popData(el, dataSetKey);
4263
+ const evaluated = Expressions.interpret(this.#modules, this.#dataStack, expression);
4264
+ if (typeof evaluated === 'boolean') {
4265
+ Attributes.toggle(el, attributeName, evaluated);
4266
+ continue;
4267
+ }
4268
+ if (evaluated !== null && evaluated !== undefined) {
4269
+ el.setAttribute(attributeName, evaluated);
4270
+ }
4271
+ } catch (ex) {
4272
+ throw new RenderError(`Error evaluating command ${dataSetKey}`, el, ex);
4273
+ }
4274
+ }
4275
+ }
4276
+ ops.cleanup();
4277
+ return fragment;
4278
+ } catch (ex) {
4279
+ throw new RenderError('Error rendering template', this.#fragment, ex);
4280
+ }
4281
+ }
4282
+ /**
4283
+ * Renders this template on the Element (replacing children).
4284
+ * @param {Element} el
4285
+ */
4286
+ renderTo(el) {
4287
+ el.replaceChildren(this.render());
4288
+ }
4289
+ /**
4290
+ * Renders this template appending the resulting fragment to the Element.
4291
+ * @param {Element} el
4292
+ */
4293
+ appendTo(el) {
4294
+ el.appendChild(this.render());
4295
+ }
4296
+ /**
4297
+ * Renders this template appending the resulting fragment to the first Element maching the selector, if exists.
4298
+ * @param {string} selector
4299
+ */
4300
+ renderToSelector(selector) {
4301
+ const el = document.querySelector(selector);
4302
+ if (el) {
4303
+ this.renderTo(el);
4304
+ }
4305
+ }
4306
+ /**
4307
+ * Renders this template appending the resulting fragment to the Element maching the selector, if exists.
4308
+ * @param {string} selector
4309
+ */
4310
+ appendToSelector(selector) {
4311
+ const el = document.querySelector(selector);
4312
+ if (el) {
4313
+ this.appendTo(el);
4314
+ }
4315
+ }
4316
+ static #NODE_FILTER(node) {
4317
+ if (node.nodeType === Node.TEXT_NODE) {
4318
+ return node.nodeValue.includes('{{') && node.nodeValue.includes('}}')
4319
+ ? NodeFilter.FILTER_ACCEPT
4320
+ : NodeFilter.FILTER_REJECT;
4321
+ }
4322
+ for (const attr of node.attributes) {
4323
+ if (attr.name.startsWith('data-tpl-')) {
4324
+ return NodeFilter.FILTER_ACCEPT;
4325
+ }
4326
+ }
4327
+ return NodeFilter.FILTER_SKIP;
4328
+ }
4329
+ }
4330
+
4331
+ class RenderError extends Error {
4332
+ constructor(message, nodeOrFragment, cause) {
4333
+ super(`${message} in \`${RenderError.stringify(nodeOrFragment)}\``, { cause });
4334
+ this.name = 'RenderError';
4335
+ this.node = nodeOrFragment.cloneNode(true);
4336
+ }
4337
+ static stringify(nodeOrFragment) {
4338
+ const t = document.createElement('template');
4339
+ t.content.appendChild(RenderError.#cleanup(nodeOrFragment.cloneNode(true)));
4340
+ return t.innerHTML;
4341
+ }
4342
+ static #cleanup(node) {
4343
+ if (node.nodeType === Node.TEXT_NODE) {
4344
+ node.nodeValue = node.nodeValue.trim();
4345
+ }
4346
+ for (var n = 0; n < node.childNodes.length; n++) {
4347
+ var child = node.childNodes[n];
4348
+ if (child.nodeType === Node.TEXT_NODE) {
4349
+ child.nodeValue = child.nodeValue.trim();
4350
+ if (child.nodeValue.length === 0) {
4351
+ node.removeChild(child);
4352
+ n--;
4353
+ }
4354
+ } else if (child.nodeType === Node.ELEMENT_NODE) {
4355
+ RenderError.#cleanup(child);
4356
+ }
4357
+ }
4358
+ return node;
4359
+ }
4360
+ }
4361
+
4362
+ class UpgradeQueue {
4363
+ #q = new Map();
4364
+ constructor() {
4365
+ document.addEventListener('DOMContentLoaded', async () => {
4366
+ const pending = Array.from(this.entries).map(([child, promise]) => promise);
4367
+ await Promise.all(pending);
4368
+ document.dispatchEvent(
4369
+ new CustomEvent('ftl:ready', {
4370
+ bubbles: false,
4371
+ cancelable: false,
4372
+ }),
4373
+ );
4374
+ });
4375
+ }
4376
+ enqueue(el) {
4377
+ if (this.#q.has(el)) {
4378
+ //already upgrading, can happen when disconnecting an element
4379
+ //while it's already queued for upgrade (e.g.: ful-form)
4380
+ return;
4381
+ }
4382
+ const promise = Nodes.waitParsed(el)
4383
+ .then(() => el.upgrade())
4384
+ .finally(() => this.#q.delete(el));
4385
+ this.#q.set(el, promise);
4386
+ }
4387
+ get entries() {
4388
+ return this.#q.entries();
4389
+ }
4390
+ }
4391
+
4392
+
4393
+ class Registry {
4394
+ #tagToClass = {};
4395
+ #configured = false;
4396
+ #mappers = {
4397
+ string: {
4398
+ unmarshal(str, name, el) {
4399
+ return str;
4400
+ },
4401
+ marshal(value, name, el) {
4402
+ return value == null ? null : String(value);
4403
+ },
4404
+ },
4405
+ number: {
4406
+ unmarshal(str, name, el) {
4407
+ return str === null ? null : Number(str);
4408
+ },
4409
+ marshal(value, name, el) {
4410
+ return value == null ? null : String(value);
4411
+ },
4412
+ },
4413
+ presence: {
4414
+ unmarshal(str, name, el) {
4415
+ return str !== null;
4416
+ },
4417
+ marshal(value, name, el) {
4418
+ return value ? '' : null;
4419
+ },
4420
+ },
4421
+ bool: {
4422
+ unmarshal(str, name, el) {
4423
+ return str === 'true';
4424
+ },
4425
+ marshal(value, name, el) {
4426
+ return value == null ? null : String(value === true);
4427
+ },
4428
+ },
4429
+ json: {
4430
+ unmarshal(str, name, el) {
4431
+ return str === null ? null : JSON.parse(str);
4432
+ },
4433
+ marshal(value, name, el) {
4434
+ return value == null ? null : JSON.stringify(value);
4435
+ },
4436
+ },
4437
+ csv: {
4438
+ unmarshal(str, name, el) {
4439
+ return str === null
4440
+ ? []
4441
+ : str
4442
+ .split(',')
4443
+ .map((e) => e.trim())
4444
+ .filter((e) => e);
4445
+ },
4446
+ marshal(value, name, el) {
4447
+ return value == null ? null : value.join(',');
4448
+ },
4449
+ },
4450
+ csvm: {
4451
+ unmarshal(str, name, el) {
4452
+ if (el.hasAttribute('multiple')) {
4453
+ return str === null
4454
+ ? []
4455
+ : str
4456
+ .split(',')
4457
+ .map((e) => e.trim())
4458
+ .filter((e) => e);
4459
+ }
4460
+ return str === null || str === '' ? null : str;
4461
+ },
4462
+ marshal(value, name, el) {
4463
+ if (el.hasAttribute('multiple')) {
4464
+ return value === null ? null : value.join(',');
4465
+ }
4466
+ return value == null ? null : String(value);
4467
+ },
4468
+ },
4469
+ };
4470
+ #components = {};
4471
+ #modules;
4472
+ #data = [];
4473
+ #upgradeQueue = new UpgradeQueue();
4474
+ defineElement(tag, klass) {
4475
+ if (!this.#configured) {
4476
+ this.#tagToClass[tag] = klass;
4477
+ return this;
4478
+ }
4479
+ this.#augmentAndDefineElement(tag, klass);
4480
+ return this;
4481
+ }
4482
+ #augmentAndDefineElement(tag, klass) {
4483
+ const { observed, attributes, template, templates, slots, mappers } = klass;
4484
+ const observedNames = (observed ?? []).map((a) => a.split(':')[0]);
4485
+ const attrToMapper = [...(attributes ?? []), ...(observed ?? [])].reduce((acc, a) => {
4486
+ const [attr, maybeType] = a.split(':');
4487
+ const type = maybeType?.trim() ?? 'string';
4488
+ if (!(type in this.#mappers) && !(type in (mappers ?? {}))) {
4489
+ throw new Error(`unsupported attribute type: ${type}`);
4490
+ }
4491
+ acc[attr.trim()] = mappers?.[type] ?? this.#mappers[type];
4492
+ return acc;
4493
+ }, {});
4494
+
4495
+ const namesAndTemplates = Object.entries(
4496
+ Object.assign({}, templates, template ? { default: template } : {}),
4497
+ ).map(([k, v]) => [k, Template.fromHtml(v)]);
4498
+ const nameToTemplate = Object.fromEntries(namesAndTemplates);
4499
+
4500
+ klass.BITS = {
4501
+ enqueue: (el) => this.#upgradeQueue.enqueue(el),
4502
+ SLOTS: slots,
4503
+ OBSERVED: observedNames,
4504
+ ATTR_TO_MAPPER: attrToMapper,
4505
+ TEMPLATES: nameToTemplate,
4506
+ };
4507
+ customElements.define(tag, klass);
4508
+ }
4509
+ defineModule(name, value) {
4510
+ const module = name ? { [name]: value } : value;
4511
+ this.#modules = { ...this.#modules, ...module };
4512
+ return this;
4513
+ }
4514
+ defineModules(ms) {
4515
+ this.#modules = ms;
4516
+ return this;
4517
+ }
4518
+ defineComponent(name, value) {
4519
+ this.#components[name] = value;
4520
+ return this;
4521
+ }
4522
+ defineData(...data) {
4523
+ this.#data = data;
4524
+ return this;
4525
+ }
4526
+ defineOverlay(...data) {
4527
+ this.#data = [...this.#data, ...data];
4528
+ return this;
4529
+ }
4530
+ defineMapper(k, v) {
4531
+ this.#mappers[k] = v;
4532
+ return this;
4533
+ }
4534
+ plugin(p) {
4535
+ p.configure(this);
4536
+ return this;
4537
+ }
4538
+ configure() {
4539
+ for (const [tag, klass] of Object.entries(this.#tagToClass)) {
4540
+ this.#augmentAndDefineElement(tag, klass);
4541
+ delete this.#tagToClass[tag];
4542
+ }
4543
+ this.#configured = true;
4544
+ return this;
4545
+ }
4546
+ get upgrades() {
4547
+ return this.#upgradeQueue.entries;
4548
+ }
4549
+ context() {
4550
+ return { modules: this.#modules, data: this.#data };
4551
+ }
4552
+ evaluator() {
4553
+ return new ExpressionEvaluator(this.#modules, this.#data);
4554
+ }
4555
+ component(name) {
4556
+ return this.#components[name];
4557
+ }
4558
+ }
4559
+
4560
+ const registry = new Registry();
4561
+
4562
+ class Templates {
4563
+ static fromHtml(html) {
4564
+ const { modules, data } = registry.context();
4565
+ return Template.fromHtml(html, modules, ...data);
4566
+ }
4567
+ static fromSelector(selector) {
4568
+ const { modules, data } = registry.context();
4569
+ return Template.fromSelector(selector, modules, ...data);
4570
+ }
4571
+ static fromTemplate(templateEl) {
4572
+ const { modules, data } = registry.context();
4573
+ return Template.fromTemplate(templateEl, modules, ...data);
4574
+ }
4575
+ static fromFragment(fragment) {
4576
+ const { modules, data } = registry.context();
4577
+ return Template.fromFragment(fragment, modules, ...data);
4578
+ }
4579
+ }
4580
+
4581
+ class Rendering {
4582
+ static async waitFor(el) {
4583
+ const pending = Array.from(registry.upgrades)
4584
+ .filter(([child, promise]) => el.contains(child))
4585
+ .map(([child, promise]) => promise);
4586
+ await Promise.all(pending);
4587
+ }
4588
+ static async waitForChildren(el) {
4589
+ const pending = Array.from(registry.upgrades)
4590
+ .filter(([child, promise]) => el !== child && el.contains(child))
4591
+ .map(([child, promise]) => promise);
4592
+ await Promise.all(pending);
4593
+ }
4594
+ }
4595
+
4596
+ /**
4597
+ * An attribute Mapper.
4598
+ *
4599
+ * @typedef {object} Mapper
4600
+ * @property {(val: string|null|undefined, name: string, el: Element) => any} unmarshal
4601
+ * @property {(val: any, name: string, el: Element) => string|null} marshal
4602
+ */
4603
+
4604
+
4605
+ class ParsedElement extends HTMLElement {
4606
+ static BITS = {
4607
+ enqueue: (el) => {},
4608
+ SLOTS: false,
4609
+ OBSERVED: [],
4610
+ /** @type {Record<string, Mapper>} */
4611
+ ATTR_TO_MAPPER: {},
4612
+ TEMPLATES: {},
4613
+ };
4614
+ static get observedAttributes() {
4615
+ return this.BITS.OBSERVED;
4616
+ }
4617
+ #parsed = false;
4618
+ #reflecting = 0;
4619
+ #bits() {
4620
+ return /** @type {typeof ParsedElement} */ (this.constructor).BITS;
4621
+ }
4622
+ unmarshal(attr, str) {
4623
+ return this.#bits().ATTR_TO_MAPPER[attr].unmarshal(str, attr, this);
4624
+ }
4625
+ marshal(attr, value) {
4626
+ return this.#bits().ATTR_TO_MAPPER[attr].marshal(value, attr, this);
4627
+ }
4628
+ /**
4629
+ * @param {string} [name] - The name of the template target, defaults to 'default'
4630
+ */
4631
+ template(name) {
4632
+ const { modules, data } = registry.context();
4633
+ let t = this.#bits().TEMPLATES[name ?? 'default'].withData(data).withModules(modules);
4634
+ for (let k of ['l10n', 'config']) {
4635
+ const v = this.constructor[k];
4636
+ if (v) {
4637
+ t = t.withOverlay({ [k]: v });
4638
+ }
4639
+ }
4640
+ return t;
4641
+ }
4642
+ connectedCallback() {
4643
+ if (this.#parsed) {
4644
+ return;
4645
+ }
4646
+ this.#bits().enqueue(this);
4647
+ }
4648
+ attributeChangedCallback(attr, oldValue, newValue) {
4649
+ if (!this.#parsed || oldValue === newValue) {
4650
+ return;
4651
+ }
4652
+ if (this.#reflecting > 0) {
4653
+ return;
4654
+ }
4655
+ this[attr] = this.unmarshal(attr, newValue);
4656
+ }
4657
+ #disabledBeforeParsed = null;
4658
+ formDisabledCallback(disabled) {
4659
+ if (!this.#parsed) {
4660
+ this.#disabledBeforeParsed = disabled;
4661
+ return;
4662
+ }
4663
+ Reflect.set(this, 'disabled', disabled);
4664
+ }
4665
+ async upgrade() {
4666
+ if (this.#parsed) {
4667
+ return;
4668
+ }
4669
+ this.#parsed = true;
4670
+ const slots = this.#bits().SLOTS ? LightSlots.from(this) : undefined;
4671
+ const observed = Object.fromEntries(
4672
+ this.#bits().OBSERVED.map((attribute) => [
4673
+ attribute,
4674
+ this.unmarshal(attribute, this.getAttribute(attribute)),
4675
+ ]),
4676
+ );
4677
+ const disabled = this.#disabledBeforeParsed ?? false;
4678
+ await this.render({ slots, observed, disabled });
4679
+ }
4680
+ render(c) {}
4681
+ reflect(fn) {
4682
+ ++this.#reflecting;
4683
+ try {
4684
+ fn();
4685
+ } finally {
4686
+ --this.#reflecting;
4687
+ }
4688
+ }
4689
+ reflectTo(attr, value) {
4690
+ ++this.#reflecting;
4691
+ try {
4692
+ Attributes.set(this, attr, this.marshal(attr, value));
4693
+ } finally {
4694
+ --this.#reflecting;
4695
+ }
4696
+ }
4697
+ }
4698
+
4699
+ export { Attributes, ExpressionEvaluator, Expressions, Fragments, LightSlots, Nodes, ParsedElement, Registry, RenderError, Rendering, Template, Templates, registry };
4700
+ //# sourceMappingURL=ftl.mjs.map