@skeptools/skep-organization-project 0.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 (137) hide show
  1. package/.gitattributes +23 -0
  2. package/.jsii +164 -0
  3. package/.projenrc.ts +29 -0
  4. package/API.md +3610 -0
  5. package/LICENSE +202 -0
  6. package/README.md +8 -0
  7. package/files/generated/.seed +1 -0
  8. package/files/scaffolding/.seed +1 -0
  9. package/files/scaffolding/README.md.liquid +43 -0
  10. package/lib/index.d.ts +1 -0
  11. package/lib/index.js +14 -0
  12. package/lib/skep-organization-project.d.ts +7 -0
  13. package/lib/skep-organization-project.js +24 -0
  14. package/node_modules/liquidjs/CHANGELOG.md +1015 -0
  15. package/node_modules/liquidjs/LICENSE +21 -0
  16. package/node_modules/liquidjs/README.md +163 -0
  17. package/node_modules/liquidjs/bin/liquid.js +24 -0
  18. package/node_modules/liquidjs/dist/builtin/filters/array.d.ts +15 -0
  19. package/node_modules/liquidjs/dist/builtin/filters/date.d.ts +2 -0
  20. package/node_modules/liquidjs/dist/builtin/filters/html.d.ts +4 -0
  21. package/node_modules/liquidjs/dist/builtin/filters/index.d.ts +7 -0
  22. package/node_modules/liquidjs/dist/builtin/filters/math.d.ts +11 -0
  23. package/node_modules/liquidjs/dist/builtin/filters/misc.d.ts +5 -0
  24. package/node_modules/liquidjs/dist/builtin/filters/string.d.ts +16 -0
  25. package/node_modules/liquidjs/dist/builtin/filters/url.d.ts +2 -0
  26. package/node_modules/liquidjs/dist/builtin/tags/assign.d.ts +3 -0
  27. package/node_modules/liquidjs/dist/builtin/tags/block.d.ts +8 -0
  28. package/node_modules/liquidjs/dist/builtin/tags/break.d.ts +5 -0
  29. package/node_modules/liquidjs/dist/builtin/tags/capture.d.ts +3 -0
  30. package/node_modules/liquidjs/dist/builtin/tags/case.d.ts +3 -0
  31. package/node_modules/liquidjs/dist/builtin/tags/comment.d.ts +3 -0
  32. package/node_modules/liquidjs/dist/builtin/tags/continue.d.ts +5 -0
  33. package/node_modules/liquidjs/dist/builtin/tags/cycle.d.ts +3 -0
  34. package/node_modules/liquidjs/dist/builtin/tags/decrement.d.ts +3 -0
  35. package/node_modules/liquidjs/dist/builtin/tags/echo.d.ts +3 -0
  36. package/node_modules/liquidjs/dist/builtin/tags/for.d.ts +3 -0
  37. package/node_modules/liquidjs/dist/builtin/tags/if.d.ts +3 -0
  38. package/node_modules/liquidjs/dist/builtin/tags/include.d.ts +3 -0
  39. package/node_modules/liquidjs/dist/builtin/tags/increment.d.ts +3 -0
  40. package/node_modules/liquidjs/dist/builtin/tags/index.d.ts +5 -0
  41. package/node_modules/liquidjs/dist/builtin/tags/inline-comment.d.ts +3 -0
  42. package/node_modules/liquidjs/dist/builtin/tags/layout.d.ts +3 -0
  43. package/node_modules/liquidjs/dist/builtin/tags/liquid.d.ts +3 -0
  44. package/node_modules/liquidjs/dist/builtin/tags/raw.d.ts +3 -0
  45. package/node_modules/liquidjs/dist/builtin/tags/render.d.ts +13 -0
  46. package/node_modules/liquidjs/dist/builtin/tags/tablerow.d.ts +3 -0
  47. package/node_modules/liquidjs/dist/builtin/tags/unless.d.ts +3 -0
  48. package/node_modules/liquidjs/dist/cache/cache.d.ts +7 -0
  49. package/node_modules/liquidjs/dist/cache/lru.d.ts +14 -0
  50. package/node_modules/liquidjs/dist/context/block-mode.d.ts +5 -0
  51. package/node_modules/liquidjs/dist/context/context.d.ts +53 -0
  52. package/node_modules/liquidjs/dist/context/scope.d.ts +6 -0
  53. package/node_modules/liquidjs/dist/drop/blank-drop.d.ts +4 -0
  54. package/node_modules/liquidjs/dist/drop/block-drop.d.ts +10 -0
  55. package/node_modules/liquidjs/dist/drop/comparable.d.ts +8 -0
  56. package/node_modules/liquidjs/dist/drop/drop.d.ts +3 -0
  57. package/node_modules/liquidjs/dist/drop/empty-drop.d.ts +10 -0
  58. package/node_modules/liquidjs/dist/drop/forloop-drop.d.ts +15 -0
  59. package/node_modules/liquidjs/dist/drop/null-drop.d.ts +10 -0
  60. package/node_modules/liquidjs/dist/drop/tablerowloop-drop.d.ts +10 -0
  61. package/node_modules/liquidjs/dist/emitters/emitter.d.ts +11 -0
  62. package/node_modules/liquidjs/dist/emitters/keeping-type-emitter.d.ts +5 -0
  63. package/node_modules/liquidjs/dist/emitters/simple-emitter.d.ts +5 -0
  64. package/node_modules/liquidjs/dist/emitters/streamed-emitter-browser.d.ts +10 -0
  65. package/node_modules/liquidjs/dist/emitters/streamed-emitter.d.ts +9 -0
  66. package/node_modules/liquidjs/dist/fs/browser.d.ts +7 -0
  67. package/node_modules/liquidjs/dist/fs/fs.d.ts +20 -0
  68. package/node_modules/liquidjs/dist/fs/loader.d.ts +24 -0
  69. package/node_modules/liquidjs/dist/fs/node-require.d.ts +2 -0
  70. package/node_modules/liquidjs/dist/fs/node.d.ts +9 -0
  71. package/node_modules/liquidjs/dist/liquid-options.d.ts +128 -0
  72. package/node_modules/liquidjs/dist/liquid.browser.esm.js +3523 -0
  73. package/node_modules/liquidjs/dist/liquid.browser.min.js +2 -0
  74. package/node_modules/liquidjs/dist/liquid.browser.min.js.map +1 -0
  75. package/node_modules/liquidjs/dist/liquid.browser.umd.js +4811 -0
  76. package/node_modules/liquidjs/dist/liquid.browser.umd.js.map +1 -0
  77. package/node_modules/liquidjs/dist/liquid.d.ts +43 -0
  78. package/node_modules/liquidjs/dist/liquid.node.cjs.js +4820 -0
  79. package/node_modules/liquidjs/dist/liquid.node.esm.js +3540 -0
  80. package/node_modules/liquidjs/dist/parser/filter-arg.d.ts +5 -0
  81. package/node_modules/liquidjs/dist/parser/match-operator.d.ts +2 -0
  82. package/node_modules/liquidjs/dist/parser/parse-stream.d.ts +16 -0
  83. package/node_modules/liquidjs/dist/parser/parse-string-literal.d.ts +1 -0
  84. package/node_modules/liquidjs/dist/parser/parser.d.ts +22 -0
  85. package/node_modules/liquidjs/dist/parser/token-kind.d.ts +15 -0
  86. package/node_modules/liquidjs/dist/parser/tokenizer.d.ts +66 -0
  87. package/node_modules/liquidjs/dist/parser/whitespace-ctrl.d.ts +3 -0
  88. package/node_modules/liquidjs/dist/render/boolean.d.ts +3 -0
  89. package/node_modules/liquidjs/dist/render/expression.d.ts +14 -0
  90. package/node_modules/liquidjs/dist/render/operator.d.ts +5 -0
  91. package/node_modules/liquidjs/dist/render/render.d.ts +8 -0
  92. package/node_modules/liquidjs/dist/template/filter/filter-impl-options.d.ts +4 -0
  93. package/node_modules/liquidjs/dist/template/filter/filter-impl.d.ts +6 -0
  94. package/node_modules/liquidjs/dist/template/filter/filter-map.d.ts +13 -0
  95. package/node_modules/liquidjs/dist/template/filter/filter.d.ts +12 -0
  96. package/node_modules/liquidjs/dist/template/html.d.ts +10 -0
  97. package/node_modules/liquidjs/dist/template/output.d.ts +11 -0
  98. package/node_modules/liquidjs/dist/template/tag/hash.d.ts +17 -0
  99. package/node_modules/liquidjs/dist/template/tag/tag-impl-options.d.ts +10 -0
  100. package/node_modules/liquidjs/dist/template/tag/tag-impl.d.ts +6 -0
  101. package/node_modules/liquidjs/dist/template/tag/tag-map.d.ts +6 -0
  102. package/node_modules/liquidjs/dist/template/tag/tag.d.ts +10 -0
  103. package/node_modules/liquidjs/dist/template/template-impl.d.ts +4 -0
  104. package/node_modules/liquidjs/dist/template/template.d.ts +7 -0
  105. package/node_modules/liquidjs/dist/template/value.d.ts +13 -0
  106. package/node_modules/liquidjs/dist/tokens/delimited-token.d.ts +8 -0
  107. package/node_modules/liquidjs/dist/tokens/filter-token.d.ts +7 -0
  108. package/node_modules/liquidjs/dist/tokens/hash-token.d.ts +12 -0
  109. package/node_modules/liquidjs/dist/tokens/html-token.d.ts +11 -0
  110. package/node_modules/liquidjs/dist/tokens/identifier-token.d.ts +10 -0
  111. package/node_modules/liquidjs/dist/tokens/liquid-tag-token.d.ts +7 -0
  112. package/node_modules/liquidjs/dist/tokens/literal-token.d.ts +9 -0
  113. package/node_modules/liquidjs/dist/tokens/number-token.d.ts +7 -0
  114. package/node_modules/liquidjs/dist/tokens/operator-token.d.ts +21 -0
  115. package/node_modules/liquidjs/dist/tokens/output-token.d.ts +5 -0
  116. package/node_modules/liquidjs/dist/tokens/property-access-token.d.ts +9 -0
  117. package/node_modules/liquidjs/dist/tokens/quoted-token.d.ts +8 -0
  118. package/node_modules/liquidjs/dist/tokens/range-token.d.ts +11 -0
  119. package/node_modules/liquidjs/dist/tokens/tag-token.d.ts +7 -0
  120. package/node_modules/liquidjs/dist/tokens/token.d.ts +12 -0
  121. package/node_modules/liquidjs/dist/tokens/toplevel-token.d.ts +4 -0
  122. package/node_modules/liquidjs/dist/tokens/value-token.d.ts +5 -0
  123. package/node_modules/liquidjs/dist/types.d.ts +30 -0
  124. package/node_modules/liquidjs/dist/util/assert.d.ts +1 -0
  125. package/node_modules/liquidjs/dist/util/async.d.ts +3 -0
  126. package/node_modules/liquidjs/dist/util/character.d.ts +8 -0
  127. package/node_modules/liquidjs/dist/util/collection.d.ts +2 -0
  128. package/node_modules/liquidjs/dist/util/error.d.ts +29 -0
  129. package/node_modules/liquidjs/dist/util/liquid-date.d.ts +19 -0
  130. package/node_modules/liquidjs/dist/util/literal.d.ts +11 -0
  131. package/node_modules/liquidjs/dist/util/operator-trie.d.ts +5 -0
  132. package/node_modules/liquidjs/dist/util/strftime.d.ts +2 -0
  133. package/node_modules/liquidjs/dist/util/timezone-date.d.ts +39 -0
  134. package/node_modules/liquidjs/dist/util/type-guards.d.ts +22 -0
  135. package/node_modules/liquidjs/dist/util/underscore.d.ts +37 -0
  136. package/node_modules/liquidjs/package.json +165 -0
  137. package/package.json +133 -0
