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