@@ -0,0 +1,3523 @@
1
+ /*
2
+ * liquidjs@9.43.0, https://github.com/harttle/liquidjs
3
+ * (c) 2016-2022 harttle
4
+ * Released under the MIT License.
5
+ */
6
+ /*! *****************************************************************************
7
+ Copyright (c) Microsoft Corporation.
8
+
9
+ Permission to use, copy, modify, and/or distribute this software for any
10
+ purpose with or without fee is hereby granted.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
+ PERFORMANCE OF THIS SOFTWARE.
19
+ ***************************************************************************** */
20
+
21
+ var __assign = function() {
22
+ __assign = Object.assign || function __assign(t) {
23
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
24
+ s = arguments[i];
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
26
+ }
27
+ return t;
28
+ };
29
+ return __assign.apply(this, arguments);
30
+ };
31
+
32
+ function __awaiter(thisArg, _arguments, P, generator) {
33
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
+ return new (P || (P = Promise))(function (resolve, reject) {
35
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
39
+ });
40
+ }
41
+
42
+ class Drop {
43
+ liquidMethodMissing(key) {
44
+ return undefined;
45
+ }
46
+ }
47
+
48
+ const toString$1 = Object.prototype.toString;
49
+ const toLowerCase = String.prototype.toLowerCase;
50
+ const hasOwnProperty = Object.hasOwnProperty;
51
+ function isString(value) {
52
+ return typeof value === 'string';
53
+ }
54
+ // eslint-disable-next-line @typescript-eslint/ban-types
55
+ function isFunction(value) {
56
+ return typeof value === 'function';
57
+ }
58
+ function isPromise(val) {
59
+ return val && isFunction(val.then);
60
+ }
61
+ function isIterator(val) {
62
+ return val && isFunction(val.next) && isFunction(val.throw) && isFunction(val.return);
63
+ }
64
+ function escapeRegex(str) {
65
+ return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
66
+ }
67
+ function stringify(value) {
68
+ value = toValue(value);
69
+ if (isString(value))
70
+ return value;
71
+ if (isNil(value))
72
+ return '';
73
+ if (isArray(value))
74
+ return value.map(x => stringify(x)).join('');
75
+ return String(value);
76
+ }
77
+ function toValue(value) {
78
+ return (value instanceof Drop && isFunction(value.valueOf)) ? value.valueOf() : value;
79
+ }
80
+ function isNumber(value) {
81
+ return typeof value === 'number';
82
+ }
83
+ function toLiquid(value) {
84
+ if (value && isFunction(value.toLiquid))
85
+ return toLiquid(value.toLiquid());
86
+ return value;
87
+ }
88
+ function isNil(value) {
89
+ return value == null;
90
+ }
91
+ function isArray(value) {
92
+ // be compatible with IE 8
93
+ return toString$1.call(value) === '[object Array]';
94
+ }
95
+ function isIterable(value) {
96
+ return isObject(value) && Symbol.iterator in value;
97
+ }
98
+ /*
99
+ * Iterates over own enumerable string keyed properties of an object and invokes iteratee for each property.
100
+ * The iteratee is invoked with three arguments: (value, key, object).
101
+ * Iteratee functions may exit iteration early by explicitly returning false.
102
+ * @param {Object} object The object to iterate over.
103
+ * @param {Function} iteratee The function invoked per iteration.
104
+ * @return {Object} Returns object.
105
+ */
106
+ function forOwn(obj, iteratee) {
107
+ obj = obj || {};
108
+ for (const k in obj) {
109
+ if (hasOwnProperty.call(obj, k)) {
110
+ if (iteratee(obj[k], k, obj) === false)
111
+ break;
112
+ }
113
+ }
114
+ return obj;
115
+ }
116
+ function last$1(arr) {
117
+ return arr[arr.length - 1];
118
+ }
119
+ /*
120
+ * Checks if value is the language type of Object.
121
+ * (e.g. arrays, functions, objects, regexes, new Number(0), and new String(''))
122
+ * @param {any} value The value to check.
123
+ * @return {Boolean} Returns true if value is an object, else false.
124
+ */
125
+ function isObject(value) {
126
+ const type = typeof value;
127
+ return value !== null && (type === 'object' || type === 'function');
128
+ }
129
+ function range(start, stop, step = 1) {
130
+ const arr = [];
131
+ for (let i = start; i < stop; i += step) {
132
+ arr.push(i);
133
+ }
134
+ return arr;
135
+ }
136
+ function padStart(str, length, ch = ' ') {
137
+ return pad(str, length, ch, (str, ch) => ch + str);
138
+ }
139
+ function padEnd(str, length, ch = ' ') {
140
+ return pad(str, length, ch, (str, ch) => str + ch);
141
+ }
142
+ function pad(str, length, ch, add) {
143
+ str = String(str);
144
+ let n = length - str.length;
145
+ while (n-- > 0)
146
+ str = add(str, ch);
147
+ return str;
148
+ }
149
+ function identify(val) {
150
+ return val;
151
+ }
152
+ function snakeCase(str) {
153
+ return str.replace(/(\w?)([A-Z])/g, (_, a, b) => (a ? a + '_' : '') + b.toLowerCase());
154
+ }
155
+ function changeCase(str) {
156
+ const hasLowerCase = [...str].some(ch => ch >= 'a' && ch <= 'z');
157
+ return hasLowerCase ? str.toUpperCase() : str.toLowerCase();
158
+ }
159
+ function ellipsis(str, N) {
160
+ return str.length > N ? str.slice(0, N - 3) + '...' : str;
161
+ }
162
+ // compare string in case-insensitive way, undefined values to the tail
163
+ function caseInsensitiveCompare(a, b) {
164
+ if (a == null && b == null)
165
+ return 0;
166
+ if (a == null)
167
+ return 1;
168
+ if (b == null)
169
+ return -1;
170
+ a = toLowerCase.call(a);
171
+ b = toLowerCase.call(b);
172
+ if (a < b)
173
+ return -1;
174
+ if (a > b)
175
+ return 1;
176
+ return 0;
177
+ }
178
+ function argumentsToValue(fn) {
179
+ return (...args) => fn(...args.map(toValue));
180
+ }
181
+ function escapeRegExp(text) {
182
+ return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
183
+ }
184
+
185
+ class Node {
186
+ constructor(key, value, next, prev) {
187
+ this.key = key;
188
+ this.value = value;
189
+ this.next = next;
190
+ this.prev = prev;
191
+ }
192
+ }
193
+ class LRU {
194
+ constructor(limit, size = 0) {
195
+ this.limit = limit;
196
+ this.size = size;
197
+ this.cache = {};
198
+ this.head = new Node('HEAD', null, null, null);
199
+ this.tail = new Node('TAIL', null, null, null);
200
+ this.head.next = this.tail;
201
+ this.tail.prev = this.head;
202
+ }
203
+ write(key, value) {
204
+ if (this.cache[key]) {
205
+ this.cache[key].value = value;
206
+ }
207
+ else {
208
+ const node = new Node(key, value, this.head.next, this.head);
209
+ this.head.next.prev = node;
210
+ this.head.next = node;
211
+ this.cache[key] = node;
212
+ this.size++;
213
+ this.ensureLimit();
214
+ }
215
+ }
216
+ read(key) {
217
+ if (!this.cache[key])
218
+ return;
219
+ const { value } = this.cache[key];
220
+ this.remove(key);
221
+ this.write(key, value);
222
+ return value;
223
+ }
224
+ remove(key) {
225
+ const node = this.cache[key];
226
+ node.prev.next = node.next;
227
+ node.next.prev = node.prev;
228
+ delete this.cache[key];
229
+ this.size--;
230
+ }
231
+ clear() {
232
+ this.head.next = this.tail;
233
+ this.tail.prev = this.head;
234
+ this.size = 0;
235
+ this.cache = {};
236
+ }
237
+ ensureLimit() {
238
+ if (this.size > this.limit)
239
+ this.remove(this.tail.prev.key);
240
+ }
241
+ }
242
+
243
+ function domResolve(root, path) {
244
+ const base = document.createElement('base');
245
+ base.href = root;
246
+ const head = document.getElementsByTagName('head')[0];
247
+ head.insertBefore(base, head.firstChild);
248
+ const a = document.createElement('a');
249
+ a.href = path;
250
+ const resolved = a.href;
251
+ head.removeChild(base);
252
+ return resolved;
253
+ }
254
+ function resolve(root, filepath, ext) {
255
+ if (root.length && last$1(root) !== '/')
256
+ root += '/';
257
+ const url = domResolve(root, filepath);
258
+ return url.replace(/^(\w+:\/\/[^/]+)(\/[^?]+)/, (str, origin, path) => {
259
+ const last = path.split('/').pop();
260
+ if (/\.\w+$/.test(last))
261
+ return str;
262
+ return origin + path + ext;
263
+ });
264
+ }
265
+ function readFile(url) {
266
+ return __awaiter(this, void 0, void 0, function* () {
267
+ return new Promise((resolve, reject) => {
268
+ const xhr = new XMLHttpRequest();
269
+ xhr.onload = () => {
270
+ if (xhr.status >= 200 && xhr.status < 300) {
271
+ resolve(xhr.responseText);
272
+ }
273
+ else {
274
+ reject(new Error(xhr.statusText));
275
+ }
276
+ };
277
+ xhr.onerror = () => {
278
+ reject(new Error('An error occurred whilst receiving the response.'));
279
+ };
280
+ xhr.open('GET', url);
281
+ xhr.send();
282
+ });
283
+ });
284
+ }
285
+ function readFileSync(url) {
286
+ const xhr = new XMLHttpRequest();
287
+ xhr.open('GET', url, false);
288
+ xhr.send();
289
+ if (xhr.status < 200 || xhr.status >= 300) {
290
+ throw new Error(xhr.statusText);
291
+ }
292
+ return xhr.responseText;
293
+ }
294
+ function exists(filepath) {
295
+ return __awaiter(this, void 0, void 0, function* () {
296
+ return true;
297
+ });
298
+ }
299
+ function existsSync(filepath) {
300
+ return true;
301
+ }
302
+ function dirname(filepath) {
303
+ return domResolve(filepath, '.');
304
+ }
305
+ const sep = '/';
306
+
307
+ var fs = /*#__PURE__*/Object.freeze({
308
+ __proto__: null,
309
+ resolve: resolve,
310
+ readFile: readFile,
311
+ readFileSync: readFileSync,
312
+ exists: exists,
313
+ existsSync: existsSync,
314
+ dirname: dirname,
315
+ sep: sep
316
+ });
317
+
318
+ function isComparable(arg) {
319
+ return arg && isFunction(arg.equals);
320
+ }
321
+
322
+ function isTruthy(val, ctx) {
323
+ return !isFalsy(val, ctx);
324
+ }
325
+ function isFalsy(val, ctx) {
326
+ if (ctx.opts.jsTruthy) {
327
+ return !val;
328
+ }
329
+ else {
330
+ return val === false || undefined === val || val === null;
331
+ }
332
+ }
333
+
334
+ const defaultOperators = {
335
+ '==': (l, r) => {
336
+ if (isComparable(l))
337
+ return l.equals(r);
338
+ if (isComparable(r))
339
+ return r.equals(l);
340
+ return toValue(l) === toValue(r);
341
+ },
342
+ '!=': (l, r) => {
343
+ if (isComparable(l))
344
+ return !l.equals(r);
345
+ if (isComparable(r))
346
+ return !r.equals(l);
347
+ return toValue(l) !== toValue(r);
348
+ },
349
+ '>': (l, r) => {
350
+ if (isComparable(l))
351
+ return l.gt(r);
352
+ if (isComparable(r))
353
+ return r.lt(l);
354
+ return toValue(l) > toValue(r);
355
+ },
356
+ '<': (l, r) => {
357
+ if (isComparable(l))
358
+ return l.lt(r);
359
+ if (isComparable(r))
360
+ return r.gt(l);
361
+ return toValue(l) < toValue(r);
362
+ },
363
+ '>=': (l, r) => {
364
+ if (isComparable(l))
365
+ return l.geq(r);
366
+ if (isComparable(r))
367
+ return r.leq(l);
368
+ return toValue(l) >= toValue(r);
369
+ },
370
+ '<=': (l, r) => {
371
+ if (isComparable(l))
372
+ return l.leq(r);
373
+ if (isComparable(r))
374
+ return r.geq(l);
375
+ return toValue(l) <= toValue(r);
376
+ },
377
+ 'contains': (l, r) => {
378
+ l = toValue(l);
379
+ r = toValue(r);
380
+ return l && isFunction(l.indexOf) ? l.indexOf(r) > -1 : false;
381
+ },
382
+ 'and': (l, r, ctx) => isTruthy(toValue(l), ctx) && isTruthy(toValue(r), ctx),
383
+ 'or': (l, r, ctx) => isTruthy(toValue(l), ctx) || isTruthy(toValue(r), ctx)
384
+ };
385
+
386
+ // **DO NOT CHANGE THIS FILE**
387
+ //
388
+ // This file is generated by bin/character-gen.js
389
+ // bitmask character types to boost performance
390
+ const TYPES = [0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 4, 4, 4, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 2, 8, 0, 0, 0, 0, 8, 0, 0, 0, 64, 0, 65, 0, 0, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 0, 0, 2, 2, 2, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0];
391
+ const IDENTIFIER = 1;
392
+ const BLANK = 4;
393
+ const QUOTE = 8;
394
+ const INLINE_BLANK = 16;
395
+ const NUMBER = 32;
396
+ const SIGN = 64;
397
+ TYPES[160] = TYPES[5760] = TYPES[6158] = TYPES[8192] = TYPES[8193] = TYPES[8194] = TYPES[8195] = TYPES[8196] = TYPES[8197] = TYPES[8198] = TYPES[8199] = TYPES[8200] = TYPES[8201] = TYPES[8202] = TYPES[8232] = TYPES[8233] = TYPES[8239] = TYPES[8287] = TYPES[12288] = BLANK;
398
+
399
+ function createTrie(operators) {
400
+ const trie = {};
401
+ for (const [name, handler] of Object.entries(operators)) {
402
+ let node = trie;
403
+ for (let i = 0; i < name.length; i++) {
404
+ const c = name[i];
405
+ node[c] = node[c] || {};
406
+ if (i === name.length - 1 && (TYPES[name.charCodeAt(i)] & IDENTIFIER)) {
407
+ node[c].needBoundary = true;
408
+ }
409
+ node = node[c];
410
+ }
411
+ node.handler = handler;
412
+ node.end = true;
413
+ }
414
+ return trie;
415
+ }
416
+
417
+ const escapeMap = {
418
+ '&': '&amp;',
419
+ '<': '&lt;',
420
+ '>': '&gt;',
421
+ '"': '&#34;',
422
+ "'": '&#39;'
423
+ };
424
+ const unescapeMap = {
425
+ '&amp;': '&',
426
+ '&lt;': '<',
427
+ '&gt;': '>',
428
+ '&#34;': '"',
429
+ '&#39;': "'"
430
+ };
431
+ function escape(str) {
432
+ return stringify(str).replace(/&|<|>|"|'/g, m => escapeMap[m]);
433
+ }
434
+ function unescape(str) {
435
+ return stringify(str).replace(/&(amp|lt|gt|#34|#39);/g, m => unescapeMap[m]);
436
+ }
437
+ function escapeOnce(str) {
438
+ return escape(unescape(stringify(str)));
439
+ }
440
+ function newlineToBr(v) {
441
+ return stringify(v).replace(/\n/g, '<br />\n');
442
+ }
443
+ function stripHtml(v) {
444
+ return stringify(v).replace(/<script.*?<\/script>|<!--.*?-->|<style.*?<\/style>|<.*?>/g, '');
445
+ }
446
+
447
+ const abs = argumentsToValue(Math.abs);
448
+ const atLeast = argumentsToValue(Math.max);
449
+ const atMost = argumentsToValue(Math.min);
450
+ const ceil = argumentsToValue(Math.ceil);
451
+ const dividedBy = argumentsToValue((dividend, divisor, integerArithmetic = false) => integerArithmetic ? Math.floor(dividend / divisor) : dividend / divisor);
452
+ const floor = argumentsToValue(Math.floor);
453
+ const minus = argumentsToValue((v, arg) => v - arg);
454
+ const modulo = argumentsToValue((v, arg) => v % arg);
455
+ const times = argumentsToValue((v, arg) => v * arg);
456
+ function round(v, arg = 0) {
457
+ v = toValue(v);
458
+ arg = toValue(arg);
459
+ const amp = Math.pow(10, arg);
460
+ return Math.round(v * amp) / amp;
461
+ }
462
+ function plus(v, arg) {
463
+ v = toValue(v);
464
+ arg = toValue(arg);
465
+ return Number(v) + Number(arg);
466
+ }
467
+
468
+ const urlDecode = (x) => stringify(x).split('+').map(decodeURIComponent).join(' ');
469
+ const urlEncode = (x) => stringify(x).split(' ').map(encodeURIComponent).join('+');
470
+
471
+ function toEnumerable(val) {
472
+ val = toValue(val);
473
+ if (isArray(val))
474
+ return val;
475
+ if (isString(val) && val.length > 0)
476
+ return [val];
477
+ if (isIterable(val))
478
+ return Array.from(val);
479
+ if (isObject(val))
480
+ return Object.keys(val).map((key) => [key, val[key]]);
481
+ return [];
482
+ }
483
+ function toArray(val) {
484
+ if (isNil(val))
485
+ return [];
486
+ if (isArray(val))
487
+ return val;
488
+ return [val];
489
+ }
490
+
491
+ const join = argumentsToValue((v, arg) => toArray(v).join(arg === undefined ? ' ' : arg));
492
+ const last = argumentsToValue((v) => isArray(v) ? last$1(v) : '');
493
+ const first = argumentsToValue((v) => isArray(v) ? v[0] : '');
494
+ const reverse = argumentsToValue((v) => [...toArray(v)].reverse());
495
+ function* sort(arr, property) {
496
+ const values = [];
497
+ for (const item of toArray(toValue(arr))) {
498
+ values.push([
499
+ item,
500
+ property ? yield this.context._getFromScope(item, stringify(property).split('.')) : item
501
+ ]);
502
+ }
503
+ return values.sort((lhs, rhs) => {
504
+ const lvalue = lhs[1];
505
+ const rvalue = rhs[1];
506
+ return lvalue < rvalue ? -1 : (lvalue > rvalue ? 1 : 0);
507
+ }).map(tuple => tuple[0]);
508
+ }
509
+ function sortNatural(input, property) {
510
+ input = toValue(input);
511
+ const propertyString = stringify(property);
512
+ const compare = property === undefined
513
+ ? caseInsensitiveCompare
514
+ : (lhs, rhs) => caseInsensitiveCompare(lhs[propertyString], rhs[propertyString]);
515
+ return [...toArray(input)].sort(compare);
516
+ }
517
+ const size = (v) => (v && v.length) || 0;
518
+ function* map(arr, property) {
519
+ const results = [];
520
+ for (const item of toArray(toValue(arr))) {
521
+ results.push(yield this.context._getFromScope(item, stringify(property).split('.')));
522
+ }
523
+ return results;
524
+ }
525
+ function compact(arr) {
526
+ arr = toValue(arr);
527
+ return toArray(arr).filter(x => !isNil(toValue(x)));
528
+ }
529
+ function concat(v, arg = []) {
530
+ v = toValue(v);
531
+ arg = toArray(arg).map(v => toValue(v));
532
+ return toArray(v).concat(arg);
533
+ }
534
+ function slice(v, begin, length = 1) {
535
+ v = toValue(v);
536
+ if (isNil(v))
537
+ return [];
538
+ if (!isArray(v))
539
+ v = stringify(v);
540
+ begin = begin < 0 ? v.length + begin : begin;
541
+ return v.slice(begin, begin + length);
542
+ }
543
+ function* where(arr, property, expected) {
544
+ const values = [];
545
+ arr = toArray(toValue(arr));
546
+ for (const item of arr) {
547
+ values.push(yield this.context._getFromScope(item, stringify(property).split('.')));
548
+ }
549
+ return arr.filter((_, i) => {
550
+ if (expected === undefined)
551
+ return isTruthy(values[i], this.context);
552
+ if (isComparable(expected))
553
+ return expected.equals(values[i]);
554
+ return values[i] === expected;
555
+ });
556
+ }
557
+ function uniq(arr) {
558
+ arr = toValue(arr);
559
+ const u = {};
560
+ return (arr || []).filter(val => {
561
+ if (hasOwnProperty.call(u, String(val)))
562
+ return false;
563
+ u[String(val)] = true;
564
+ return true;
565
+ });
566
+ }
567
+
568
+ const rFormat = /%([-_0^#:]+)?(\d+)?([EO])?(.)/;
569
+ const monthNames = [
570
+ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',
571
+ 'September', 'October', 'November', 'December'
572
+ ];
573
+ const dayNames = [
574
+ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
575
+ ];
576
+ const monthNamesShort = monthNames.map(abbr);
577
+ const dayNamesShort = dayNames.map(abbr);
578
+ const suffixes = {
579
+ 1: 'st',
580
+ 2: 'nd',
581
+ 3: 'rd',
582
+ 'default': 'th'
583
+ };
584
+ function abbr(str) {
585
+ return str.slice(0, 3);
586
+ }
587
+ // prototype extensions
588
+ function daysInMonth(d) {
589
+ const feb = isLeapYear(d) ? 29 : 28;
590
+ return [31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
591
+ }
592
+ function getDayOfYear(d) {
593
+ let num = 0;
594
+ for (let i = 0; i < d.getMonth(); ++i) {
595
+ num += daysInMonth(d)[i];
596
+ }
597
+ return num + d.getDate();
598
+ }
599
+ function getWeekOfYear(d, startDay) {
600
+ // Skip to startDay of this week
601
+ const now = getDayOfYear(d) + (startDay - d.getDay());
602
+ // Find the first startDay of the year
603
+ const jan1 = new Date(d.getFullYear(), 0, 1);
604
+ const then = (7 - jan1.getDay() + startDay);
605
+ return String(Math.floor((now - then) / 7) + 1);
606
+ }
607
+ function isLeapYear(d) {
608
+ const year = d.getFullYear();
609
+ return !!((year & 3) === 0 && (year % 100 || (year % 400 === 0 && year)));
610
+ }
611
+ function getSuffix(d) {
612
+ const str = d.getDate().toString();
613
+ const index = parseInt(str.slice(-1));
614
+ return suffixes[index] || suffixes['default'];
615
+ }
616
+ function century(d) {
617
+ return parseInt(d.getFullYear().toString().substring(0, 2), 10);
618
+ }
619
+ // default to 0
620
+ const padWidths = {
621
+ d: 2,
622
+ e: 2,
623
+ H: 2,
624
+ I: 2,
625
+ j: 3,
626
+ k: 2,
627
+ l: 2,
628
+ L: 3,
629
+ m: 2,
630
+ M: 2,
631
+ S: 2,
632
+ U: 2,
633
+ W: 2
634
+ };
635
+ // default to '0'
636
+ const padChars = {
637
+ a: ' ',
638
+ A: ' ',
639
+ b: ' ',
640
+ B: ' ',
641
+ c: ' ',
642
+ e: ' ',
643
+ k: ' ',
644
+ l: ' ',
645
+ p: ' ',
646
+ P: ' '
647
+ };
648
+ const formatCodes = {
649
+ a: (d) => dayNamesShort[d.getDay()],
650
+ A: (d) => dayNames[d.getDay()],
651
+ b: (d) => monthNamesShort[d.getMonth()],
652
+ B: (d) => monthNames[d.getMonth()],
653
+ c: (d) => d.toLocaleString(),
654
+ C: (d) => century(d),
655
+ d: (d) => d.getDate(),
656
+ e: (d) => d.getDate(),
657
+ H: (d) => d.getHours(),
658
+ I: (d) => String(d.getHours() % 12 || 12),
659
+ j: (d) => getDayOfYear(d),
660
+ k: (d) => d.getHours(),
661
+ l: (d) => String(d.getHours() % 12 || 12),
662
+ L: (d) => d.getMilliseconds(),
663
+ m: (d) => d.getMonth() + 1,
664
+ M: (d) => d.getMinutes(),
665
+ N: (d, opts) => {
666
+ const width = Number(opts.width) || 9;
667
+ const str = String(d.getMilliseconds()).slice(0, width);
668
+ return padEnd(str, width, '0');
669
+ },
670
+ p: (d) => (d.getHours() < 12 ? 'AM' : 'PM'),
671
+ P: (d) => (d.getHours() < 12 ? 'am' : 'pm'),
672
+ q: (d) => getSuffix(d),
673
+ s: (d) => Math.round(d.getTime() / 1000),
674
+ S: (d) => d.getSeconds(),
675
+ u: (d) => d.getDay() || 7,
676
+ U: (d) => getWeekOfYear(d, 0),
677
+ w: (d) => d.getDay(),
678
+ W: (d) => getWeekOfYear(d, 1),
679
+ x: (d) => d.toLocaleDateString(),
680
+ X: (d) => d.toLocaleTimeString(),
681
+ y: (d) => d.getFullYear().toString().slice(2, 4),
682
+ Y: (d) => d.getFullYear(),
683
+ z: (d, opts) => {
684
+ const nOffset = Math.abs(d.getTimezoneOffset());
685
+ const h = Math.floor(nOffset / 60);
686
+ const m = nOffset % 60;
687
+ return (d.getTimezoneOffset() > 0 ? '-' : '+') +
688
+ padStart(h, 2, '0') +
689
+ (opts.flags[':'] ? ':' : '') +
690
+ padStart(m, 2, '0');
691
+ },
692
+ 't': () => '\t',
693
+ 'n': () => '\n',
694
+ '%': () => '%'
695
+ };
696
+ formatCodes.h = formatCodes.b;
697
+ function strftime (d, formatStr) {
698
+ let output = '';
699
+ let remaining = formatStr;
700
+ let match;
701
+ while ((match = rFormat.exec(remaining))) {
702
+ output += remaining.slice(0, match.index);
703
+ remaining = remaining.slice(match.index + match[0].length);
704
+ output += format(d, match);
705
+ }
706
+ return output + remaining;
707
+ }
708
+ function format(d, match) {
709
+ const [input, flagStr = '', width, modifier, conversion] = match;
710
+ const convert = formatCodes[conversion];
711
+ if (!convert)
712
+ return input;
713
+ const flags = {};
714
+ for (const flag of flagStr)
715
+ flags[flag] = true;
716
+ let ret = String(convert(d, { flags, width, modifier }));
717
+ let padChar = padChars[conversion] || '0';
718
+ let padWidth = width || padWidths[conversion] || 0;
719
+ if (flags['^'])
720
+ ret = ret.toUpperCase();
721
+ else if (flags['#'])
722
+ ret = changeCase(ret);
723
+ if (flags['_'])
724
+ padChar = ' ';
725
+ else if (flags['0'])
726
+ padChar = '0';
727
+ if (flags['-'])
728
+ padWidth = 0;
729
+ return padStart(ret, padWidth, padChar);
730
+ }
731
+
732
+ // one minute in milliseconds
733
+ const OneMinute = 60000;
734
+ const hostTimezoneOffset = new Date().getTimezoneOffset();
735
+ const ISO8601_TIMEZONE_PATTERN = /([zZ]|([+-])(\d{2}):(\d{2}))$/;
736
+ /**
737
+ * A date implementation with timezone info, just like Ruby date
738
+ *
739
+ * Implementation:
740
+ * - create a Date offset by it's timezone difference, avoiding overriding a bunch of methods
741
+ * - rewrite getTimezoneOffset() to trick strftime
742
+ */
743
+ class TimezoneDate {
744
+ constructor(init, timezoneOffset) {
745
+ if (init instanceof TimezoneDate) {
746
+ this.date = init.date;
747
+ timezoneOffset = init.timezoneOffset;
748
+ }
749
+ else {
750
+ const diff = (hostTimezoneOffset - timezoneOffset) * OneMinute;
751
+ const time = new Date(init).getTime() + diff;
752
+ this.date = new Date(time);
753
+ }
754
+ this.timezoneOffset = timezoneOffset;
755
+ }
756
+ getTime() {
757
+ return this.date.getTime();
758
+ }
759
+ getMilliseconds() {
760
+ return this.date.getMilliseconds();
761
+ }
762
+ getSeconds() {
763
+ return this.date.getSeconds();
764
+ }
765
+ getMinutes() {
766
+ return this.date.getMinutes();
767
+ }
768
+ getHours() {
769
+ return this.date.getHours();
770
+ }
771
+ getDay() {
772
+ return this.date.getDay();
773
+ }
774
+ getDate() {
775
+ return this.date.getDate();
776
+ }
777
+ getMonth() {
778
+ return this.date.getMonth();
779
+ }
780
+ getFullYear() {
781
+ return this.date.getFullYear();
782
+ }
783
+ toLocaleTimeString(locale) {
784
+ return this.date.toLocaleTimeString(locale);
785
+ }
786
+ toLocaleDateString(locale) {
787
+ return this.date.toLocaleDateString(locale);
788
+ }
789
+ getTimezoneOffset() {
790
+ return this.timezoneOffset;
791
+ }
792
+ /**
793
+ * Create a Date object fixed to it's declared Timezone. Both
794
+ * - 2021-08-06T02:29:00.000Z and
795
+ * - 2021-08-06T02:29:00.000+08:00
796
+ * will always be displayed as
797
+ * - 2021-08-06 02:29:00
798
+ * regardless timezoneOffset in JavaScript realm
799
+ *
800
+ * The implementation hack:
801
+ * Instead of calling `.getMonth()`/`.getUTCMonth()` respect to `preserveTimezones`,
802
+ * we create a different Date to trick strftime, it's both simpler and more performant.
803
+ * Given that a template is expected to be parsed fewer times than rendered.
804
+ */
805
+ static createDateFixedToTimezone(dateString) {
806
+ const m = dateString.match(ISO8601_TIMEZONE_PATTERN);
807
+ // representing a UTC timestamp
808
+ if (m && m[1] === 'Z') {
809
+ return new TimezoneDate(+new Date(dateString), 0);
810
+ }
811
+ // has a timezone specified
812
+ if (m && m[2] && m[3] && m[4]) {
813
+ const [, , sign, hours, minutes] = m;
814
+ const delta = (sign === '+' ? -1 : 1) * (parseInt(hours, 10) * 60 + parseInt(minutes, 10));
815
+ return new TimezoneDate(+new Date(dateString), delta);
816
+ }
817
+ return new Date(dateString);
818
+ }
819
+ }
820
+
821
+ function date(v, format, timeZoneOffset) {
822
+ const opts = this.context.opts;
823
+ let date;
824
+ v = toValue(v);
825
+ format = stringify(format);
826
+ if (v === 'now' || v === 'today') {
827
+ date = new Date();
828
+ }
829
+ else if (isNumber(v)) {
830
+ date = new Date(v * 1000);
831
+ }
832
+ else if (isString(v)) {
833
+ if (/^\d+$/.test(v)) {
834
+ date = new Date(+v * 1000);
835
+ }
836
+ else if (opts.preserveTimezones) {
837
+ date = TimezoneDate.createDateFixedToTimezone(v);
838
+ }
839
+ else {
840
+ date = new Date(v);
841
+ }
842
+ }
843
+ else {
844
+ date = v;
845
+ }
846
+ if (!isValidDate(date))
847
+ return v;
848
+ if (timeZoneOffset !== undefined) {
849
+ date = new TimezoneDate(date, timeZoneOffset);
850
+ }
851
+ else if (opts.timezoneOffset !== undefined) {
852
+ date = new TimezoneDate(date, opts.timezoneOffset);
853
+ }
854
+ return strftime(date, format);
855
+ }
856
+ function isValidDate(date) {
857
+ return (date instanceof Date || date instanceof TimezoneDate) && !isNaN(date.getTime());
858
+ }
859
+
860
+ function Default(value, defaultValue, ...args) {
861
+ value = toValue(value);
862
+ if (isArray(value) || isString(value))
863
+ return value.length ? value : defaultValue;
864
+ if (value === false && (new Map(args)).get('allow_false'))
865
+ return false;
866
+ return isFalsy(value, this.context) ? defaultValue : value;
867
+ }
868
+ function json(value) {
869
+ return JSON.stringify(value);
870
+ }
871
+ const raw$1 = identify;
872
+
873
+ class LiquidError extends Error {
874
+ constructor(err, token) {
875
+ super(err.message);
876
+ this.originalError = err;
877
+ this.token = token;
878
+ this.context = '';
879
+ }
880
+ update() {
881
+ const err = this.originalError;
882
+ this.context = mkContext(this.token);
883
+ this.message = mkMessage(err.message, this.token);
884
+ this.stack = this.message + '\n' + this.context +
885
+ '\n' + this.stack + '\nFrom ' + err.stack;
886
+ }
887
+ }
888
+ class TokenizationError extends LiquidError {
889
+ constructor(message, token) {
890
+ super(new Error(message), token);
891
+ this.name = 'TokenizationError';
892
+ super.update();
893
+ }
894
+ }
895
+ class ParseError extends LiquidError {
896
+ constructor(err, token) {
897
+ super(err, token);
898
+ this.name = 'ParseError';
899
+ this.message = err.message;
900
+ super.update();
901
+ }
902
+ }
903
+ class RenderError extends LiquidError {
904
+ constructor(err, tpl) {
905
+ super(err, tpl.token);
906
+ this.name = 'RenderError';
907
+ this.message = err.message;
908
+ super.update();
909
+ }
910
+ static is(obj) {
911
+ return obj.name === 'RenderError';
912
+ }
913
+ }
914
+ class UndefinedVariableError extends LiquidError {
915
+ constructor(err, token) {
916
+ super(err, token);
917
+ this.name = 'UndefinedVariableError';
918
+ this.message = err.message;
919
+ super.update();
920
+ }
921
+ }
922
+ // only used internally; raised where we don't have token information,
923
+ // so it can't be an UndefinedVariableError.
924
+ class InternalUndefinedVariableError extends Error {
925
+ constructor(variableName) {
926
+ super(`undefined variable: ${variableName}`);
927
+ this.name = 'InternalUndefinedVariableError';
928
+ this.variableName = variableName;
929
+ }
930
+ }
931
+ class AssertionError extends Error {
932
+ constructor(message) {
933
+ super(message);
934
+ this.name = 'AssertionError';
935
+ this.message = message + '';
936
+ }
937
+ }
938
+ function mkContext(token) {
939
+ const [line] = token.getPosition();
940
+ const lines = token.input.split('\n');
941
+ const begin = Math.max(line - 2, 1);
942
+ const end = Math.min(line + 3, lines.length);
943
+ const context = range(begin, end + 1)
944
+ .map(lineNumber => {
945
+ const indicator = (lineNumber === line) ? '>> ' : ' ';
946
+ const num = padStart(String(lineNumber), String(end).length);
947
+ const text = lines[lineNumber - 1];
948
+ return `${indicator}${num}| ${text}`;
949
+ })
950
+ .join('\n');
951
+ return context;
952
+ }
953
+ function mkMessage(msg, token) {
954
+ if (token.file)
955
+ msg += `, file:${token.file}`;
956
+ const [line, col] = token.getPosition();
957
+ msg += `, line:${line}, col:${col}`;
958
+ return msg;
959
+ }
960
+
961
+ function assert(predicate, message) {
962
+ if (!predicate) {
963
+ const msg = typeof message === 'function'
964
+ ? message()
965
+ : (message || `expect ${predicate} to be true`);
966
+ throw new AssertionError(msg);
967
+ }
968
+ }
969
+
970
+ /**
971
+ * String related filters
972
+ *
973
+ * * prefer stringify() to String() since `undefined`, `null` should eval ''
974
+ */
975
+ function append(v, arg) {
976
+ assert(arguments.length === 2, 'append expect 2 arguments');
977
+ return stringify(v) + stringify(arg);
978
+ }
979
+ function prepend(v, arg) {
980
+ assert(arguments.length === 2, 'prepend expect 2 arguments');
981
+ return stringify(arg) + stringify(v);
982
+ }
983
+ function lstrip(v, chars) {
984
+ if (chars) {
985
+ chars = escapeRegExp(stringify(chars));
986
+ return stringify(v).replace(new RegExp(`^[${chars}]+`, 'g'), '');
987
+ }
988
+ return stringify(v).replace(/^\s+/, '');
989
+ }
990
+ function downcase(v) {
991
+ return stringify(v).toLowerCase();
992
+ }
993
+ function upcase(str) {
994
+ return stringify(str).toUpperCase();
995
+ }
996
+ function remove(v, arg) {
997
+ return stringify(v).split(String(arg)).join('');
998
+ }
999
+ function removeFirst(v, l) {
1000
+ return stringify(v).replace(String(l), '');
1001
+ }
1002
+ function rstrip(str, chars) {
1003
+ if (chars) {
1004
+ chars = escapeRegExp(stringify(chars));
1005
+ return stringify(str).replace(new RegExp(`[${chars}]+$`, 'g'), '');
1006
+ }
1007
+ return stringify(str).replace(/\s+$/, '');
1008
+ }
1009
+ function split(v, arg) {
1010
+ const arr = stringify(v).split(String(arg));
1011
+ // align to ruby split, which is the behavior of shopify/liquid
1012
+ // see: https://ruby-doc.org/core-2.4.0/String.html#method-i-split
1013
+ while (arr.length && arr[arr.length - 1] === '')
1014
+ arr.pop();
1015
+ return arr;
1016
+ }
1017
+ function strip(v, chars) {
1018
+ if (chars) {
1019
+ chars = escapeRegExp(stringify(chars));
1020
+ return stringify(v)
1021
+ .replace(new RegExp(`^[${chars}]+`, 'g'), '')
1022
+ .replace(new RegExp(`[${chars}]+$`, 'g'), '');
1023
+ }
1024
+ return stringify(v).trim();
1025
+ }
1026
+ function stripNewlines(v) {
1027
+ return stringify(v).replace(/\n/g, '');
1028
+ }
1029
+ function capitalize(str) {
1030
+ str = stringify(str);
1031
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
1032
+ }
1033
+ function replace(v, pattern, replacement) {
1034
+ return stringify(v).split(String(pattern)).join(replacement);
1035
+ }
1036
+ function replaceFirst(v, arg1, arg2) {
1037
+ return stringify(v).replace(String(arg1), arg2);
1038
+ }
1039
+ function truncate(v, l = 50, o = '...') {
1040
+ v = stringify(v);
1041
+ if (v.length <= l)
1042
+ return v;
1043
+ return v.substring(0, l - o.length) + o;
1044
+ }
1045
+ function truncatewords(v, words = 15, o = '...') {
1046
+ const arr = stringify(v).split(/\s+/);
1047
+ if (words <= 0)
1048
+ words = 1;
1049
+ let ret = arr.slice(0, words).join(' ');
1050
+ if (arr.length >= words)
1051
+ ret += o;
1052
+ return ret;
1053
+ }
1054
+
1055
+ var builtinFilters = /*#__PURE__*/Object.freeze({
1056
+ __proto__: null,
1057
+ escape: escape,
1058
+ escapeOnce: escapeOnce,
1059
+ newlineToBr: newlineToBr,
1060
+ stripHtml: stripHtml,
1061
+ abs: abs,
1062
+ atLeast: atLeast,
1063
+ atMost: atMost,
1064
+ ceil: ceil,
1065
+ dividedBy: dividedBy,
1066
+ floor: floor,
1067
+ minus: minus,
1068
+ modulo: modulo,
1069
+ times: times,
1070
+ round: round,
1071
+ plus: plus,
1072
+ urlDecode: urlDecode,
1073
+ urlEncode: urlEncode,
1074
+ join: join,
1075
+ last: last,
1076
+ first: first,
1077
+ reverse: reverse,
1078
+ sort: sort,
1079
+ sortNatural: sortNatural,
1080
+ size: size,
1081
+ map: map,
1082
+ compact: compact,
1083
+ concat: concat,
1084
+ slice: slice,
1085
+ where: where,
1086
+ uniq: uniq,
1087
+ date: date,
1088
+ Default: Default,
1089
+ json: json,
1090
+ raw: raw$1,
1091
+ append: append,
1092
+ prepend: prepend,
1093
+ lstrip: lstrip,
1094
+ downcase: downcase,
1095
+ upcase: upcase,
1096
+ remove: remove,
1097
+ removeFirst: removeFirst,
1098
+ rstrip: rstrip,
1099
+ split: split,
1100
+ strip: strip,
1101
+ stripNewlines: stripNewlines,
1102
+ capitalize: capitalize,
1103
+ replace: replace,
1104
+ replaceFirst: replaceFirst,
1105
+ truncate: truncate,
1106
+ truncatewords: truncatewords
1107
+ });
1108
+
1109
+ var TokenKind;
1110
+ (function (TokenKind) {
1111
+ TokenKind[TokenKind["Number"] = 1] = "Number";
1112
+ TokenKind[TokenKind["Literal"] = 2] = "Literal";
1113
+ TokenKind[TokenKind["Tag"] = 4] = "Tag";
1114
+ TokenKind[TokenKind["Output"] = 8] = "Output";
1115
+ TokenKind[TokenKind["HTML"] = 16] = "HTML";
1116
+ TokenKind[TokenKind["Filter"] = 32] = "Filter";
1117
+ TokenKind[TokenKind["Hash"] = 64] = "Hash";
1118
+ TokenKind[TokenKind["PropertyAccess"] = 128] = "PropertyAccess";
1119
+ TokenKind[TokenKind["Word"] = 256] = "Word";
1120
+ TokenKind[TokenKind["Range"] = 512] = "Range";
1121
+ TokenKind[TokenKind["Quoted"] = 1024] = "Quoted";
1122
+ TokenKind[TokenKind["Operator"] = 2048] = "Operator";
1123
+ TokenKind[TokenKind["Delimited"] = 12] = "Delimited";
1124
+ })(TokenKind || (TokenKind = {}));
1125
+
1126
+ function isDelimitedToken(val) {
1127
+ return !!(getKind(val) & TokenKind.Delimited);
1128
+ }
1129
+ function isOperatorToken(val) {
1130
+ return getKind(val) === TokenKind.Operator;
1131
+ }
1132
+ function isHTMLToken(val) {
1133
+ return getKind(val) === TokenKind.HTML;
1134
+ }
1135
+ function isOutputToken(val) {
1136
+ return getKind(val) === TokenKind.Output;
1137
+ }
1138
+ function isTagToken(val) {
1139
+ return getKind(val) === TokenKind.Tag;
1140
+ }
1141
+ function isQuotedToken(val) {
1142
+ return getKind(val) === TokenKind.Quoted;
1143
+ }
1144
+ function isLiteralToken(val) {
1145
+ return getKind(val) === TokenKind.Literal;
1146
+ }
1147
+ function isNumberToken(val) {
1148
+ return getKind(val) === TokenKind.Number;
1149
+ }
1150
+ function isPropertyAccessToken(val) {
1151
+ return getKind(val) === TokenKind.PropertyAccess;
1152
+ }
1153
+ function isWordToken(val) {
1154
+ return getKind(val) === TokenKind.Word;
1155
+ }
1156
+ function isRangeToken(val) {
1157
+ return getKind(val) === TokenKind.Range;
1158
+ }
1159
+ function getKind(val) {
1160
+ return val ? val.kind : -1;
1161
+ }
1162
+
1163
+ var typeGuards = /*#__PURE__*/Object.freeze({
1164
+ __proto__: null,
1165
+ isDelimitedToken: isDelimitedToken,
1166
+ isOperatorToken: isOperatorToken,
1167
+ isHTMLToken: isHTMLToken,
1168
+ isOutputToken: isOutputToken,
1169
+ isTagToken: isTagToken,
1170
+ isQuotedToken: isQuotedToken,
1171
+ isLiteralToken: isLiteralToken,
1172
+ isNumberToken: isNumberToken,
1173
+ isPropertyAccessToken: isPropertyAccessToken,
1174
+ isWordToken: isWordToken,
1175
+ isRangeToken: isRangeToken
1176
+ });
1177
+
1178
+ class NullDrop extends Drop {
1179
+ equals(value) {
1180
+ return isNil(toValue(value));
1181
+ }
1182
+ gt() {
1183
+ return false;
1184
+ }
1185
+ geq() {
1186
+ return false;
1187
+ }
1188
+ lt() {
1189
+ return false;
1190
+ }
1191
+ leq() {
1192
+ return false;
1193
+ }
1194
+ valueOf() {
1195
+ return null;
1196
+ }
1197
+ }
1198
+
1199
+ class EmptyDrop extends Drop {
1200
+ equals(value) {
1201
+ if (value instanceof EmptyDrop)
1202
+ return false;
1203
+ value = toValue(value);
1204
+ if (isString(value) || isArray(value))
1205
+ return value.length === 0;
1206
+ if (isObject(value))
1207
+ return Object.keys(value).length === 0;
1208
+ return false;
1209
+ }
1210
+ gt() {
1211
+ return false;
1212
+ }
1213
+ geq() {
1214
+ return false;
1215
+ }
1216
+ lt() {
1217
+ return false;
1218
+ }
1219
+ leq() {
1220
+ return false;
1221
+ }
1222
+ valueOf() {
1223
+ return '';
1224
+ }
1225
+ }
1226
+
1227
+ class BlankDrop extends EmptyDrop {
1228
+ equals(value) {
1229
+ if (value === false)
1230
+ return true;
1231
+ if (isNil(toValue(value)))
1232
+ return true;
1233
+ if (isString(value))
1234
+ return /^\s*$/.test(value);
1235
+ return super.equals(value);
1236
+ }
1237
+ }
1238
+
1239
+ const nil = new NullDrop();
1240
+ const literalValues = {
1241
+ 'true': true,
1242
+ 'false': false,
1243
+ 'nil': nil,
1244
+ 'null': nil,
1245
+ 'empty': new EmptyDrop(),
1246
+ 'blank': new BlankDrop()
1247
+ };
1248
+
1249
+ const rHex = /[\da-fA-F]/;
1250
+ const rOct = /[0-7]/;
1251
+ const escapeChar = {
1252
+ b: '\b',
1253
+ f: '\f',
1254
+ n: '\n',
1255
+ r: '\r',
1256
+ t: '\t',
1257
+ v: '\x0B'
1258
+ };
1259
+ function hexVal(c) {
1260
+ const code = c.charCodeAt(0);
1261
+ if (code >= 97)
1262
+ return code - 87;
1263
+ if (code >= 65)
1264
+ return code - 55;
1265
+ return code - 48;
1266
+ }
1267
+ function parseStringLiteral(str) {
1268
+ let ret = '';
1269
+ for (let i = 1; i < str.length - 1; i++) {
1270
+ if (str[i] !== '\\') {
1271
+ ret += str[i];
1272
+ continue;
1273
+ }
1274
+ if (escapeChar[str[i + 1]] !== undefined) {
1275
+ ret += escapeChar[str[++i]];
1276
+ }
1277
+ else if (str[i + 1] === 'u') {
1278
+ let val = 0;
1279
+ let j = i + 2;
1280
+ while (j <= i + 5 && rHex.test(str[j])) {
1281
+ val = val * 16 + hexVal(str[j++]);
1282
+ }
1283
+ i = j - 1;
1284
+ ret += String.fromCharCode(val);
1285
+ }
1286
+ else if (!rOct.test(str[i + 1])) {
1287
+ ret += str[++i];
1288
+ }
1289
+ else {
1290
+ let j = i + 1;
1291
+ let val = 0;
1292
+ while (j <= i + 3 && rOct.test(str[j])) {
1293
+ val = val * 8 + hexVal(str[j++]);
1294
+ }
1295
+ i = j - 1;
1296
+ ret += String.fromCharCode(val);
1297
+ }
1298
+ }
1299
+ return ret;
1300
+ }
1301
+
1302
+ // convert an async iterator to a Promise
1303
+ function toPromise(val) {
1304
+ return __awaiter(this, void 0, void 0, function* () {
1305
+ if (!isIterator(val))
1306
+ return val;
1307
+ let value;
1308
+ let done = false;
1309
+ let next = 'next';
1310
+ do {
1311
+ const state = val[next](value);
1312
+ done = state.done;
1313
+ value = state.value;
1314
+ next = 'next';
1315
+ try {
1316
+ if (isIterator(value))
1317
+ value = toPromise(value);
1318
+ if (isPromise(value))
1319
+ value = yield value;
1320
+ }
1321
+ catch (err) {
1322
+ next = 'throw';
1323
+ value = err;
1324
+ }
1325
+ } while (!done);
1326
+ return value;
1327
+ });
1328
+ }
1329
+ // convert an async iterator to a value in a synchronous manner
1330
+ function toValueSync(val) {
1331
+ if (!isIterator(val))
1332
+ return val;
1333
+ let value;
1334
+ let done = false;
1335
+ let next = 'next';
1336
+ do {
1337
+ const state = val[next](value);
1338
+ done = state.done;
1339
+ value = state.value;
1340
+ next = 'next';
1341
+ if (isIterator(value)) {
1342
+ try {
1343
+ value = toValueSync(value);
1344
+ }
1345
+ catch (err) {
1346
+ next = 'throw';
1347
+ value = err;
1348
+ }
1349
+ }
1350
+ } while (!done);
1351
+ return value;
1352
+ }
1353
+ const toThenable = toPromise;
1354
+
1355
+ class Expression {
1356
+ constructor(tokens) {
1357
+ this.postfix = [...toPostfix(tokens)];
1358
+ }
1359
+ *evaluate(ctx, lenient) {
1360
+ assert(ctx, 'unable to evaluate: context not defined');
1361
+ const operands = [];
1362
+ for (const token of this.postfix) {
1363
+ if (isOperatorToken(token)) {
1364
+ const r = operands.pop();
1365
+ const l = operands.pop();
1366
+ const result = yield evalOperatorToken(ctx.opts.operators, token, l, r, ctx);
1367
+ operands.push(result);
1368
+ }
1369
+ else {
1370
+ operands.push(yield _evalToken(token, ctx, lenient && this.postfix.length === 1));
1371
+ }
1372
+ }
1373
+ return operands[0];
1374
+ }
1375
+ }
1376
+ /**
1377
+ * @deprecated use `_evalToken` instead
1378
+ */
1379
+ function* evalToken(token, ctx, lenient = false) {
1380
+ return toValueSync(_evalToken(token, ctx, lenient));
1381
+ }
1382
+ function* _evalToken(token, ctx, lenient = false) {
1383
+ if (isPropertyAccessToken(token))
1384
+ return yield evalPropertyAccessToken(token, ctx, lenient);
1385
+ if (isRangeToken(token))
1386
+ return yield evalRangeToken(token, ctx);
1387
+ if (isLiteralToken(token))
1388
+ return evalLiteralToken(token);
1389
+ if (isNumberToken(token))
1390
+ return evalNumberToken(token);
1391
+ if (isWordToken(token))
1392
+ return token.getText();
1393
+ if (isQuotedToken(token))
1394
+ return evalQuotedToken(token);
1395
+ }
1396
+ function* evalPropertyAccessToken(token, ctx, lenient) {
1397
+ const props = [];
1398
+ for (const prop of token.props) {
1399
+ props.push((yield _evalToken(prop, ctx, false)));
1400
+ }
1401
+ try {
1402
+ return yield ctx._get([token.propertyName, ...props]);
1403
+ }
1404
+ catch (e) {
1405
+ if (lenient && e.name === 'InternalUndefinedVariableError')
1406
+ return null;
1407
+ throw (new UndefinedVariableError(e, token));
1408
+ }
1409
+ }
1410
+ function evalNumberToken(token) {
1411
+ const str = token.whole.content + '.' + (token.decimal ? token.decimal.content : '');
1412
+ return Number(str);
1413
+ }
1414
+ function evalQuotedToken(token) {
1415
+ return parseStringLiteral(token.getText());
1416
+ }
1417
+ function evalOperatorToken(operators, token, lhs, rhs, ctx) {
1418
+ const impl = operators[token.operator];
1419
+ return impl(lhs, rhs, ctx);
1420
+ }
1421
+ function evalLiteralToken(token) {
1422
+ return literalValues[token.literal];
1423
+ }
1424
+ function* evalRangeToken(token, ctx) {
1425
+ const low = yield _evalToken(token.lhs, ctx);
1426
+ const high = yield _evalToken(token.rhs, ctx);
1427
+ return range(+low, +high + 1);
1428
+ }
1429
+ function* toPostfix(tokens) {
1430
+ const ops = [];
1431
+ for (const token of tokens) {
1432
+ if (isOperatorToken(token)) {
1433
+ while (ops.length && ops[ops.length - 1].getPrecedence() > token.getPrecedence()) {
1434
+ yield ops.pop();
1435
+ }
1436
+ ops.push(token);
1437
+ }
1438
+ else
1439
+ yield token;
1440
+ }
1441
+ while (ops.length) {
1442
+ yield ops.pop();
1443
+ }
1444
+ }
1445
+
1446
+ class Token {
1447
+ constructor(kind, input, begin, end, file) {
1448
+ this.kind = kind;
1449
+ this.input = input;
1450
+ this.begin = begin;
1451
+ this.end = end;
1452
+ this.file = file;
1453
+ }
1454
+ getText() {
1455
+ return this.input.slice(this.begin, this.end);
1456
+ }
1457
+ getPosition() {
1458
+ let [row, col] = [1, 1];
1459
+ for (let i = 0; i < this.begin; i++) {
1460
+ if (this.input[i] === '\n') {
1461
+ row++;
1462
+ col = 1;
1463
+ }
1464
+ else
1465
+ col++;
1466
+ }
1467
+ return [row, col];
1468
+ }
1469
+ size() {
1470
+ return this.end - this.begin;
1471
+ }
1472
+ }
1473
+
1474
+ class DelimitedToken extends Token {
1475
+ constructor(kind, content, input, begin, end, trimLeft, trimRight, file) {
1476
+ super(kind, input, begin, end, file);
1477
+ this.trimLeft = false;
1478
+ this.trimRight = false;
1479
+ this.content = this.getText();
1480
+ const tl = content[0] === '-';
1481
+ const tr = last$1(content) === '-';
1482
+ this.content = content
1483
+ .slice(tl ? 1 : 0, tr ? -1 : content.length)
1484
+ .trim();
1485
+ this.trimLeft = tl || trimLeft;
1486
+ this.trimRight = tr || trimRight;
1487
+ }
1488
+ }
1489
+
1490
+ function whiteSpaceCtrl(tokens, options) {
1491
+ let inRaw = false;
1492
+ for (let i = 0; i < tokens.length; i++) {
1493
+ const token = tokens[i];
1494
+ if (!isDelimitedToken(token))
1495
+ continue;
1496
+ if (!inRaw && token.trimLeft) {
1497
+ trimLeft(tokens[i - 1], options.greedy);
1498
+ }
1499
+ if (isTagToken(token)) {
1500
+ if (token.name === 'raw')
1501
+ inRaw = true;
1502
+ else if (token.name === 'endraw')
1503
+ inRaw = false;
1504
+ }
1505
+ if (!inRaw && token.trimRight) {
1506
+ trimRight(tokens[i + 1], options.greedy);
1507
+ }
1508
+ }
1509
+ }
1510
+ function trimLeft(token, greedy) {
1511
+ if (!token || !isHTMLToken(token))
1512
+ return;
1513
+ const mask = greedy ? BLANK : INLINE_BLANK;
1514
+ while (TYPES[token.input.charCodeAt(token.end - 1 - token.trimRight)] & mask)
1515
+ token.trimRight++;
1516
+ }
1517
+ function trimRight(token, greedy) {
1518
+ if (!token || !isHTMLToken(token))
1519
+ return;
1520
+ const mask = greedy ? BLANK : INLINE_BLANK;
1521
+ while (TYPES[token.input.charCodeAt(token.begin + token.trimLeft)] & mask)
1522
+ token.trimLeft++;
1523
+ if (token.input.charAt(token.begin + token.trimLeft) === '\n')
1524
+ token.trimLeft++;
1525
+ }
1526
+
1527
+ class NumberToken extends Token {
1528
+ constructor(whole, decimal) {
1529
+ super(TokenKind.Number, whole.input, whole.begin, decimal ? decimal.end : whole.end, whole.file);
1530
+ this.whole = whole;
1531
+ this.decimal = decimal;
1532
+ }
1533
+ }
1534
+
1535
+ class IdentifierToken extends Token {
1536
+ constructor(input, begin, end, file) {
1537
+ super(TokenKind.Word, input, begin, end, file);
1538
+ this.input = input;
1539
+ this.begin = begin;
1540
+ this.end = end;
1541
+ this.file = file;
1542
+ this.content = this.getText();
1543
+ }
1544
+ isNumber(allowSign = false) {
1545
+ const begin = allowSign && TYPES[this.input.charCodeAt(this.begin)] & SIGN
1546
+ ? this.begin + 1
1547
+ : this.begin;
1548
+ for (let i = begin; i < this.end; i++) {
1549
+ if (!(TYPES[this.input.charCodeAt(i)] & NUMBER))
1550
+ return false;
1551
+ }
1552
+ return true;
1553
+ }
1554
+ }
1555
+
1556
+ class LiteralToken extends Token {
1557
+ constructor(input, begin, end, file) {
1558
+ super(TokenKind.Literal, input, begin, end, file);
1559
+ this.input = input;
1560
+ this.begin = begin;
1561
+ this.end = end;
1562
+ this.file = file;
1563
+ this.literal = this.getText();
1564
+ }
1565
+ }
1566
+
1567
+ const precedence = {
1568
+ '==': 1,
1569
+ '!=': 1,
1570
+ '>': 1,
1571
+ '<': 1,
1572
+ '>=': 1,
1573
+ '<=': 1,
1574
+ 'contains': 1,
1575
+ 'and': 0,
1576
+ 'or': 0
1577
+ };
1578
+ class OperatorToken extends Token {
1579
+ constructor(input, begin, end, file) {
1580
+ super(TokenKind.Operator, input, begin, end, file);
1581
+ this.input = input;
1582
+ this.begin = begin;
1583
+ this.end = end;
1584
+ this.file = file;
1585
+ this.operator = this.getText();
1586
+ }
1587
+ getPrecedence() {
1588
+ const key = this.getText();
1589
+ return key in precedence ? precedence[key] : 1;
1590
+ }
1591
+ }
1592
+
1593
+ class PropertyAccessToken extends Token {
1594
+ constructor(variable, props, end) {
1595
+ super(TokenKind.PropertyAccess, variable.input, variable.begin, end, variable.file);
1596
+ this.variable = variable;
1597
+ this.props = props;
1598
+ this.propertyName = this.variable instanceof IdentifierToken
1599
+ ? this.variable.getText()
1600
+ : parseStringLiteral(this.variable.getText());
1601
+ }
1602
+ }
1603
+
1604
+ class FilterToken extends Token {
1605
+ constructor(name, args, input, begin, end, file) {
1606
+ super(TokenKind.Filter, input, begin, end, file);
1607
+ this.name = name;
1608
+ this.args = args;
1609
+ }
1610
+ }
1611
+
1612
+ class HashToken extends Token {
1613
+ constructor(input, begin, end, name, value, file) {
1614
+ super(TokenKind.Hash, input, begin, end, file);
1615
+ this.input = input;
1616
+ this.begin = begin;
1617
+ this.end = end;
1618
+ this.name = name;
1619
+ this.value = value;
1620
+ this.file = file;
1621
+ }
1622
+ }
1623
+
1624
+ class QuotedToken extends Token {
1625
+ constructor(input, begin, end, file) {
1626
+ super(TokenKind.Quoted, input, begin, end, file);
1627
+ this.input = input;
1628
+ this.begin = begin;
1629
+ this.end = end;
1630
+ this.file = file;
1631
+ }
1632
+ }
1633
+
1634
+ class HTMLToken extends Token {
1635
+ constructor(input, begin, end, file) {
1636
+ super(TokenKind.HTML, input, begin, end, file);
1637
+ this.input = input;
1638
+ this.begin = begin;
1639
+ this.end = end;
1640
+ this.file = file;
1641
+ this.trimLeft = 0;
1642
+ this.trimRight = 0;
1643
+ }
1644
+ getContent() {
1645
+ return this.input.slice(this.begin + this.trimLeft, this.end - this.trimRight);
1646
+ }
1647
+ }
1648
+
1649
+ class RangeToken extends Token {
1650
+ constructor(input, begin, end, lhs, rhs, file) {
1651
+ super(TokenKind.Range, input, begin, end, file);
1652
+ this.input = input;
1653
+ this.begin = begin;
1654
+ this.end = end;
1655
+ this.lhs = lhs;
1656
+ this.rhs = rhs;
1657
+ this.file = file;
1658
+ }
1659
+ }
1660
+
1661
+ class OutputToken extends DelimitedToken {
1662
+ constructor(input, begin, end, options, file) {
1663
+ const { trimOutputLeft, trimOutputRight, outputDelimiterLeft, outputDelimiterRight } = options;
1664
+ const value = input.slice(begin + outputDelimiterLeft.length, end - outputDelimiterRight.length);
1665
+ super(TokenKind.Output, value, input, begin, end, trimOutputLeft, trimOutputRight, file);
1666
+ }
1667
+ }
1668
+
1669
+ function matchOperator(str, begin, trie, end = str.length) {
1670
+ let node = trie;
1671
+ let i = begin;
1672
+ let info;
1673
+ while (node[str[i]] && i < end) {
1674
+ node = node[str[i++]];
1675
+ if (node['end'])
1676
+ info = node;
1677
+ }
1678
+ if (!info)
1679
+ return -1;
1680
+ if (info['needBoundary'] && (TYPES[str.charCodeAt(i)] & IDENTIFIER))
1681
+ return -1;
1682
+ return i;
1683
+ }
1684
+
1685
+ class LiquidTagToken extends DelimitedToken {
1686
+ constructor(input, begin, end, options, file) {
1687
+ const value = input.slice(begin, end);
1688
+ super(TokenKind.Tag, value, input, begin, end, false, false, file);
1689
+ if (!/\S/.test(value)) {
1690
+ // A line that contains only whitespace.
1691
+ this.name = '';
1692
+ this.args = '';
1693
+ }
1694
+ else {
1695
+ const tokenizer = new Tokenizer(this.content, options.operatorsTrie);
1696
+ this.name = tokenizer.readTagName();
1697
+ if (!this.name)
1698
+ throw new TokenizationError(`illegal liquid tag syntax`, this);
1699
+ tokenizer.skipBlank();
1700
+ this.args = tokenizer.remaining();
1701
+ }
1702
+ }
1703
+ }
1704
+
1705
+ class Tokenizer {
1706
+ constructor(input, trie = defaultOptions.operatorsTrie, file = '') {
1707
+ this.input = input;
1708
+ this.trie = trie;
1709
+ this.file = file;
1710
+ this.p = 0;
1711
+ this.rawBeginAt = -1;
1712
+ this.N = input.length;
1713
+ }
1714
+ readExpression() {
1715
+ return new Expression(this.readExpressionTokens());
1716
+ }
1717
+ *readExpressionTokens() {
1718
+ const operand = this.readValue();
1719
+ if (!operand)
1720
+ return;
1721
+ yield operand;
1722
+ while (this.p < this.N) {
1723
+ const operator = this.readOperator();
1724
+ if (!operator)
1725
+ return;
1726
+ const operand = this.readValue();
1727
+ if (!operand)
1728
+ return;
1729
+ yield operator;
1730
+ yield operand;
1731
+ }
1732
+ }
1733
+ readOperator() {
1734
+ this.skipBlank();
1735
+ const end = matchOperator(this.input, this.p, this.trie);
1736
+ if (end === -1)
1737
+ return;
1738
+ return new OperatorToken(this.input, this.p, (this.p = end), this.file);
1739
+ }
1740
+ readFilters() {
1741
+ const filters = [];
1742
+ while (true) {
1743
+ const filter = this.readFilter();
1744
+ if (!filter)
1745
+ return filters;
1746
+ filters.push(filter);
1747
+ }
1748
+ }
1749
+ readFilter() {
1750
+ this.skipBlank();
1751
+ if (this.end())
1752
+ return null;
1753
+ assert(this.peek() === '|', () => `unexpected token at ${this.snapshot()}`);
1754
+ this.p++;
1755
+ const begin = this.p;
1756
+ const name = this.readIdentifier();
1757
+ if (!name.size())
1758
+ return null;
1759
+ const args = [];
1760
+ this.skipBlank();
1761
+ if (this.peek() === ':') {
1762
+ do {
1763
+ ++this.p;
1764
+ const arg = this.readFilterArg();
1765
+ arg && args.push(arg);
1766
+ this.skipBlank();
1767
+ assert(this.end() || this.peek() === ',' || this.peek() === '|', () => `unexpected character ${this.snapshot()}`);
1768
+ } while (this.peek() === ',');
1769
+ }
1770
+ return new FilterToken(name.getText(), args, this.input, begin, this.p, this.file);
1771
+ }
1772
+ readFilterArg() {
1773
+ const key = this.readValue();
1774
+ if (!key)
1775
+ return;
1776
+ this.skipBlank();
1777
+ if (this.peek() !== ':')
1778
+ return key;
1779
+ ++this.p;
1780
+ const value = this.readValue();
1781
+ return [key.getText(), value];
1782
+ }
1783
+ readTopLevelTokens(options = defaultOptions) {
1784
+ const tokens = [];
1785
+ while (this.p < this.N) {
1786
+ const token = this.readTopLevelToken(options);
1787
+ tokens.push(token);
1788
+ }
1789
+ whiteSpaceCtrl(tokens, options);
1790
+ return tokens;
1791
+ }
1792
+ readTopLevelToken(options) {
1793
+ const { tagDelimiterLeft, outputDelimiterLeft } = options;
1794
+ if (this.rawBeginAt > -1)
1795
+ return this.readEndrawOrRawContent(options);
1796
+ if (this.match(tagDelimiterLeft))
1797
+ return this.readTagToken(options);
1798
+ if (this.match(outputDelimiterLeft))
1799
+ return this.readOutputToken(options);
1800
+ return this.readHTMLToken([tagDelimiterLeft, outputDelimiterLeft]);
1801
+ }
1802
+ readHTMLToken(stopStrings) {
1803
+ const begin = this.p;
1804
+ while (this.p < this.N) {
1805
+ if (stopStrings.some(str => this.match(str)))
1806
+ break;
1807
+ ++this.p;
1808
+ }
1809
+ return new HTMLToken(this.input, begin, this.p, this.file);
1810
+ }
1811
+ readTagToken(options = defaultOptions) {
1812
+ const { file, input } = this;
1813
+ const begin = this.p;
1814
+ if (this.readToDelimiter(options.tagDelimiterRight) === -1) {
1815
+ throw this.mkError(`tag ${this.snapshot(begin)} not closed`, begin);
1816
+ }
1817
+ const token = new TagToken(input, begin, this.p, options, file);
1818
+ if (token.name === 'raw')
1819
+ this.rawBeginAt = begin;
1820
+ return token;
1821
+ }
1822
+ readToDelimiter(delimiter) {
1823
+ while (this.p < this.N) {
1824
+ if ((this.peekType() & QUOTE)) {
1825
+ this.readQuoted();
1826
+ continue;
1827
+ }
1828
+ ++this.p;
1829
+ if (this.rmatch(delimiter))
1830
+ return this.p;
1831
+ }
1832
+ return -1;
1833
+ }
1834
+ readOutputToken(options = defaultOptions) {
1835
+ const { file, input } = this;
1836
+ const { outputDelimiterRight } = options;
1837
+ const begin = this.p;
1838
+ if (this.readToDelimiter(outputDelimiterRight) === -1) {
1839
+ throw this.mkError(`output ${this.snapshot(begin)} not closed`, begin);
1840
+ }
1841
+ return new OutputToken(input, begin, this.p, options, file);
1842
+ }
1843
+ readEndrawOrRawContent(options) {
1844
+ const { tagDelimiterLeft, tagDelimiterRight } = options;
1845
+ const begin = this.p;
1846
+ let leftPos = this.readTo(tagDelimiterLeft) - tagDelimiterLeft.length;
1847
+ while (this.p < this.N) {
1848
+ if (this.readIdentifier().getText() !== 'endraw') {
1849
+ leftPos = this.readTo(tagDelimiterLeft) - tagDelimiterLeft.length;
1850
+ continue;
1851
+ }
1852
+ while (this.p <= this.N) {
1853
+ if (this.rmatch(tagDelimiterRight)) {
1854
+ const end = this.p;
1855
+ if (begin === leftPos) {
1856
+ this.rawBeginAt = -1;
1857
+ return new TagToken(this.input, begin, end, options, this.file);
1858
+ }
1859
+ else {
1860
+ this.p = leftPos;
1861
+ return new HTMLToken(this.input, begin, leftPos, this.file);
1862
+ }
1863
+ }
1864
+ if (this.rmatch(tagDelimiterLeft))
1865
+ break;
1866
+ this.p++;
1867
+ }
1868
+ }
1869
+ throw this.mkError(`raw ${this.snapshot(this.rawBeginAt)} not closed`, begin);
1870
+ }
1871
+ readLiquidTagTokens(options = defaultOptions) {
1872
+ const tokens = [];
1873
+ while (this.p < this.N) {
1874
+ const token = this.readLiquidTagToken(options);
1875
+ if (token.name)
1876
+ tokens.push(token);
1877
+ }
1878
+ return tokens;
1879
+ }
1880
+ readLiquidTagToken(options) {
1881
+ const { file, input } = this;
1882
+ const begin = this.p;
1883
+ let end = this.N;
1884
+ if (this.readToDelimiter('\n') !== -1)
1885
+ end = this.p;
1886
+ return new LiquidTagToken(input, begin, end, options, file);
1887
+ }
1888
+ mkError(msg, begin) {
1889
+ return new TokenizationError(msg, new IdentifierToken(this.input, begin, this.N, this.file));
1890
+ }
1891
+ snapshot(begin = this.p) {
1892
+ return JSON.stringify(ellipsis(this.input.slice(begin), 16));
1893
+ }
1894
+ /**
1895
+ * @deprecated
1896
+ */
1897
+ readWord() {
1898
+ console.warn('Tokenizer#readWord() will be removed, use #readIdentifier instead');
1899
+ return this.readIdentifier();
1900
+ }
1901
+ readIdentifier() {
1902
+ this.skipBlank();
1903
+ const begin = this.p;
1904
+ while (this.peekType() & IDENTIFIER)
1905
+ ++this.p;
1906
+ return new IdentifierToken(this.input, begin, this.p, this.file);
1907
+ }
1908
+ readTagName() {
1909
+ this.skipBlank();
1910
+ // Handle inline comment tags
1911
+ if (this.input[this.p] === '#')
1912
+ return this.input.slice(this.p, ++this.p);
1913
+ return this.readIdentifier().getText();
1914
+ }
1915
+ readHashes(jekyllStyle) {
1916
+ const hashes = [];
1917
+ while (true) {
1918
+ const hash = this.readHash(jekyllStyle);
1919
+ if (!hash)
1920
+ return hashes;
1921
+ hashes.push(hash);
1922
+ }
1923
+ }
1924
+ readHash(jekyllStyle) {
1925
+ this.skipBlank();
1926
+ if (this.peek() === ',')
1927
+ ++this.p;
1928
+ const begin = this.p;
1929
+ const name = this.readIdentifier();
1930
+ if (!name.size())
1931
+ return;
1932
+ let value;
1933
+ this.skipBlank();
1934
+ const sep = jekyllStyle ? '=' : ':';
1935
+ if (this.peek() === sep) {
1936
+ ++this.p;
1937
+ value = this.readValue();
1938
+ }
1939
+ return new HashToken(this.input, begin, this.p, name, value, this.file);
1940
+ }
1941
+ remaining() {
1942
+ return this.input.slice(this.p);
1943
+ }
1944
+ advance(i = 1) {
1945
+ this.p += i;
1946
+ }
1947
+ end() {
1948
+ return this.p >= this.N;
1949
+ }
1950
+ readTo(end) {
1951
+ while (this.p < this.N) {
1952
+ ++this.p;
1953
+ if (this.rmatch(end))
1954
+ return this.p;
1955
+ }
1956
+ return -1;
1957
+ }
1958
+ readValue() {
1959
+ const value = this.readQuoted() || this.readRange();
1960
+ if (value)
1961
+ return value;
1962
+ if (this.peek() === '[') {
1963
+ this.p++;
1964
+ const prop = this.readQuoted();
1965
+ if (!prop)
1966
+ return;
1967
+ if (this.peek() !== ']')
1968
+ return;
1969
+ this.p++;
1970
+ return new PropertyAccessToken(prop, [], this.p);
1971
+ }
1972
+ const variable = this.readIdentifier();
1973
+ if (!variable.size())
1974
+ return;
1975
+ let isNumber = variable.isNumber(true);
1976
+ const props = [];
1977
+ while (true) {
1978
+ if (this.peek() === '[') {
1979
+ isNumber = false;
1980
+ this.p++;
1981
+ const prop = this.readValue() || new IdentifierToken(this.input, this.p, this.p, this.file);
1982
+ this.readTo(']');
1983
+ props.push(prop);
1984
+ }
1985
+ else if (this.peek() === '.' && this.peek(1) !== '.') { // skip range syntax
1986
+ this.p++;
1987
+ const prop = this.readIdentifier();
1988
+ if (!prop.size())
1989
+ break;
1990
+ if (!prop.isNumber())
1991
+ isNumber = false;
1992
+ props.push(prop);
1993
+ }
1994
+ else
1995
+ break;
1996
+ }
1997
+ if (!props.length && literalValues.hasOwnProperty(variable.content)) {
1998
+ return new LiteralToken(this.input, variable.begin, variable.end, this.file);
1999
+ }
2000
+ if (isNumber)
2001
+ return new NumberToken(variable, props[0]);
2002
+ return new PropertyAccessToken(variable, props, this.p);
2003
+ }
2004
+ readRange() {
2005
+ this.skipBlank();
2006
+ const begin = this.p;
2007
+ if (this.peek() !== '(')
2008
+ return;
2009
+ ++this.p;
2010
+ const lhs = this.readValueOrThrow();
2011
+ this.p += 2;
2012
+ const rhs = this.readValueOrThrow();
2013
+ ++this.p;
2014
+ return new RangeToken(this.input, begin, this.p, lhs, rhs, this.file);
2015
+ }
2016
+ readValueOrThrow() {
2017
+ const value = this.readValue();
2018
+ assert(value, () => `unexpected token ${this.snapshot()}, value expected`);
2019
+ return value;
2020
+ }
2021
+ readQuoted() {
2022
+ this.skipBlank();
2023
+ const begin = this.p;
2024
+ if (!(this.peekType() & QUOTE))
2025
+ return;
2026
+ ++this.p;
2027
+ let escaped = false;
2028
+ while (this.p < this.N) {
2029
+ ++this.p;
2030
+ if (this.input[this.p - 1] === this.input[begin] && !escaped)
2031
+ break;
2032
+ if (escaped)
2033
+ escaped = false;
2034
+ else if (this.input[this.p - 1] === '\\')
2035
+ escaped = true;
2036
+ }
2037
+ return new QuotedToken(this.input, begin, this.p, this.file);
2038
+ }
2039
+ *readFileNameTemplate(options) {
2040
+ const { outputDelimiterLeft } = options;
2041
+ const htmlStopStrings = [',', ' ', outputDelimiterLeft];
2042
+ const htmlStopStringSet = new Set(htmlStopStrings);
2043
+ // break on ',' and ' ', outputDelimiterLeft only stops HTML token
2044
+ while (this.p < this.N && !htmlStopStringSet.has(this.peek())) {
2045
+ yield this.match(outputDelimiterLeft)
2046
+ ? this.readOutputToken(options)
2047
+ : this.readHTMLToken(htmlStopStrings);
2048
+ }
2049
+ }
2050
+ match(word) {
2051
+ for (let i = 0; i < word.length; i++) {
2052
+ if (word[i] !== this.input[this.p + i])
2053
+ return false;
2054
+ }
2055
+ return true;
2056
+ }
2057
+ rmatch(pattern) {
2058
+ for (let i = 0; i < pattern.length; i++) {
2059
+ if (pattern[pattern.length - 1 - i] !== this.input[this.p - 1 - i])
2060
+ return false;
2061
+ }
2062
+ return true;
2063
+ }
2064
+ peekType(n = 0) {
2065
+ return TYPES[this.input.charCodeAt(this.p + n)];
2066
+ }
2067
+ peek(n = 0) {
2068
+ return this.input[this.p + n];
2069
+ }
2070
+ skipBlank() {
2071
+ while (this.peekType() & BLANK)
2072
+ ++this.p;
2073
+ }
2074
+ }
2075
+
2076
+ class TagToken extends DelimitedToken {
2077
+ constructor(input, begin, end, options, file) {
2078
+ const { trimTagLeft, trimTagRight, tagDelimiterLeft, tagDelimiterRight } = options;
2079
+ const value = input.slice(begin + tagDelimiterLeft.length, end - tagDelimiterRight.length);
2080
+ super(TokenKind.Tag, value, input, begin, end, trimTagLeft, trimTagRight, file);
2081
+ const tokenizer = new Tokenizer(this.content, options.operatorsTrie);
2082
+ this.name = tokenizer.readTagName();
2083
+ if (!this.name)
2084
+ throw new TokenizationError(`illegal tag syntax`, this);
2085
+ tokenizer.skipBlank();
2086
+ this.args = tokenizer.remaining();
2087
+ }
2088
+ }
2089
+
2090
+ class ParseStream {
2091
+ constructor(tokens, parseToken) {
2092
+ this.handlers = {};
2093
+ this.stopRequested = false;
2094
+ this.tokens = tokens;
2095
+ this.parseToken = parseToken;
2096
+ }
2097
+ on(name, cb) {
2098
+ this.handlers[name] = cb;
2099
+ return this;
2100
+ }
2101
+ trigger(event, arg) {
2102
+ const h = this.handlers[event];
2103
+ return h ? (h.call(this, arg), true) : false;
2104
+ }
2105
+ start() {
2106
+ this.trigger('start');
2107
+ let token;
2108
+ while (!this.stopRequested && (token = this.tokens.shift())) {
2109
+ if (this.trigger('token', token))
2110
+ continue;
2111
+ if (isTagToken(token) && this.trigger(`tag:${token.name}`, token)) {
2112
+ continue;
2113
+ }
2114
+ const template = this.parseToken(token, this.tokens);
2115
+ this.trigger('template', template);
2116
+ }
2117
+ if (!this.stopRequested)
2118
+ this.trigger('end');
2119
+ return this;
2120
+ }
2121
+ stop() {
2122
+ this.stopRequested = true;
2123
+ return this;
2124
+ }
2125
+ }
2126
+
2127
+ /**
2128
+ * Key-Value Pairs Representing Tag Arguments
2129
+ * Example:
2130
+ * For the markup `, foo:'bar', coo:2 reversed %}`,
2131
+ * hash['foo'] === 'bar'
2132
+ * hash['coo'] === 2
2133
+ * hash['reversed'] === undefined
2134
+ */
2135
+ class Hash {
2136
+ constructor(markup, jekyllStyle) {
2137
+ this.hash = {};
2138
+ const tokenizer = new Tokenizer(markup, {});
2139
+ for (const hash of tokenizer.readHashes(jekyllStyle)) {
2140
+ this.hash[hash.name.content] = hash.value;
2141
+ }
2142
+ }
2143
+ *render(ctx) {
2144
+ const hash = {};
2145
+ for (const key of Object.keys(this.hash)) {
2146
+ hash[key] = this.hash[key] === undefined ? true : yield _evalToken(this.hash[key], ctx);
2147
+ }
2148
+ return hash;
2149
+ }
2150
+ }
2151
+
2152
+ function isKeyValuePair(arr) {
2153
+ return isArray(arr);
2154
+ }
2155
+
2156
+ class Filter {
2157
+ constructor(name, impl, args, liquid) {
2158
+ this.name = name;
2159
+ this.impl = impl || identify;
2160
+ this.args = args;
2161
+ this.liquid = liquid;
2162
+ }
2163
+ *render(value, context) {
2164
+ const argv = [];
2165
+ for (const arg of this.args) {
2166
+ if (isKeyValuePair(arg))
2167
+ argv.push([arg[0], yield _evalToken(arg[1], context)]);
2168
+ else
2169
+ argv.push(yield _evalToken(arg, context));
2170
+ }
2171
+ return this.impl.apply({ context, liquid: this.liquid }, [value, ...argv]);
2172
+ }
2173
+ }
2174
+
2175
+ class Value {
2176
+ /**
2177
+ * @param str the value to be valuated, eg.: "foobar" | truncate: 3
2178
+ */
2179
+ constructor(str, liquid) {
2180
+ this.filters = [];
2181
+ const tokenizer = new Tokenizer(str, liquid.options.operatorsTrie);
2182
+ this.initial = tokenizer.readExpression();
2183
+ this.filters = tokenizer.readFilters().map(({ name, args }) => new Filter(name, liquid.filters.get(name), args, liquid));
2184
+ }
2185
+ *value(ctx, lenient) {
2186
+ lenient = lenient || (ctx.opts.lenientIf && this.filters.length > 0 && this.filters[0].name === 'default');
2187
+ let val = yield this.initial.evaluate(ctx, lenient);
2188
+ for (const filter of this.filters) {
2189
+ val = yield filter.render(val, ctx);
2190
+ }
2191
+ return val;
2192
+ }
2193
+ }
2194
+
2195
+ var assign = {
2196
+ parse: function (token) {
2197
+ const tokenizer = new Tokenizer(token.args, this.liquid.options.operatorsTrie);
2198
+ this.key = tokenizer.readIdentifier().content;
2199
+ tokenizer.skipBlank();
2200
+ assert(tokenizer.peek() === '=', () => `illegal token ${token.getText()}`);
2201
+ tokenizer.advance();
2202
+ this.value = new Value(tokenizer.remaining(), this.liquid);
2203
+ },
2204
+ render: function* (ctx) {
2205
+ ctx.bottom()[this.key] = yield this.value.value(ctx, this.liquid.options.lenientIf);
2206
+ }
2207
+ };
2208
+
2209
+ class ForloopDrop extends Drop {
2210
+ constructor(length, collection, variable) {
2211
+ super();
2212
+ this.i = 0;
2213
+ this.length = length;
2214
+ this.name = `${variable}-${collection}`;
2215
+ }
2216
+ next() {
2217
+ this.i++;
2218
+ }
2219
+ index0() {
2220
+ return this.i;
2221
+ }
2222
+ index() {
2223
+ return this.i + 1;
2224
+ }
2225
+ first() {
2226
+ return this.i === 0;
2227
+ }
2228
+ last() {
2229
+ return this.i === this.length - 1;
2230
+ }
2231
+ rindex() {
2232
+ return this.length - this.i;
2233
+ }
2234
+ rindex0() {
2235
+ return this.length - this.i - 1;
2236
+ }
2237
+ valueOf() {
2238
+ return JSON.stringify(this);
2239
+ }
2240
+ }
2241
+
2242
+ const MODIFIERS = ['offset', 'limit', 'reversed'];
2243
+ var For = {
2244
+ type: 'block',
2245
+ parse: function (token, remainTokens) {
2246
+ const tokenizer = new Tokenizer(token.args, this.liquid.options.operatorsTrie);
2247
+ const variable = tokenizer.readIdentifier();
2248
+ const inStr = tokenizer.readIdentifier();
2249
+ const collection = tokenizer.readValue();
2250
+ assert(variable.size() && inStr.content === 'in' && collection, () => `illegal tag: ${token.getText()}`);
2251
+ this.variable = variable.content;
2252
+ this.collection = collection;
2253
+ this.hash = new Hash(tokenizer.remaining());
2254
+ this.templates = [];
2255
+ this.elseTemplates = [];
2256
+ let p;
2257
+ const stream = this.liquid.parser.parseStream(remainTokens)
2258
+ .on('start', () => (p = this.templates))
2259
+ .on('tag:else', () => (p = this.elseTemplates))
2260
+ .on('tag:endfor', () => stream.stop())
2261
+ .on('template', (tpl) => p.push(tpl))
2262
+ .on('end', () => {
2263
+ throw new Error(`tag ${token.getText()} not closed`);
2264
+ });
2265
+ stream.start();
2266
+ },
2267
+ render: function* (ctx, emitter) {
2268
+ const r = this.liquid.renderer;
2269
+ let collection = toEnumerable(yield _evalToken(this.collection, ctx));
2270
+ if (!collection.length) {
2271
+ yield r.renderTemplates(this.elseTemplates, ctx, emitter);
2272
+ return;
2273
+ }
2274
+ const continueKey = 'continue-' + this.variable + '-' + this.collection.getText();
2275
+ ctx.push({ continue: ctx.getRegister(continueKey) });
2276
+ const hash = yield this.hash.render(ctx);
2277
+ ctx.pop();
2278
+ const modifiers = this.liquid.options.orderedFilterParameters
2279
+ ? Object.keys(hash).filter(x => MODIFIERS.includes(x))
2280
+ : MODIFIERS.filter(x => hash[x] !== undefined);
2281
+ collection = modifiers.reduce((collection, modifier) => {
2282
+ if (modifier === 'offset')
2283
+ return offset(collection, hash['offset']);
2284
+ if (modifier === 'limit')
2285
+ return limit(collection, hash['limit']);
2286
+ return reversed(collection);
2287
+ }, collection);
2288
+ ctx.setRegister(continueKey, (hash['offset'] || 0) + collection.length);
2289
+ const scope = { forloop: new ForloopDrop(collection.length, this.collection.getText(), this.variable) };
2290
+ ctx.push(scope);
2291
+ for (const item of collection) {
2292
+ scope[this.variable] = item;
2293
+ yield r.renderTemplates(this.templates, ctx, emitter);
2294
+ if (emitter['break']) {
2295
+ emitter['break'] = false;
2296
+ break;
2297
+ }
2298
+ emitter['continue'] = false;
2299
+ scope.forloop.next();
2300
+ }
2301
+ ctx.pop();
2302
+ }
2303
+ };
2304
+ function reversed(arr) {
2305
+ return [...arr].reverse();
2306
+ }
2307
+ function offset(arr, count) {
2308
+ return arr.slice(count);
2309
+ }
2310
+ function limit(arr, count) {
2311
+ return arr.slice(0, count);
2312
+ }
2313
+
2314
+ var capture = {
2315
+ parse: function (tagToken, remainTokens) {
2316
+ const tokenizer = new Tokenizer(tagToken.args, this.liquid.options.operatorsTrie);
2317
+ this.variable = readVariableName(tokenizer);
2318
+ assert(this.variable, () => `${tagToken.args} not valid identifier`);
2319
+ this.templates = [];
2320
+ const stream = this.liquid.parser.parseStream(remainTokens);
2321
+ stream.on('tag:endcapture', () => stream.stop())
2322
+ .on('template', (tpl) => this.templates.push(tpl))
2323
+ .on('end', () => {
2324
+ throw new Error(`tag ${tagToken.getText()} not closed`);
2325
+ });
2326
+ stream.start();
2327
+ },
2328
+ render: function* (ctx) {
2329
+ const r = this.liquid.renderer;
2330
+ const html = yield r.renderTemplates(this.templates, ctx);
2331
+ ctx.bottom()[this.variable] = html;
2332
+ }
2333
+ };
2334
+ function readVariableName(tokenizer) {
2335
+ const word = tokenizer.readIdentifier().content;
2336
+ if (word)
2337
+ return word;
2338
+ const quoted = tokenizer.readQuoted();
2339
+ if (quoted)
2340
+ return evalQuotedToken(quoted);
2341
+ }
2342
+
2343
+ var Case = {
2344
+ parse: function (tagToken, remainTokens) {
2345
+ this.cond = new Value(tagToken.args, this.liquid);
2346
+ this.cases = [];
2347
+ this.elseTemplates = [];
2348
+ let p = [];
2349
+ const stream = this.liquid.parser.parseStream(remainTokens)
2350
+ .on('tag:when', (token) => {
2351
+ p = [];
2352
+ const tokenizer = new Tokenizer(token.args, this.liquid.options.operatorsTrie);
2353
+ while (!tokenizer.end()) {
2354
+ const value = tokenizer.readValue();
2355
+ this.cases.push({
2356
+ val: value,
2357
+ templates: p
2358
+ });
2359
+ tokenizer.readTo(',');
2360
+ }
2361
+ })
2362
+ .on('tag:else', () => (p = this.elseTemplates))
2363
+ .on('tag:endcase', () => stream.stop())
2364
+ .on('template', (tpl) => p.push(tpl))
2365
+ .on('end', () => {
2366
+ throw new Error(`tag ${tagToken.getText()} not closed`);
2367
+ });
2368
+ stream.start();
2369
+ },
2370
+ render: function* (ctx, emitter) {
2371
+ const r = this.liquid.renderer;
2372
+ const cond = toValue(yield this.cond.value(ctx, ctx.opts.lenientIf));
2373
+ for (const branch of this.cases) {
2374
+ const val = yield _evalToken(branch.val, ctx, ctx.opts.lenientIf);
2375
+ if (val === cond) {
2376
+ yield r.renderTemplates(branch.templates, ctx, emitter);
2377
+ return;
2378
+ }
2379
+ }
2380
+ yield r.renderTemplates(this.elseTemplates, ctx, emitter);
2381
+ }
2382
+ };
2383
+
2384
+ var comment = {
2385
+ parse: function (tagToken, remainTokens) {
2386
+ const stream = this.liquid.parser.parseStream(remainTokens);
2387
+ stream
2388
+ .on('token', (token) => {
2389
+ if (token.name === 'endcomment')
2390
+ stream.stop();
2391
+ })
2392
+ .on('end', () => {
2393
+ throw new Error(`tag ${tagToken.getText()} not closed`);
2394
+ });
2395
+ stream.start();
2396
+ }
2397
+ };
2398
+
2399
+ var BlockMode;
2400
+ (function (BlockMode) {
2401
+ /* store rendered html into blocks */
2402
+ BlockMode[BlockMode["OUTPUT"] = 0] = "OUTPUT";
2403
+ /* output rendered html directly */
2404
+ BlockMode[BlockMode["STORE"] = 1] = "STORE";
2405
+ })(BlockMode || (BlockMode = {}));
2406
+ var BlockMode$1 = BlockMode;
2407
+
2408
+ var render = {
2409
+ parseFilePath,
2410
+ renderFilePath,
2411
+ parse: function (token) {
2412
+ const args = token.args;
2413
+ const tokenizer = new Tokenizer(args, this.liquid.options.operatorsTrie);
2414
+ this['file'] = this.parseFilePath(tokenizer, this.liquid);
2415
+ this['currentFile'] = token.file;
2416
+ while (!tokenizer.end()) {
2417
+ tokenizer.skipBlank();
2418
+ const begin = tokenizer.p;
2419
+ const keyword = tokenizer.readIdentifier();
2420
+ if (keyword.content === 'with' || keyword.content === 'for') {
2421
+ tokenizer.skipBlank();
2422
+ // can be normal key/value pair, like "with: true"
2423
+ if (tokenizer.peek() !== ':') {
2424
+ const value = tokenizer.readValue();
2425
+ // can be normal key, like "with,"
2426
+ if (value) {
2427
+ const beforeAs = tokenizer.p;
2428
+ const asStr = tokenizer.readIdentifier();
2429
+ let alias;
2430
+ if (asStr.content === 'as')
2431
+ alias = tokenizer.readIdentifier();
2432
+ else
2433
+ tokenizer.p = beforeAs;
2434
+ this[keyword.content] = { value, alias: alias && alias.content };
2435
+ tokenizer.skipBlank();
2436
+ if (tokenizer.peek() === ',')
2437
+ tokenizer.advance();
2438
+ // matched!
2439
+ continue;
2440
+ }
2441
+ }
2442
+ }
2443
+ /**
2444
+ * restore cursor if with/for not matched
2445
+ */
2446
+ tokenizer.p = begin;
2447
+ break;
2448
+ }
2449
+ this.hash = new Hash(tokenizer.remaining());
2450
+ },
2451
+ render: function* (ctx, emitter) {
2452
+ const { liquid, hash } = this;
2453
+ const filepath = yield this.renderFilePath(this['file'], ctx, liquid);
2454
+ assert(filepath, () => `illegal filename "${filepath}"`);
2455
+ const childCtx = new Context({}, ctx.opts, { sync: ctx.sync, globals: ctx.globals, strictVariables: ctx.strictVariables });
2456
+ const scope = childCtx.bottom();
2457
+ __assign(scope, yield hash.render(ctx));
2458
+ if (this['with']) {
2459
+ const { value, alias } = this['with'];
2460
+ scope[alias || filepath] = yield _evalToken(value, ctx);
2461
+ }
2462
+ if (this['for']) {
2463
+ const { value, alias } = this['for'];
2464
+ let collection = yield _evalToken(value, ctx);
2465
+ collection = toEnumerable(collection);
2466
+ scope['forloop'] = new ForloopDrop(collection.length, value.getText(), alias);
2467
+ for (const item of collection) {
2468
+ scope[alias] = item;
2469
+ const templates = yield liquid._parsePartialFile(filepath, childCtx.sync, this['currentFile']);
2470
+ yield liquid.renderer.renderTemplates(templates, childCtx, emitter);
2471
+ scope['forloop'].next();
2472
+ }
2473
+ }
2474
+ else {
2475
+ const templates = yield liquid._parsePartialFile(filepath, childCtx.sync, this['currentFile']);
2476
+ yield liquid.renderer.renderTemplates(templates, childCtx, emitter);
2477
+ }
2478
+ }
2479
+ };
2480
+ /**
2481
+ * @return null for "none",
2482
+ * @return Template[] for quoted with tags and/or filters
2483
+ * @return Token for expression (not quoted)
2484
+ * @throws TypeError if cannot read next token
2485
+ */
2486
+ function parseFilePath(tokenizer, liquid) {
2487
+ if (liquid.options.dynamicPartials) {
2488
+ const file = tokenizer.readValue();
2489
+ if (file === undefined)
2490
+ throw new TypeError(`illegal argument "${tokenizer.input}"`);
2491
+ if (file.getText() === 'none')
2492
+ return null;
2493
+ if (isQuotedToken(file)) {
2494
+ // for filenames like "files/{{file}}", eval as liquid template
2495
+ const templates = liquid.parse(evalQuotedToken(file));
2496
+ return optimize(templates);
2497
+ }
2498
+ return file;
2499
+ }
2500
+ const tokens = [...tokenizer.readFileNameTemplate(liquid.options)];
2501
+ const templates = optimize(liquid.parser.parseTokens(tokens));
2502
+ return templates === 'none' ? null : templates;
2503
+ }
2504
+ function optimize(templates) {
2505
+ // for filenames like "files/file.liquid", extract the string directly
2506
+ if (templates.length === 1 && isHTMLToken(templates[0].token))
2507
+ return templates[0].token.getContent();
2508
+ return templates;
2509
+ }
2510
+ function* renderFilePath(file, ctx, liquid) {
2511
+ if (typeof file === 'string')
2512
+ return file;
2513
+ if (Array.isArray(file))
2514
+ return liquid.renderer.renderTemplates(file, ctx);
2515
+ return yield _evalToken(file, ctx);
2516
+ }
2517
+
2518
+ var include = {
2519
+ parseFilePath,
2520
+ renderFilePath,
2521
+ parse: function (token) {
2522
+ const args = token.args;
2523
+ const tokenizer = new Tokenizer(args, this.liquid.options.operatorsTrie);
2524
+ this['file'] = this.parseFilePath(tokenizer, this.liquid);
2525
+ this['currentFile'] = token.file;
2526
+ const begin = tokenizer.p;
2527
+ const withStr = tokenizer.readIdentifier();
2528
+ if (withStr.content === 'with') {
2529
+ tokenizer.skipBlank();
2530
+ if (tokenizer.peek() !== ':') {
2531
+ this.withVar = tokenizer.readValue();
2532
+ }
2533
+ else
2534
+ tokenizer.p = begin;
2535
+ }
2536
+ else
2537
+ tokenizer.p = begin;
2538
+ this.hash = new Hash(tokenizer.remaining(), this.liquid.options.jekyllInclude);
2539
+ },
2540
+ render: function* (ctx, emitter) {
2541
+ const { liquid, hash, withVar } = this;
2542
+ const { renderer } = liquid;
2543
+ const filepath = yield this.renderFilePath(this['file'], ctx, liquid);
2544
+ assert(filepath, () => `illegal filename "${filepath}"`);
2545
+ const saved = ctx.saveRegister('blocks', 'blockMode');
2546
+ ctx.setRegister('blocks', {});
2547
+ ctx.setRegister('blockMode', BlockMode$1.OUTPUT);
2548
+ const scope = yield hash.render(ctx);
2549
+ if (withVar)
2550
+ scope[filepath] = yield _evalToken(withVar, ctx);
2551
+ const templates = yield liquid._parsePartialFile(filepath, ctx.sync, this['currentFile']);
2552
+ ctx.push(ctx.opts.jekyllInclude ? { include: scope } : scope);
2553
+ yield renderer.renderTemplates(templates, ctx, emitter);
2554
+ ctx.pop();
2555
+ ctx.restoreRegister(saved);
2556
+ }
2557
+ };
2558
+
2559
+ var decrement = {
2560
+ parse: function (token) {
2561
+ const tokenizer = new Tokenizer(token.args, this.liquid.options.operatorsTrie);
2562
+ this.variable = tokenizer.readIdentifier().content;
2563
+ },
2564
+ render: function (context, emitter) {
2565
+ const scope = context.environments;
2566
+ if (!isNumber(scope[this.variable])) {
2567
+ scope[this.variable] = 0;
2568
+ }
2569
+ emitter.write(stringify(--scope[this.variable]));
2570
+ }
2571
+ };
2572
+
2573
+ var cycle = {
2574
+ parse: function (tagToken) {
2575
+ const tokenizer = new Tokenizer(tagToken.args, this.liquid.options.operatorsTrie);
2576
+ const group = tokenizer.readValue();
2577
+ tokenizer.skipBlank();
2578
+ this.candidates = [];
2579
+ if (group) {
2580
+ if (tokenizer.peek() === ':') {
2581
+ this.group = group;
2582
+ tokenizer.advance();
2583
+ }
2584
+ else
2585
+ this.candidates.push(group);
2586
+ }
2587
+ while (!tokenizer.end()) {
2588
+ const value = tokenizer.readValue();
2589
+ if (value)
2590
+ this.candidates.push(value);
2591
+ tokenizer.readTo(',');
2592
+ }
2593
+ assert(this.candidates.length, () => `empty candidates: ${tagToken.getText()}`);
2594
+ },
2595
+ render: function* (ctx, emitter) {
2596
+ const group = yield _evalToken(this.group, ctx);
2597
+ const fingerprint = `cycle:${group}:` + this.candidates.join(',');
2598
+ const groups = ctx.getRegister('cycle');
2599
+ let idx = groups[fingerprint];
2600
+ if (idx === undefined) {
2601
+ idx = groups[fingerprint] = 0;
2602
+ }
2603
+ const candidate = this.candidates[idx];
2604
+ idx = (idx + 1) % this.candidates.length;
2605
+ groups[fingerprint] = idx;
2606
+ const html = yield _evalToken(candidate, ctx);
2607
+ emitter.write(html);
2608
+ }
2609
+ };
2610
+
2611
+ var If = {
2612
+ parse: function (tagToken, remainTokens) {
2613
+ this.branches = [];
2614
+ this.elseTemplates = [];
2615
+ let p;
2616
+ this.liquid.parser.parseStream(remainTokens)
2617
+ .on('start', () => this.branches.push({
2618
+ predicate: new Value(tagToken.args, this.liquid),
2619
+ templates: (p = [])
2620
+ }))
2621
+ .on('tag:elsif', (token) => this.branches.push({
2622
+ predicate: new Value(token.args, this.liquid),
2623
+ templates: (p = [])
2624
+ }))
2625
+ .on('tag:else', () => (p = this.elseTemplates))
2626
+ .on('tag:endif', function () { this.stop(); })
2627
+ .on('template', (tpl) => p.push(tpl))
2628
+ .on('end', () => { throw new Error(`tag ${tagToken.getText()} not closed`); })
2629
+ .start();
2630
+ },
2631
+ render: function* (ctx, emitter) {
2632
+ const r = this.liquid.renderer;
2633
+ for (const { predicate, templates } of this.branches) {
2634
+ const value = yield predicate.value(ctx, ctx.opts.lenientIf);
2635
+ if (isTruthy(value, ctx)) {
2636
+ yield r.renderTemplates(templates, ctx, emitter);
2637
+ return;
2638
+ }
2639
+ }
2640
+ yield r.renderTemplates(this.elseTemplates, ctx, emitter);
2641
+ }
2642
+ };
2643
+
2644
+ var increment = {
2645
+ parse: function (token) {
2646
+ const tokenizer = new Tokenizer(token.args, this.liquid.options.operatorsTrie);
2647
+ this.variable = tokenizer.readIdentifier().content;
2648
+ },
2649
+ render: function (context, emitter) {
2650
+ const scope = context.environments;
2651
+ if (!isNumber(scope[this.variable])) {
2652
+ scope[this.variable] = 0;
2653
+ }
2654
+ const val = scope[this.variable];
2655
+ scope[this.variable]++;
2656
+ emitter.write(stringify(val));
2657
+ }
2658
+ };
2659
+
2660
+ var layout = {
2661
+ parseFilePath,
2662
+ renderFilePath,
2663
+ parse: function (token, remainTokens) {
2664
+ const tokenizer = new Tokenizer(token.args, this.liquid.options.operatorsTrie);
2665
+ this['file'] = this.parseFilePath(tokenizer, this.liquid);
2666
+ this['currentFile'] = token.file;
2667
+ this.hash = new Hash(tokenizer.remaining());
2668
+ this.tpls = this.liquid.parser.parseTokens(remainTokens);
2669
+ },
2670
+ render: function* (ctx, emitter) {
2671
+ const { liquid, hash, file } = this;
2672
+ const { renderer } = liquid;
2673
+ if (file === null) {
2674
+ ctx.setRegister('blockMode', BlockMode$1.OUTPUT);
2675
+ yield renderer.renderTemplates(this.tpls, ctx, emitter);
2676
+ return;
2677
+ }
2678
+ const filepath = yield this.renderFilePath(this['file'], ctx, liquid);
2679
+ assert(filepath, () => `illegal filename "${filepath}"`);
2680
+ const templates = yield liquid._parseLayoutFile(filepath, ctx.sync, this['currentFile']);
2681
+ // render remaining contents and store rendered results
2682
+ ctx.setRegister('blockMode', BlockMode$1.STORE);
2683
+ const html = yield renderer.renderTemplates(this.tpls, ctx);
2684
+ const blocks = ctx.getRegister('blocks');
2685
+ // set whole content to anonymous block if anonymous doesn't specified
2686
+ if (blocks[''] === undefined)
2687
+ blocks[''] = (parent, emitter) => emitter.write(html);
2688
+ ctx.setRegister('blockMode', BlockMode$1.OUTPUT);
2689
+ // render the layout file use stored blocks
2690
+ ctx.push(yield hash.render(ctx));
2691
+ yield renderer.renderTemplates(templates, ctx, emitter);
2692
+ ctx.pop();
2693
+ }
2694
+ };
2695
+
2696
+ class BlockDrop extends Drop {
2697
+ constructor(
2698
+ // the block render from layout template
2699
+ superBlockRender = () => '') {
2700
+ super();
2701
+ this.superBlockRender = superBlockRender;
2702
+ }
2703
+ /**
2704
+ * Provide parent access in child block by
2705
+ * {{ block.super }}
2706
+ */
2707
+ super() {
2708
+ return this.superBlockRender();
2709
+ }
2710
+ }
2711
+
2712
+ var block = {
2713
+ parse(token, remainTokens) {
2714
+ const match = /\w+/.exec(token.args);
2715
+ this.block = match ? match[0] : '';
2716
+ this.tpls = [];
2717
+ this.liquid.parser.parseStream(remainTokens)
2718
+ .on('tag:endblock', function () { this.stop(); })
2719
+ .on('template', (tpl) => this.tpls.push(tpl))
2720
+ .on('end', () => { throw new Error(`tag ${token.getText()} not closed`); })
2721
+ .start();
2722
+ },
2723
+ *render(ctx, emitter) {
2724
+ const blockRender = this.getBlockRender(ctx);
2725
+ if (ctx.getRegister('blockMode') === BlockMode$1.STORE) {
2726
+ ctx.getRegister('blocks')[this.block] = blockRender;
2727
+ }
2728
+ else {
2729
+ yield blockRender(new BlockDrop(), emitter);
2730
+ }
2731
+ },
2732
+ getBlockRender(ctx) {
2733
+ const { liquid, tpls } = this;
2734
+ const renderChild = ctx.getRegister('blocks')[this.block];
2735
+ const renderCurrent = function* (superBlock, emitter) {
2736
+ // add {{ block.super }} support when rendering
2737
+ ctx.push({ block: superBlock });
2738
+ yield liquid.renderer.renderTemplates(tpls, ctx, emitter);
2739
+ ctx.pop();
2740
+ };
2741
+ return renderChild
2742
+ ? (superBlock, emitter) => renderChild(new BlockDrop(() => renderCurrent(superBlock, emitter)), emitter)
2743
+ : renderCurrent;
2744
+ }
2745
+ };
2746
+
2747
+ var raw = {
2748
+ parse: function (tagToken, remainTokens) {
2749
+ this.tokens = [];
2750
+ const stream = this.liquid.parser.parseStream(remainTokens);
2751
+ stream
2752
+ .on('token', (token) => {
2753
+ if (token.name === 'endraw')
2754
+ stream.stop();
2755
+ else
2756
+ this.tokens.push(token);
2757
+ })
2758
+ .on('end', () => {
2759
+ throw new Error(`tag ${tagToken.getText()} not closed`);
2760
+ });
2761
+ stream.start();
2762
+ },
2763
+ render: function () {
2764
+ return this.tokens.map((token) => token.getText()).join('');
2765
+ }
2766
+ };
2767
+
2768
+ class TablerowloopDrop extends ForloopDrop {
2769
+ constructor(length, cols, collection, variable) {
2770
+ super(length, collection, variable);
2771
+ this.length = length;
2772
+ this.cols = cols;
2773
+ }
2774
+ row() {
2775
+ return Math.floor(this.i / this.cols) + 1;
2776
+ }
2777
+ col0() {
2778
+ return (this.i % this.cols);
2779
+ }
2780
+ col() {
2781
+ return this.col0() + 1;
2782
+ }
2783
+ col_first() {
2784
+ return this.col0() === 0;
2785
+ }
2786
+ col_last() {
2787
+ return this.col() === this.cols;
2788
+ }
2789
+ }
2790
+
2791
+ var tablerow = {
2792
+ parse: function (tagToken, remainTokens) {
2793
+ const tokenizer = new Tokenizer(tagToken.args, this.liquid.options.operatorsTrie);
2794
+ const variable = tokenizer.readIdentifier();
2795
+ tokenizer.skipBlank();
2796
+ const tmp = tokenizer.readIdentifier();
2797
+ assert(tmp && tmp.content === 'in', () => `illegal tag: ${tagToken.getText()}`);
2798
+ this.variable = variable.content;
2799
+ this.collection = tokenizer.readValue();
2800
+ this.hash = new Hash(tokenizer.remaining());
2801
+ this.templates = [];
2802
+ let p;
2803
+ const stream = this.liquid.parser.parseStream(remainTokens)
2804
+ .on('start', () => (p = this.templates))
2805
+ .on('tag:endtablerow', () => stream.stop())
2806
+ .on('template', (tpl) => p.push(tpl))
2807
+ .on('end', () => {
2808
+ throw new Error(`tag ${tagToken.getText()} not closed`);
2809
+ });
2810
+ stream.start();
2811
+ },
2812
+ render: function* (ctx, emitter) {
2813
+ let collection = toEnumerable(yield _evalToken(this.collection, ctx));
2814
+ const hash = yield this.hash.render(ctx);
2815
+ const offset = hash.offset || 0;
2816
+ const limit = (hash.limit === undefined) ? collection.length : hash.limit;
2817
+ collection = collection.slice(offset, offset + limit);
2818
+ const cols = hash.cols || collection.length;
2819
+ const r = this.liquid.renderer;
2820
+ const tablerowloop = new TablerowloopDrop(collection.length, cols, this.collection.getText(), this.variable);
2821
+ const scope = { tablerowloop };
2822
+ ctx.push(scope);
2823
+ for (let idx = 0; idx < collection.length; idx++, tablerowloop.next()) {
2824
+ scope[this.variable] = collection[idx];
2825
+ if (tablerowloop.col0() === 0) {
2826
+ if (tablerowloop.row() !== 1)
2827
+ emitter.write('</tr>');
2828
+ emitter.write(`<tr class="row${tablerowloop.row()}">`);
2829
+ }
2830
+ emitter.write(`<td class="col${tablerowloop.col()}">`);
2831
+ yield r.renderTemplates(this.templates, ctx, emitter);
2832
+ emitter.write('</td>');
2833
+ }
2834
+ if (collection.length)
2835
+ emitter.write('</tr>');
2836
+ ctx.pop();
2837
+ }
2838
+ };
2839
+
2840
+ var unless = {
2841
+ parse: function (tagToken, remainTokens) {
2842
+ this.branches = [];
2843
+ this.elseTemplates = [];
2844
+ let p;
2845
+ this.liquid.parser.parseStream(remainTokens)
2846
+ .on('start', () => this.branches.push({
2847
+ predicate: new Value(tagToken.args, this.liquid),
2848
+ test: isFalsy,
2849
+ templates: (p = [])
2850
+ }))
2851
+ .on('tag:elsif', (token) => this.branches.push({
2852
+ predicate: new Value(token.args, this.liquid),
2853
+ test: isTruthy,
2854
+ templates: (p = [])
2855
+ }))
2856
+ .on('tag:else', () => (p = this.elseTemplates))
2857
+ .on('tag:endunless', function () { this.stop(); })
2858
+ .on('template', (tpl) => p.push(tpl))
2859
+ .on('end', () => { throw new Error(`tag ${tagToken.getText()} not closed`); })
2860
+ .start();
2861
+ },
2862
+ render: function* (ctx, emitter) {
2863
+ const r = this.liquid.renderer;
2864
+ for (const { predicate, test, templates } of this.branches) {
2865
+ const value = yield predicate.value(ctx, ctx.opts.lenientIf);
2866
+ if (test(value, ctx)) {
2867
+ yield r.renderTemplates(templates, ctx, emitter);
2868
+ return;
2869
+ }
2870
+ }
2871
+ yield r.renderTemplates(this.elseTemplates, ctx, emitter);
2872
+ }
2873
+ };
2874
+
2875
+ var Break = {
2876
+ render: function (ctx, emitter) {
2877
+ emitter['break'] = true;
2878
+ }
2879
+ };
2880
+
2881
+ var Continue = {
2882
+ render: function (ctx, emitter) {
2883
+ emitter['continue'] = true;
2884
+ }
2885
+ };
2886
+
2887
+ var echo = {
2888
+ parse: function (token) {
2889
+ this.value = new Value(token.args, this.liquid);
2890
+ },
2891
+ render: function* (ctx, emitter) {
2892
+ const val = yield this.value.value(ctx, false);
2893
+ emitter.write(val);
2894
+ }
2895
+ };
2896
+
2897
+ var liquid = {
2898
+ parse: function (token) {
2899
+ const tokenizer = new Tokenizer(token.args, this.liquid.options.operatorsTrie);
2900
+ const tokens = tokenizer.readLiquidTagTokens(this.liquid.options);
2901
+ this.tpls = this.liquid.parser.parseTokens(tokens);
2902
+ },
2903
+ render: function* (ctx, emitter) {
2904
+ yield this.liquid.renderer.renderTemplates(this.tpls, ctx, emitter);
2905
+ }
2906
+ };
2907
+
2908
+ var inlineComment = {
2909
+ parse: function (tagToken, remainTokens) {
2910
+ if (tagToken.args.search(/\n\s*[^#\s]/g) !== -1) {
2911
+ throw new Error('every line of an inline comment must start with a \'#\' character');
2912
+ }
2913
+ }
2914
+ };
2915
+
2916
+ const tags = {
2917
+ assign, 'for': For, capture, 'case': Case, comment, include, render, decrement, increment, cycle, 'if': If, layout, block, raw, tablerow, unless, 'break': Break, 'continue': Continue, echo, liquid, '#': inlineComment
2918
+ };
2919
+
2920
+ var index = /*#__PURE__*/Object.freeze({
2921
+ __proto__: null,
2922
+ 'default': tags
2923
+ });
2924
+
2925
+ const filters = new Map();
2926
+ forOwn(builtinFilters, (conf, name) => {
2927
+ filters.set(snakeCase(name), conf);
2928
+ });
2929
+ const defaultOptions = {
2930
+ root: ['.'],
2931
+ layouts: ['.'],
2932
+ partials: ['.'],
2933
+ relativeReference: true,
2934
+ jekyllInclude: false,
2935
+ cache: undefined,
2936
+ extname: '',
2937
+ fs: fs,
2938
+ dynamicPartials: true,
2939
+ jsTruthy: false,
2940
+ trimTagRight: false,
2941
+ trimTagLeft: false,
2942
+ trimOutputRight: false,
2943
+ trimOutputLeft: false,
2944
+ greedy: true,
2945
+ tagDelimiterLeft: '{%',
2946
+ tagDelimiterRight: '%}',
2947
+ outputDelimiterLeft: '{{',
2948
+ outputDelimiterRight: '}}',
2949
+ preserveTimezones: false,
2950
+ strictFilters: false,
2951
+ strictVariables: false,
2952
+ ownPropertyOnly: false,
2953
+ lenientIf: false,
2954
+ globals: {},
2955
+ keepOutputType: false,
2956
+ operators: defaultOperators,
2957
+ operatorsTrie: createTrie(defaultOperators)
2958
+ };
2959
+ function normalize(options) {
2960
+ if (options.hasOwnProperty('operators')) {
2961
+ options.operatorsTrie = createTrie(options.operators);
2962
+ }
2963
+ if (options.hasOwnProperty('root')) {
2964
+ if (!options.hasOwnProperty('partials'))
2965
+ options.partials = options.root;
2966
+ if (!options.hasOwnProperty('layouts'))
2967
+ options.layouts = options.root;
2968
+ }
2969
+ if (options.hasOwnProperty('cache')) {
2970
+ let cache;
2971
+ if (typeof options.cache === 'number')
2972
+ cache = options.cache > 0 ? new LRU(options.cache) : undefined;
2973
+ else if (typeof options.cache === 'object')
2974
+ cache = options.cache;
2975
+ else
2976
+ cache = options.cache ? new LRU(1024) : undefined;
2977
+ options.cache = cache;
2978
+ }
2979
+ options = Object.assign(Object.assign(Object.assign({}, defaultOptions), (options.jekyllInclude ? { dynamicPartials: false } : {})), options);
2980
+ if (!options.fs.dirname && options.relativeReference) {
2981
+ console.warn('[LiquidJS] `fs.dirname` is required for relativeReference, set relativeReference to `false` to suppress this warning, or provide implementation for `fs.dirname`');
2982
+ options.relativeReference = false;
2983
+ }
2984
+ options.root = normalizeDirectoryList(options.root);
2985
+ options.partials = normalizeDirectoryList(options.partials);
2986
+ options.layouts = normalizeDirectoryList(options.layouts);
2987
+ options.outputEscape = options.outputEscape && getOutputEscapeFunction(options.outputEscape);
2988
+ return options;
2989
+ }
2990
+ function getOutputEscapeFunction(nameOrFunction) {
2991
+ if (isString(nameOrFunction)) {
2992
+ const filterImpl = filters.get(nameOrFunction);
2993
+ assert(isFunction(filterImpl), `filter "${nameOrFunction}" not found`);
2994
+ return filterImpl;
2995
+ }
2996
+ else {
2997
+ assert(isFunction(nameOrFunction), '`outputEscape` need to be of type string or function');
2998
+ return nameOrFunction;
2999
+ }
3000
+ }
3001
+ function normalizeDirectoryList(value) {
3002
+ let list = [];
3003
+ if (isArray(value))
3004
+ list = value;
3005
+ if (isString(value))
3006
+ list = [value];
3007
+ return list;
3008
+ }
3009
+
3010
+ class Context {
3011
+ constructor(env = {}, opts = defaultOptions, renderOptions = {}) {
3012
+ var _a, _b;
3013
+ /**
3014
+ * insert a Context-level empty scope,
3015
+ * for tags like `{% capture %}` `{% assign %}` to operate
3016
+ */
3017
+ this.scopes = [{}];
3018
+ this.registers = {};
3019
+ this.sync = !!renderOptions.sync;
3020
+ this.opts = opts;
3021
+ this.globals = (_a = renderOptions.globals) !== null && _a !== void 0 ? _a : opts.globals;
3022
+ this.environments = env;
3023
+ this.strictVariables = (_b = renderOptions.strictVariables) !== null && _b !== void 0 ? _b : this.opts.strictVariables;
3024
+ }
3025
+ getRegister(key) {
3026
+ return (this.registers[key] = this.registers[key] || {});
3027
+ }
3028
+ setRegister(key, value) {
3029
+ return (this.registers[key] = value);
3030
+ }
3031
+ saveRegister(...keys) {
3032
+ return keys.map(key => [key, this.getRegister(key)]);
3033
+ }
3034
+ restoreRegister(keyValues) {
3035
+ return keyValues.forEach(([key, value]) => this.setRegister(key, value));
3036
+ }
3037
+ getAll() {
3038
+ return [this.globals, this.environments, ...this.scopes]
3039
+ .reduce((ctx, val) => __assign(ctx, val), {});
3040
+ }
3041
+ /**
3042
+ * @deprecated use `_get()` instead
3043
+ */
3044
+ get(paths) {
3045
+ return toValueSync(this._get(paths));
3046
+ }
3047
+ *_get(paths) {
3048
+ const scope = this.findScope(paths[0]);
3049
+ return yield this._getFromScope(scope, paths);
3050
+ }
3051
+ /**
3052
+ * @deprecated use `_get()` instead
3053
+ */
3054
+ getFromScope(scope, paths) {
3055
+ return toValueSync(this._getFromScope(scope, paths));
3056
+ }
3057
+ *_getFromScope(scope, paths) {
3058
+ if (isString(paths))
3059
+ paths = paths.split('.');
3060
+ for (let i = 0; i < paths.length; i++) {
3061
+ scope = yield readProperty(scope, paths[i], this.opts.ownPropertyOnly);
3062
+ if (isNil(scope) && this.strictVariables) {
3063
+ throw new InternalUndefinedVariableError(paths.slice(0, i + 1).join('.'));
3064
+ }
3065
+ }
3066
+ return scope;
3067
+ }
3068
+ push(ctx) {
3069
+ return this.scopes.push(ctx);
3070
+ }
3071
+ pop() {
3072
+ return this.scopes.pop();
3073
+ }
3074
+ bottom() {
3075
+ return this.scopes[0];
3076
+ }
3077
+ findScope(key) {
3078
+ for (let i = this.scopes.length - 1; i >= 0; i--) {
3079
+ const candidate = this.scopes[i];
3080
+ if (key in candidate)
3081
+ return candidate;
3082
+ }
3083
+ if (key in this.environments)
3084
+ return this.environments;
3085
+ return this.globals;
3086
+ }
3087
+ }
3088
+ function readProperty(obj, key, ownPropertyOnly) {
3089
+ if (isNil(obj))
3090
+ return obj;
3091
+ obj = toLiquid(obj);
3092
+ if (isArray(obj) && key < 0)
3093
+ return obj[obj.length + +key];
3094
+ const jsProperty = readJSProperty(obj, key, ownPropertyOnly);
3095
+ if (jsProperty === undefined && obj instanceof Drop)
3096
+ return obj.liquidMethodMissing(key);
3097
+ if (isFunction(jsProperty))
3098
+ return jsProperty.call(obj);
3099
+ if (key === 'size')
3100
+ return readSize(obj);
3101
+ else if (key === 'first')
3102
+ return readFirst(obj);
3103
+ else if (key === 'last')
3104
+ return readLast(obj);
3105
+ return jsProperty;
3106
+ }
3107
+ function readJSProperty(obj, key, ownPropertyOnly) {
3108
+ if (ownPropertyOnly && !Object.hasOwnProperty.call(obj, key))
3109
+ return undefined;
3110
+ return obj[key];
3111
+ }
3112
+ function readFirst(obj) {
3113
+ if (isArray(obj))
3114
+ return obj[0];
3115
+ return obj['first'];
3116
+ }
3117
+ function readLast(obj) {
3118
+ if (isArray(obj))
3119
+ return obj[obj.length - 1];
3120
+ return obj['last'];
3121
+ }
3122
+ function readSize(obj) {
3123
+ if (obj.hasOwnProperty('size') || obj['size'] !== undefined)
3124
+ return obj['size'];
3125
+ if (isArray(obj) || isString(obj))
3126
+ return obj.length;
3127
+ if (typeof obj === 'object')
3128
+ return Object.keys(obj).length;
3129
+ }
3130
+
3131
+ var LookupType;
3132
+ (function (LookupType) {
3133
+ LookupType["Partials"] = "partials";
3134
+ LookupType["Layouts"] = "layouts";
3135
+ LookupType["Root"] = "root";
3136
+ })(LookupType || (LookupType = {}));
3137
+ class Loader {
3138
+ constructor(options) {
3139
+ this.options = options;
3140
+ if (options.relativeReference) {
3141
+ const sep = options.fs.sep;
3142
+ assert(sep, '`fs.sep` is required for relative reference');
3143
+ const rRelativePath = new RegExp(['.' + sep, '..' + sep, './', '../'].map(prefix => escapeRegex(prefix)).join('|'));
3144
+ this.shouldLoadRelative = (referencedFile) => rRelativePath.test(referencedFile);
3145
+ }
3146
+ else {
3147
+ this.shouldLoadRelative = (referencedFile) => false;
3148
+ }
3149
+ this.contains = this.options.fs.contains || (() => true);
3150
+ }
3151
+ *lookup(file, type, sync, currentFile) {
3152
+ const { fs } = this.options;
3153
+ const dirs = this.options[type];
3154
+ for (const filepath of this.candidates(file, dirs, currentFile, type !== LookupType.Root)) {
3155
+ if (sync ? fs.existsSync(filepath) : yield fs.exists(filepath))
3156
+ return filepath;
3157
+ }
3158
+ throw this.lookupError(file, dirs);
3159
+ }
3160
+ *candidates(file, dirs, currentFile, enforceRoot) {
3161
+ const { fs, extname } = this.options;
3162
+ if (this.shouldLoadRelative(file) && currentFile) {
3163
+ const referenced = fs.resolve(this.dirname(currentFile), file, extname);
3164
+ for (const dir of dirs) {
3165
+ if (!enforceRoot || this.contains(dir, referenced)) {
3166
+ // the relatively referenced file is within one of root dirs
3167
+ yield referenced;
3168
+ break;
3169
+ }
3170
+ }
3171
+ }
3172
+ for (const dir of dirs) {
3173
+ const referenced = fs.resolve(dir, file, extname);
3174
+ if (!enforceRoot || this.contains(dir, referenced)) {
3175
+ yield referenced;
3176
+ }
3177
+ }
3178
+ if (fs.fallback !== undefined) {
3179
+ const filepath = fs.fallback(file);
3180
+ if (filepath !== undefined)
3181
+ yield filepath;
3182
+ }
3183
+ }
3184
+ dirname(path) {
3185
+ const fs = this.options.fs;
3186
+ assert(fs.dirname, '`fs.dirname` is required for relative reference');
3187
+ return fs.dirname(path);
3188
+ }
3189
+ lookupError(file, roots) {
3190
+ const err = new Error('ENOENT');
3191
+ err.message = `ENOENT: Failed to lookup "${file}" in "${roots}"`;
3192
+ err.code = 'ENOENT';
3193
+ return err;
3194
+ }
3195
+ }
3196
+
3197
+ class SimpleEmitter {
3198
+ constructor() {
3199
+ this.buffer = '';
3200
+ }
3201
+ write(html) {
3202
+ this.buffer += stringify(html);
3203
+ }
3204
+ }
3205
+
3206
+ class StreamedEmitter {
3207
+ constructor() {
3208
+ this.buffer = '';
3209
+ this.stream = null;
3210
+ throw new Error('streaming not supported in browser');
3211
+ }
3212
+ }
3213
+
3214
+ class KeepingTypeEmitter {
3215
+ constructor() {
3216
+ this.buffer = '';
3217
+ }
3218
+ write(html) {
3219
+ html = toValue(html);
3220
+ // This will only preserve the type if the value is isolated.
3221
+ // I.E:
3222
+ // {{ my-port }} -> 42
3223
+ // {{ my-host }}:{{ my-port }} -> 'host:42'
3224
+ if (typeof html !== 'string' && this.buffer === '') {
3225
+ this.buffer = html;
3226
+ }
3227
+ else {
3228
+ this.buffer = stringify(this.buffer) + stringify(html);
3229
+ }
3230
+ }
3231
+ }
3232
+
3233
+ class Render {
3234
+ renderTemplatesToNodeStream(templates, ctx) {
3235
+ const emitter = new StreamedEmitter();
3236
+ Promise.resolve().then(() => toPromise(this.renderTemplates(templates, ctx, emitter)))
3237
+ .then(() => emitter.end(), err => emitter.error(err));
3238
+ return emitter.stream;
3239
+ }
3240
+ *renderTemplates(templates, ctx, emitter) {
3241
+ if (!emitter) {
3242
+ emitter = ctx.opts.keepOutputType ? new KeepingTypeEmitter() : new SimpleEmitter();
3243
+ }
3244
+ for (const tpl of templates) {
3245
+ try {
3246
+ // if tpl.render supports emitter, it'll return empty `html`
3247
+ const html = yield tpl.render(ctx, emitter);
3248
+ // if not, it'll return an `html`, write to the emitter for it
3249
+ html && emitter.write(html);
3250
+ if (emitter['break'] || emitter['continue'])
3251
+ break;
3252
+ }
3253
+ catch (e) {
3254
+ const err = RenderError.is(e) ? e : new RenderError(e, tpl);
3255
+ throw err;
3256
+ }
3257
+ }
3258
+ return emitter.buffer;
3259
+ }
3260
+ }
3261
+
3262
+ class TemplateImpl {
3263
+ constructor(token) {
3264
+ this.token = token;
3265
+ }
3266
+ }
3267
+
3268
+ class Tag extends TemplateImpl {
3269
+ constructor(token, tokens, liquid) {
3270
+ super(token);
3271
+ this.name = token.name;
3272
+ const impl = liquid.tags.get(token.name);
3273
+ this.impl = Object.create(impl);
3274
+ this.impl.liquid = liquid;
3275
+ if (this.impl.parse) {
3276
+ this.impl.parse(token, tokens);
3277
+ }
3278
+ }
3279
+ *render(ctx, emitter) {
3280
+ const hash = (yield new Hash(this.token.args).render(ctx));
3281
+ const impl = this.impl;
3282
+ if (isFunction(impl.render))
3283
+ return yield impl.render(ctx, emitter, hash);
3284
+ }
3285
+ }
3286
+
3287
+ class Output extends TemplateImpl {
3288
+ constructor(token, liquid) {
3289
+ super(token);
3290
+ this.value = new Value(token.content, liquid);
3291
+ const filters = this.value.filters;
3292
+ const outputEscape = liquid.options.outputEscape;
3293
+ if (filters.length && filters[filters.length - 1].name === 'raw') {
3294
+ filters.pop();
3295
+ }
3296
+ else if (outputEscape) {
3297
+ filters.push(new Filter(toString.call(outputEscape), outputEscape, [], liquid));
3298
+ }
3299
+ }
3300
+ *render(ctx, emitter) {
3301
+ const val = yield this.value.value(ctx, false);
3302
+ emitter.write(val);
3303
+ }
3304
+ }
3305
+
3306
+ class HTML extends TemplateImpl {
3307
+ constructor(token) {
3308
+ super(token);
3309
+ this.str = token.getContent();
3310
+ }
3311
+ *render(ctx, emitter) {
3312
+ emitter.write(this.str);
3313
+ }
3314
+ }
3315
+
3316
+ class Parser {
3317
+ constructor(liquid) {
3318
+ this.liquid = liquid;
3319
+ this.cache = this.liquid.options.cache;
3320
+ this.fs = this.liquid.options.fs;
3321
+ this.parseFile = this.cache ? this._parseFileCached : this._parseFile;
3322
+ this.loader = new Loader(this.liquid.options);
3323
+ }
3324
+ parse(html, filepath) {
3325
+ const tokenizer = new Tokenizer(html, this.liquid.options.operatorsTrie, filepath);
3326
+ const tokens = tokenizer.readTopLevelTokens(this.liquid.options);
3327
+ return this.parseTokens(tokens);
3328
+ }
3329
+ parseTokens(tokens) {
3330
+ let token;
3331
+ const templates = [];
3332
+ while ((token = tokens.shift())) {
3333
+ templates.push(this.parseToken(token, tokens));
3334
+ }
3335
+ return templates;
3336
+ }
3337
+ parseToken(token, remainTokens) {
3338
+ try {
3339
+ if (isTagToken(token)) {
3340
+ return new Tag(token, remainTokens, this.liquid);
3341
+ }
3342
+ if (isOutputToken(token)) {
3343
+ return new Output(token, this.liquid);
3344
+ }
3345
+ return new HTML(token);
3346
+ }
3347
+ catch (e) {
3348
+ throw new ParseError(e, token);
3349
+ }
3350
+ }
3351
+ parseStream(tokens) {
3352
+ return new ParseStream(tokens, (token, tokens) => this.parseToken(token, tokens));
3353
+ }
3354
+ *_parseFileCached(file, sync, type = LookupType.Root, currentFile) {
3355
+ const cache = this.cache;
3356
+ const key = this.loader.shouldLoadRelative(file) ? currentFile + ',' + file : type + ':' + file;
3357
+ const tpls = yield cache.read(key);
3358
+ if (tpls)
3359
+ return tpls;
3360
+ const task = this._parseFile(file, sync, type, currentFile);
3361
+ // sync mode: exec the task and cache the result
3362
+ // async mode: cache the task before exec
3363
+ const taskOrTpl = sync ? yield task : toPromise(task);
3364
+ cache.write(key, taskOrTpl);
3365
+ // note: concurrent tasks will be reused, cache for failed task is removed until its end
3366
+ try {
3367
+ return yield taskOrTpl;
3368
+ }
3369
+ catch (err) {
3370
+ cache.remove(key);
3371
+ throw err;
3372
+ }
3373
+ }
3374
+ *_parseFile(file, sync, type = LookupType.Root, currentFile) {
3375
+ const filepath = yield this.loader.lookup(file, type, sync, currentFile);
3376
+ return this.liquid.parse(sync ? this.fs.readFileSync(filepath) : yield this.fs.readFile(filepath), filepath);
3377
+ }
3378
+ }
3379
+
3380
+ class TagMap {
3381
+ constructor() {
3382
+ this.impls = {};
3383
+ }
3384
+ get(name) {
3385
+ const impl = this.impls[name];
3386
+ assert(impl, () => `tag "${name}" not found`);
3387
+ return impl;
3388
+ }
3389
+ set(name, impl) {
3390
+ this.impls[name] = impl;
3391
+ }
3392
+ }
3393
+
3394
+ class FilterMap {
3395
+ constructor(strictFilters, liquid) {
3396
+ this.strictFilters = strictFilters;
3397
+ this.liquid = liquid;
3398
+ this.impls = {};
3399
+ }
3400
+ get(name) {
3401
+ const impl = this.impls[name];
3402
+ assert(impl || !this.strictFilters, () => `undefined filter: ${name}`);
3403
+ return impl;
3404
+ }
3405
+ set(name, impl) {
3406
+ this.impls[name] = impl;
3407
+ }
3408
+ create(name, args) {
3409
+ return new Filter(name, this.get(name), args, this.liquid);
3410
+ }
3411
+ }
3412
+
3413
+ const version = '9.43.0';
3414
+ class Liquid {
3415
+ constructor(opts = {}) {
3416
+ this.options = normalize(opts);
3417
+ this.parser = new Parser(this);
3418
+ this.renderer = new Render();
3419
+ this.filters = new FilterMap(this.options.strictFilters, this);
3420
+ this.tags = new TagMap();
3421
+ forOwn(tags, (conf, name) => this.registerTag(snakeCase(name), conf));
3422
+ forOwn(builtinFilters, (handler, name) => this.registerFilter(snakeCase(name), handler));
3423
+ }
3424
+ parse(html, filepath) {
3425
+ return this.parser.parse(html, filepath);
3426
+ }
3427
+ _render(tpl, scope, renderOptions) {
3428
+ const ctx = new Context(scope, this.options, renderOptions);
3429
+ return this.renderer.renderTemplates(tpl, ctx);
3430
+ }
3431
+ render(tpl, scope, renderOptions) {
3432
+ return __awaiter(this, void 0, void 0, function* () {
3433
+ return toPromise(this._render(tpl, scope, Object.assign(Object.assign({}, renderOptions), { sync: false })));
3434
+ });
3435
+ }
3436
+ renderSync(tpl, scope, renderOptions) {
3437
+ return toValueSync(this._render(tpl, scope, Object.assign(Object.assign({}, renderOptions), { sync: true })));
3438
+ }
3439
+ renderToNodeStream(tpl, scope, renderOptions = {}) {
3440
+ const ctx = new Context(scope, this.options, renderOptions);
3441
+ return this.renderer.renderTemplatesToNodeStream(tpl, ctx);
3442
+ }
3443
+ _parseAndRender(html, scope, renderOptions) {
3444
+ const tpl = this.parse(html);
3445
+ return this._render(tpl, scope, renderOptions);
3446
+ }
3447
+ parseAndRender(html, scope, renderOptions) {
3448
+ return __awaiter(this, void 0, void 0, function* () {
3449
+ return toPromise(this._parseAndRender(html, scope, Object.assign(Object.assign({}, renderOptions), { sync: false })));
3450
+ });
3451
+ }
3452
+ parseAndRenderSync(html, scope, renderOptions) {
3453
+ return toValueSync(this._parseAndRender(html, scope, Object.assign(Object.assign({}, renderOptions), { sync: true })));
3454
+ }
3455
+ _parsePartialFile(file, sync, currentFile) {
3456
+ return this.parser.parseFile(file, sync, LookupType.Partials, currentFile);
3457
+ }
3458
+ _parseLayoutFile(file, sync, currentFile) {
3459
+ return this.parser.parseFile(file, sync, LookupType.Layouts, currentFile);
3460
+ }
3461
+ parseFile(file) {
3462
+ return __awaiter(this, void 0, void 0, function* () {
3463
+ return toPromise(this.parser.parseFile(file, false));
3464
+ });
3465
+ }
3466
+ parseFileSync(file) {
3467
+ return toValueSync(this.parser.parseFile(file, true));
3468
+ }
3469
+ renderFile(file, ctx, renderOptions) {
3470
+ return __awaiter(this, void 0, void 0, function* () {
3471
+ const templates = yield this.parseFile(file);
3472
+ return this.render(templates, ctx, renderOptions);
3473
+ });
3474
+ }
3475
+ renderFileSync(file, ctx, renderOptions) {
3476
+ const templates = this.parseFileSync(file);
3477
+ return this.renderSync(templates, ctx, renderOptions);
3478
+ }
3479
+ renderFileToNodeStream(file, scope, renderOptions) {
3480
+ return __awaiter(this, void 0, void 0, function* () {
3481
+ const templates = yield this.parseFile(file);
3482
+ return this.renderToNodeStream(templates, scope, renderOptions);
3483
+ });
3484
+ }
3485
+ _evalValue(str, scopeOrContext) {
3486
+ const value = new Value(str, this);
3487
+ const ctx = scopeOrContext instanceof Context ? scopeOrContext : new Context(scopeOrContext, this.options);
3488
+ return value.value(ctx, false);
3489
+ }
3490
+ evalValue(str, scopeOrContext) {
3491
+ return __awaiter(this, void 0, void 0, function* () {
3492
+ return toPromise(this._evalValue(str, scopeOrContext));
3493
+ });
3494
+ }
3495
+ evalValueSync(str, scopeOrContext) {
3496
+ return toValueSync(this._evalValue(str, scopeOrContext));
3497
+ }
3498
+ registerFilter(name, filter) {
3499
+ this.filters.set(name, filter);
3500
+ }
3501
+ registerTag(name, tag) {
3502
+ this.tags.set(name, tag);
3503
+ }
3504
+ plugin(plugin) {
3505
+ return plugin.call(this, Liquid);
3506
+ }
3507
+ express() {
3508
+ const self = this; // eslint-disable-line
3509
+ let firstCall = true;
3510
+ return function (filePath, ctx, callback) {
3511
+ if (firstCall) {
3512
+ firstCall = false;
3513
+ const dirs = normalizeDirectoryList(this.root);
3514
+ self.options.root.unshift(...dirs);
3515
+ self.options.layouts.unshift(...dirs);
3516
+ self.options.partials.unshift(...dirs);
3517
+ }
3518
+ self.renderFile(filePath, ctx).then(html => callback(null, html), callback);
3519
+ };
3520
+ }
3521
+ }
3522
+
3523
+ export { AssertionError, Context, Drop, Expression, Hash, InternalUndefinedVariableError, Liquid, LiquidError, ParseError, ParseStream, RenderError, TagToken, TimezoneDate, Token, TokenKind, TokenizationError, Tokenizer, typeGuards as TypeGuards, UndefinedVariableError, Value, _evalToken, assert, createTrie, defaultOperators, defaultOptions, evalQuotedToken, evalToken, builtinFilters as filters, isFalsy, isTruthy, index as tags, toPromise, toThenable, toValue, toValueSync, version };