UNPKG

234 kBJavaScriptView Raw
1/*
2 * liquidjs@10.14.0, https://github.com/harttle/liquidjs
3 * (c) 2016-2024 harttle
4 * Released under the MIT License.
5 */
6(function (global, factory) {
7 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
8 typeof define === 'function' && define.amd ? define(['exports'], factory) :
9 (global = global || self, factory(global.liquidjs = {}));
10}(this, (function (exports) { 'use strict';
11
12 /******************************************************************************
13 Copyright (c) Microsoft Corporation.
14
15 Permission to use, copy, modify, and/or distribute this software for any
16 purpose with or without fee is hereby granted.
17
18 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
21 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24 PERFORMANCE OF THIS SOFTWARE.
25 ***************************************************************************** */
26 /* global Reflect, Promise */
27
28 var extendStatics = function(d, b) {
29 extendStatics = Object.setPrototypeOf ||
30 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
31 function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
32 return extendStatics(d, b);
33 };
34
35 function __extends(d, b) {
36 if (typeof b !== "function" && b !== null)
37 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
38 extendStatics(d, b);
39 function __() { this.constructor = d; }
40 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
41 }
42
43 var __assign = function() {
44 __assign = Object.assign || function __assign(t) {
45 for (var s, i = 1, n = arguments.length; i < n; i++) {
46 s = arguments[i];
47 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
48 }
49 return t;
50 };
51 return __assign.apply(this, arguments);
52 };
53
54 function __awaiter(thisArg, _arguments, P, generator) {
55 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
56 return new (P || (P = Promise))(function (resolve, reject) {
57 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
58 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
59 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
60 step((generator = generator.apply(thisArg, _arguments || [])).next());
61 });
62 }
63
64 function __generator(thisArg, body) {
65 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
66 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
67 function verb(n) { return function (v) { return step([n, v]); }; }
68 function step(op) {
69 if (f) throw new TypeError("Generator is already executing.");
70 while (g && (g = 0, op[0] && (_ = 0)), _) try {
71 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
72 if (y = 0, t) op = [op[0] & 2, t.value];
73 switch (op[0]) {
74 case 0: case 1: t = op; break;
75 case 4: _.label++; return { value: op[1], done: false };
76 case 5: _.label++; y = op[1]; op = [0]; continue;
77 case 7: op = _.ops.pop(); _.trys.pop(); continue;
78 default:
79 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
80 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
81 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
82 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
83 if (t[2]) _.ops.pop();
84 _.trys.pop(); continue;
85 }
86 op = body.call(thisArg, _);
87 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
88 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
89 }
90 }
91
92 function __values(o) {
93 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
94 if (m) return m.call(o);
95 if (o && typeof o.length === "number") return {
96 next: function () {
97 if (o && i >= o.length) o = void 0;
98 return { value: o && o[i++], done: !o };
99 }
100 };
101 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
102 }
103
104 function __read(o, n) {
105 var m = typeof Symbol === "function" && o[Symbol.iterator];
106 if (!m) return o;
107 var i = m.call(o), r, ar = [], e;
108 try {
109 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
110 }
111 catch (error) { e = { error: error }; }
112 finally {
113 try {
114 if (r && !r.done && (m = i["return"])) m.call(i);
115 }
116 finally { if (e) throw e.error; }
117 }
118 return ar;
119 }
120
121 function __spreadArray(to, from, pack) {
122 if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
123 if (ar || !(i in from)) {
124 if (!ar) ar = Array.prototype.slice.call(from, 0, i);
125 ar[i] = from[i];
126 }
127 }
128 return to.concat(ar || Array.prototype.slice.call(from));
129 }
130
131 var Token = /** @class */ (function () {
132 function Token(kind, input, begin, end, file) {
133 this.kind = kind;
134 this.input = input;
135 this.begin = begin;
136 this.end = end;
137 this.file = file;
138 }
139 Token.prototype.getText = function () {
140 return this.input.slice(this.begin, this.end);
141 };
142 Token.prototype.getPosition = function () {
143 var _a = __read([1, 1], 2), row = _a[0], col = _a[1];
144 for (var i = 0; i < this.begin; i++) {
145 if (this.input[i] === '\n') {
146 row++;
147 col = 1;
148 }
149 else
150 col++;
151 }
152 return [row, col];
153 };
154 Token.prototype.size = function () {
155 return this.end - this.begin;
156 };
157 return Token;
158 }());
159
160 var Drop = /** @class */ (function () {
161 function Drop() {
162 }
163 Drop.prototype.liquidMethodMissing = function (key) {
164 return undefined;
165 };
166 return Drop;
167 }());
168
169 var toString$1 = Object.prototype.toString;
170 var toLowerCase = String.prototype.toLowerCase;
171 var hasOwnProperty = Object.hasOwnProperty;
172 function isString(value) {
173 return typeof value === 'string';
174 }
175 // eslint-disable-next-line @typescript-eslint/ban-types
176 function isFunction(value) {
177 return typeof value === 'function';
178 }
179 function isPromise(val) {
180 return val && isFunction(val.then);
181 }
182 function isIterator(val) {
183 return val && isFunction(val.next) && isFunction(val.throw) && isFunction(val.return);
184 }
185 function escapeRegex(str) {
186 return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
187 }
188 function stringify(value) {
189 value = toValue(value);
190 if (isString(value))
191 return value;
192 if (isNil(value))
193 return '';
194 if (isArray(value))
195 return value.map(function (x) { return stringify(x); }).join('');
196 return String(value);
197 }
198 function toEnumerable(val) {
199 val = toValue(val);
200 if (isArray(val))
201 return val;
202 if (isString(val) && val.length > 0)
203 return [val];
204 if (isIterable(val))
205 return Array.from(val);
206 if (isObject(val))
207 return Object.keys(val).map(function (key) { return [key, val[key]]; });
208 return [];
209 }
210 function toArray(val) {
211 val = toValue(val);
212 if (isNil(val))
213 return [];
214 if (isArray(val))
215 return val;
216 return [val];
217 }
218 function toValue(value) {
219 return (value instanceof Drop && isFunction(value.valueOf)) ? value.valueOf() : value;
220 }
221 function isNumber(value) {
222 return typeof value === 'number';
223 }
224 function toLiquid(value) {
225 if (value && isFunction(value.toLiquid))
226 return toLiquid(value.toLiquid());
227 return value;
228 }
229 function isNil(value) {
230 return value == null;
231 }
232 function isUndefined(value) {
233 return value === undefined;
234 }
235 function isArray(value) {
236 // be compatible with IE 8
237 return toString$1.call(value) === '[object Array]';
238 }
239 function isIterable(value) {
240 return isObject(value) && Symbol.iterator in value;
241 }
242 /*
243 * Iterates over own enumerable string keyed properties of an object and invokes iteratee for each property.
244 * The iteratee is invoked with three arguments: (value, key, object).
245 * Iteratee functions may exit iteration early by explicitly returning false.
246 * @param {Object} object The object to iterate over.
247 * @param {Function} iteratee The function invoked per iteration.
248 * @return {Object} Returns object.
249 */
250 function forOwn(obj, iteratee) {
251 obj = obj || {};
252 for (var k in obj) {
253 if (hasOwnProperty.call(obj, k)) {
254 if (iteratee(obj[k], k, obj) === false)
255 break;
256 }
257 }
258 return obj;
259 }
260 function last(arr) {
261 return arr[arr.length - 1];
262 }
263 /*
264 * Checks if value is the language type of Object.
265 * (e.g. arrays, functions, objects, regexes, new Number(0), and new String(''))
266 * @param {any} value The value to check.
267 * @return {Boolean} Returns true if value is an object, else false.
268 */
269 function isObject(value) {
270 var type = typeof value;
271 return value !== null && (type === 'object' || type === 'function');
272 }
273 function range(start, stop, step) {
274 if (step === void 0) { step = 1; }
275 var arr = [];
276 for (var i = start; i < stop; i += step) {
277 arr.push(i);
278 }
279 return arr;
280 }
281 function padStart(str, length, ch) {
282 if (ch === void 0) { ch = ' '; }
283 return pad(str, length, ch, function (str, ch) { return ch + str; });
284 }
285 function padEnd(str, length, ch) {
286 if (ch === void 0) { ch = ' '; }
287 return pad(str, length, ch, function (str, ch) { return str + ch; });
288 }
289 function pad(str, length, ch, add) {
290 str = String(str);
291 var n = length - str.length;
292 while (n-- > 0)
293 str = add(str, ch);
294 return str;
295 }
296 function identify(val) {
297 return val;
298 }
299 function changeCase(str) {
300 var hasLowerCase = __spreadArray([], __read(str), false).some(function (ch) { return ch >= 'a' && ch <= 'z'; });
301 return hasLowerCase ? str.toUpperCase() : str.toLowerCase();
302 }
303 function ellipsis(str, N) {
304 return str.length > N ? str.slice(0, N - 3) + '...' : str;
305 }
306 // compare string in case-insensitive way, undefined values to the tail
307 function caseInsensitiveCompare(a, b) {
308 if (a == null && b == null)
309 return 0;
310 if (a == null)
311 return 1;
312 if (b == null)
313 return -1;
314 a = toLowerCase.call(a);
315 b = toLowerCase.call(b);
316 if (a < b)
317 return -1;
318 if (a > b)
319 return 1;
320 return 0;
321 }
322 function argumentsToValue(fn) {
323 return function () {
324 var args = [];
325 for (var _i = 0; _i < arguments.length; _i++) {
326 args[_i] = arguments[_i];
327 }
328 return fn.apply(void 0, __spreadArray([], __read(args.map(toValue)), false));
329 };
330 }
331 function escapeRegExp(text) {
332 return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
333 }
334
335 /**
336 * targeting ES5, extends Error won't create a proper prototype chain, need a trait to keep track of classes
337 */
338 var TRAIT = '__liquidClass__';
339 var LiquidError = /** @class */ (function (_super) {
340 __extends(LiquidError, _super);
341 function LiquidError(err, token) {
342 var _this =
343 /**
344 * note: for ES5 targeting, `this` will be replaced by return value of Error(),
345 * thus everything on `this` will be lost, avoid calling `LiquidError` methods here
346 */
347 _super.call(this, typeof err === 'string' ? err : err.message) || this;
348 _this.context = '';
349 if (typeof err !== 'string')
350 Object.defineProperty(_this, 'originalError', { value: err, enumerable: false });
351 Object.defineProperty(_this, 'token', { value: token, enumerable: false });
352 Object.defineProperty(_this, TRAIT, { value: 'LiquidError', enumerable: false });
353 return _this;
354 }
355 LiquidError.prototype.update = function () {
356 Object.defineProperty(this, 'context', { value: mkContext(this.token), enumerable: false });
357 this.message = mkMessage(this.message, this.token);
358 this.stack = this.message + '\n' + this.context +
359 '\n' + this.stack;
360 if (this.originalError)
361 this.stack += '\nFrom ' + this.originalError.stack;
362 };
363 LiquidError.is = function (obj) {
364 return (obj === null || obj === void 0 ? void 0 : obj[TRAIT]) === 'LiquidError';
365 };
366 return LiquidError;
367 }(Error));
368 var TokenizationError = /** @class */ (function (_super) {
369 __extends(TokenizationError, _super);
370 function TokenizationError(message, token) {
371 var _this = _super.call(this, message, token) || this;
372 _this.name = 'TokenizationError';
373 _super.prototype.update.call(_this);
374 return _this;
375 }
376 return TokenizationError;
377 }(LiquidError));
378 var ParseError = /** @class */ (function (_super) {
379 __extends(ParseError, _super);
380 function ParseError(err, token) {
381 var _this = _super.call(this, err, token) || this;
382 _this.name = 'ParseError';
383 _this.message = err.message;
384 _super.prototype.update.call(_this);
385 return _this;
386 }
387 return ParseError;
388 }(LiquidError));
389 var RenderError = /** @class */ (function (_super) {
390 __extends(RenderError, _super);
391 function RenderError(err, tpl) {
392 var _this = _super.call(this, err, tpl.token) || this;
393 _this.name = 'RenderError';
394 _this.message = err.message;
395 _super.prototype.update.call(_this);
396 return _this;
397 }
398 RenderError.is = function (obj) {
399 return obj.name === 'RenderError';
400 };
401 return RenderError;
402 }(LiquidError));
403 var LiquidErrors = /** @class */ (function (_super) {
404 __extends(LiquidErrors, _super);
405 function LiquidErrors(errors) {
406 var _this = _super.call(this, errors[0], errors[0].token) || this;
407 _this.errors = errors;
408 _this.name = 'LiquidErrors';
409 var s = errors.length > 1 ? 's' : '';
410 _this.message = "".concat(errors.length, " error").concat(s, " found");
411 _super.prototype.update.call(_this);
412 return _this;
413 }
414 LiquidErrors.is = function (obj) {
415 return obj.name === 'LiquidErrors';
416 };
417 return LiquidErrors;
418 }(LiquidError));
419 var UndefinedVariableError = /** @class */ (function (_super) {
420 __extends(UndefinedVariableError, _super);
421 function UndefinedVariableError(err, token) {
422 var _this = _super.call(this, err, token) || this;
423 _this.name = 'UndefinedVariableError';
424 _this.message = err.message;
425 _super.prototype.update.call(_this);
426 return _this;
427 }
428 return UndefinedVariableError;
429 }(LiquidError));
430 // only used internally; raised where we don't have token information,
431 // so it can't be an UndefinedVariableError.
432 var InternalUndefinedVariableError = /** @class */ (function (_super) {
433 __extends(InternalUndefinedVariableError, _super);
434 function InternalUndefinedVariableError(variableName) {
435 var _this = _super.call(this, "undefined variable: ".concat(variableName)) || this;
436 _this.name = 'InternalUndefinedVariableError';
437 _this.variableName = variableName;
438 return _this;
439 }
440 return InternalUndefinedVariableError;
441 }(Error));
442 var AssertionError = /** @class */ (function (_super) {
443 __extends(AssertionError, _super);
444 function AssertionError(message) {
445 var _this = _super.call(this, message) || this;
446 _this.name = 'AssertionError';
447 _this.message = message + '';
448 return _this;
449 }
450 return AssertionError;
451 }(Error));
452 function mkContext(token) {
453 var _a = __read(token.getPosition(), 2), line = _a[0], col = _a[1];
454 var lines = token.input.split('\n');
455 var begin = Math.max(line - 2, 1);
456 var end = Math.min(line + 3, lines.length);
457 var context = range(begin, end + 1)
458 .map(function (lineNumber) {
459 var rowIndicator = (lineNumber === line) ? '>> ' : ' ';
460 var num = padStart(String(lineNumber), String(end).length);
461 var text = "".concat(rowIndicator).concat(num, "| ");
462 var colIndicator = lineNumber === line
463 ? '\n' + padStart('^', col + text.length)
464 : '';
465 text += lines[lineNumber - 1];
466 text += colIndicator;
467 return text;
468 })
469 .join('\n');
470 return context;
471 }
472 function mkMessage(msg, token) {
473 if (token.file)
474 msg += ", file:".concat(token.file);
475 var _a = __read(token.getPosition(), 2), line = _a[0], col = _a[1];
476 msg += ", line:".concat(line, ", col:").concat(col);
477 return msg;
478 }
479
480 // **DO NOT CHANGE THIS FILE**
481 //
482 // This file is generated by bin/character-gen.js
483 // bitmask character types to boost performance
484 var 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];
485 var WORD = 1;
486 var BLANK = 4;
487 var QUOTE = 8;
488 var INLINE_BLANK = 16;
489 var NUMBER = 32;
490 var SIGN = 64;
491 var PUNCTUATION = 128;
492 function isWord(char) {
493 var code = char.charCodeAt(0);
494 return code >= 128 ? !TYPES[code] : !!(TYPES[code] & WORD);
495 }
496 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;
497 TYPES[8220] = TYPES[8221] = PUNCTUATION;
498
499 function assert(predicate, message) {
500 if (!predicate) {
501 var msg = typeof message === 'function'
502 ? message()
503 : (message || "expect ".concat(predicate, " to be true"));
504 throw new AssertionError(msg);
505 }
506 }
507
508 var NullDrop = /** @class */ (function (_super) {
509 __extends(NullDrop, _super);
510 function NullDrop() {
511 return _super !== null && _super.apply(this, arguments) || this;
512 }
513 NullDrop.prototype.equals = function (value) {
514 return isNil(toValue(value));
515 };
516 NullDrop.prototype.gt = function () {
517 return false;
518 };
519 NullDrop.prototype.geq = function () {
520 return false;
521 };
522 NullDrop.prototype.lt = function () {
523 return false;
524 };
525 NullDrop.prototype.leq = function () {
526 return false;
527 };
528 NullDrop.prototype.valueOf = function () {
529 return null;
530 };
531 return NullDrop;
532 }(Drop));
533
534 var EmptyDrop = /** @class */ (function (_super) {
535 __extends(EmptyDrop, _super);
536 function EmptyDrop() {
537 return _super !== null && _super.apply(this, arguments) || this;
538 }
539 EmptyDrop.prototype.equals = function (value) {
540 if (value instanceof EmptyDrop)
541 return false;
542 value = toValue(value);
543 if (isString(value) || isArray(value))
544 return value.length === 0;
545 if (isObject(value))
546 return Object.keys(value).length === 0;
547 return false;
548 };
549 EmptyDrop.prototype.gt = function () {
550 return false;
551 };
552 EmptyDrop.prototype.geq = function () {
553 return false;
554 };
555 EmptyDrop.prototype.lt = function () {
556 return false;
557 };
558 EmptyDrop.prototype.leq = function () {
559 return false;
560 };
561 EmptyDrop.prototype.valueOf = function () {
562 return '';
563 };
564 return EmptyDrop;
565 }(Drop));
566
567 var BlankDrop = /** @class */ (function (_super) {
568 __extends(BlankDrop, _super);
569 function BlankDrop() {
570 return _super !== null && _super.apply(this, arguments) || this;
571 }
572 BlankDrop.prototype.equals = function (value) {
573 if (value === false)
574 return true;
575 if (isNil(toValue(value)))
576 return true;
577 if (isString(value))
578 return /^\s*$/.test(value);
579 return _super.prototype.equals.call(this, value);
580 };
581 return BlankDrop;
582 }(EmptyDrop));
583
584 var ForloopDrop = /** @class */ (function (_super) {
585 __extends(ForloopDrop, _super);
586 function ForloopDrop(length, collection, variable) {
587 var _this = _super.call(this) || this;
588 _this.i = 0;
589 _this.length = length;
590 _this.name = "".concat(variable, "-").concat(collection);
591 return _this;
592 }
593 ForloopDrop.prototype.next = function () {
594 this.i++;
595 };
596 ForloopDrop.prototype.index0 = function () {
597 return this.i;
598 };
599 ForloopDrop.prototype.index = function () {
600 return this.i + 1;
601 };
602 ForloopDrop.prototype.first = function () {
603 return this.i === 0;
604 };
605 ForloopDrop.prototype.last = function () {
606 return this.i === this.length - 1;
607 };
608 ForloopDrop.prototype.rindex = function () {
609 return this.length - this.i;
610 };
611 ForloopDrop.prototype.rindex0 = function () {
612 return this.length - this.i - 1;
613 };
614 ForloopDrop.prototype.valueOf = function () {
615 return JSON.stringify(this);
616 };
617 return ForloopDrop;
618 }(Drop));
619
620 var BlockDrop = /** @class */ (function (_super) {
621 __extends(BlockDrop, _super);
622 function BlockDrop(
623 // the block render from layout template
624 superBlockRender) {
625 if (superBlockRender === void 0) { superBlockRender = function () { return ''; }; }
626 var _this = _super.call(this) || this;
627 _this.superBlockRender = superBlockRender;
628 return _this;
629 }
630 /**
631 * Provide parent access in child block by
632 * {{ block.super }}
633 */
634 BlockDrop.prototype.super = function () {
635 return this.superBlockRender();
636 };
637 return BlockDrop;
638 }(Drop));
639
640 function isComparable(arg) {
641 return (arg &&
642 isFunction(arg.equals) &&
643 isFunction(arg.gt) &&
644 isFunction(arg.geq) &&
645 isFunction(arg.lt) &&
646 isFunction(arg.leq));
647 }
648
649 var nil = new NullDrop();
650 var literalValues = {
651 'true': true,
652 'false': false,
653 'nil': nil,
654 'null': nil,
655 'empty': new EmptyDrop(),
656 'blank': new BlankDrop()
657 };
658
659 function createTrie(input) {
660 var e_1, _a;
661 var trie = {};
662 try {
663 for (var _b = __values(Object.entries(input)), _c = _b.next(); !_c.done; _c = _b.next()) {
664 var _d = __read(_c.value, 2), name_1 = _d[0], data = _d[1];
665 var node = trie;
666 for (var i = 0; i < name_1.length; i++) {
667 var c = name_1[i];
668 node[c] = node[c] || {};
669 if (i === name_1.length - 1 && isWord(name_1[i])) {
670 node[c].needBoundary = true;
671 }
672 node = node[c];
673 }
674 node.data = data;
675 node.end = true;
676 }
677 }
678 catch (e_1_1) { e_1 = { error: e_1_1 }; }
679 finally {
680 try {
681 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
682 }
683 finally { if (e_1) throw e_1.error; }
684 }
685 return trie;
686 }
687
688 // convert an async iterator to a Promise
689 function toPromise(val) {
690 return __awaiter(this, void 0, void 0, function () {
691 var value, done, next, state, err_1;
692 return __generator(this, function (_a) {
693 switch (_a.label) {
694 case 0:
695 if (!isIterator(val))
696 return [2 /*return*/, val];
697 done = false;
698 next = 'next';
699 _a.label = 1;
700 case 1:
701 state = val[next](value);
702 done = state.done;
703 value = state.value;
704 next = 'next';
705 _a.label = 2;
706 case 2:
707 _a.trys.push([2, 5, , 6]);
708 if (isIterator(value))
709 value = toPromise(value);
710 if (!isPromise(value)) return [3 /*break*/, 4];
711 return [4 /*yield*/, value];
712 case 3:
713 value = _a.sent();
714 _a.label = 4;
715 case 4: return [3 /*break*/, 6];
716 case 5:
717 err_1 = _a.sent();
718 next = 'throw';
719 value = err_1;
720 return [3 /*break*/, 6];
721 case 6:
722 if (!done) return [3 /*break*/, 1];
723 _a.label = 7;
724 case 7: return [2 /*return*/, value];
725 }
726 });
727 });
728 }
729 // convert an async iterator to a value in a synchronous manner
730 function toValueSync(val) {
731 if (!isIterator(val))
732 return val;
733 var value;
734 var done = false;
735 var next = 'next';
736 do {
737 var state = val[next](value);
738 done = state.done;
739 value = state.value;
740 next = 'next';
741 if (isIterator(value)) {
742 try {
743 value = toValueSync(value);
744 }
745 catch (err) {
746 next = 'throw';
747 value = err;
748 }
749 }
750 } while (!done);
751 return value;
752 }
753
754 var rFormat = /%([-_0^#:]+)?(\d+)?([EO])?(.)/;
755 var monthNames = [
756 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',
757 'September', 'October', 'November', 'December'
758 ];
759 var dayNames = [
760 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
761 ];
762 var monthNamesShort = monthNames.map(abbr);
763 var dayNamesShort = dayNames.map(abbr);
764 function abbr(str) {
765 return str.slice(0, 3);
766 }
767 // prototype extensions
768 function daysInMonth(d) {
769 var feb = isLeapYear(d) ? 29 : 28;
770 return [31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
771 }
772 function getDayOfYear(d) {
773 var num = 0;
774 for (var i = 0; i < d.getMonth(); ++i) {
775 num += daysInMonth(d)[i];
776 }
777 return num + d.getDate();
778 }
779 function getWeekOfYear(d, startDay) {
780 // Skip to startDay of this week
781 var now = getDayOfYear(d) + (startDay - d.getDay());
782 // Find the first startDay of the year
783 var jan1 = new Date(d.getFullYear(), 0, 1);
784 var then = (7 - jan1.getDay() + startDay);
785 return String(Math.floor((now - then) / 7) + 1);
786 }
787 function isLeapYear(d) {
788 var year = d.getFullYear();
789 return !!((year & 3) === 0 && (year % 100 || (year % 400 === 0 && year)));
790 }
791 function ordinal(d) {
792 var date = d.getDate();
793 if ([11, 12, 13].includes(date))
794 return 'th';
795 switch (date % 10) {
796 case 1: return 'st';
797 case 2: return 'nd';
798 case 3: return 'rd';
799 default: return 'th';
800 }
801 }
802 function century(d) {
803 return parseInt(d.getFullYear().toString().substring(0, 2), 10);
804 }
805 // default to 0
806 var padWidths = {
807 d: 2,
808 e: 2,
809 H: 2,
810 I: 2,
811 j: 3,
812 k: 2,
813 l: 2,
814 L: 3,
815 m: 2,
816 M: 2,
817 S: 2,
818 U: 2,
819 W: 2
820 };
821 // default to '0'
822 var padChars = {
823 a: ' ',
824 A: ' ',
825 b: ' ',
826 B: ' ',
827 c: ' ',
828 e: ' ',
829 k: ' ',
830 l: ' ',
831 p: ' ',
832 P: ' '
833 };
834 function getTimezoneOffset(d, opts) {
835 var nOffset = Math.abs(d.getTimezoneOffset());
836 var h = Math.floor(nOffset / 60);
837 var m = nOffset % 60;
838 return (d.getTimezoneOffset() > 0 ? '-' : '+') +
839 padStart(h, 2, '0') +
840 (opts.flags[':'] ? ':' : '') +
841 padStart(m, 2, '0');
842 }
843 var formatCodes = {
844 a: function (d) { return dayNamesShort[d.getDay()]; },
845 A: function (d) { return dayNames[d.getDay()]; },
846 b: function (d) { return monthNamesShort[d.getMonth()]; },
847 B: function (d) { return monthNames[d.getMonth()]; },
848 c: function (d) { return d.toLocaleString(); },
849 C: function (d) { return century(d); },
850 d: function (d) { return d.getDate(); },
851 e: function (d) { return d.getDate(); },
852 H: function (d) { return d.getHours(); },
853 I: function (d) { return String(d.getHours() % 12 || 12); },
854 j: function (d) { return getDayOfYear(d); },
855 k: function (d) { return d.getHours(); },
856 l: function (d) { return String(d.getHours() % 12 || 12); },
857 L: function (d) { return d.getMilliseconds(); },
858 m: function (d) { return d.getMonth() + 1; },
859 M: function (d) { return d.getMinutes(); },
860 N: function (d, opts) {
861 var width = Number(opts.width) || 9;
862 var str = String(d.getMilliseconds()).slice(0, width);
863 return padEnd(str, width, '0');
864 },
865 p: function (d) { return (d.getHours() < 12 ? 'AM' : 'PM'); },
866 P: function (d) { return (d.getHours() < 12 ? 'am' : 'pm'); },
867 q: function (d) { return ordinal(d); },
868 s: function (d) { return Math.round(d.getTime() / 1000); },
869 S: function (d) { return d.getSeconds(); },
870 u: function (d) { return d.getDay() || 7; },
871 U: function (d) { return getWeekOfYear(d, 0); },
872 w: function (d) { return d.getDay(); },
873 W: function (d) { return getWeekOfYear(d, 1); },
874 x: function (d) { return d.toLocaleDateString(); },
875 X: function (d) { return d.toLocaleTimeString(); },
876 y: function (d) { return d.getFullYear().toString().slice(2, 4); },
877 Y: function (d) { return d.getFullYear(); },
878 z: getTimezoneOffset,
879 Z: function (d, opts) {
880 if (d.getTimezoneName) {
881 return d.getTimezoneName() || getTimezoneOffset(d, opts);
882 }
883 return (typeof Intl !== 'undefined' ? Intl.DateTimeFormat().resolvedOptions().timeZone : '');
884 },
885 't': function () { return '\t'; },
886 'n': function () { return '\n'; },
887 '%': function () { return '%'; }
888 };
889 formatCodes.h = formatCodes.b;
890 function strftime(d, formatStr) {
891 var output = '';
892 var remaining = formatStr;
893 var match;
894 while ((match = rFormat.exec(remaining))) {
895 output += remaining.slice(0, match.index);
896 remaining = remaining.slice(match.index + match[0].length);
897 output += format(d, match);
898 }
899 return output + remaining;
900 }
901 function format(d, match) {
902 var e_1, _a;
903 var _b = __read(match, 5), input = _b[0], _c = _b[1], flagStr = _c === void 0 ? '' : _c, width = _b[2], modifier = _b[3], conversion = _b[4];
904 var convert = formatCodes[conversion];
905 if (!convert)
906 return input;
907 var flags = {};
908 try {
909 for (var flagStr_1 = __values(flagStr), flagStr_1_1 = flagStr_1.next(); !flagStr_1_1.done; flagStr_1_1 = flagStr_1.next()) {
910 var flag = flagStr_1_1.value;
911 flags[flag] = true;
912 }
913 }
914 catch (e_1_1) { e_1 = { error: e_1_1 }; }
915 finally {
916 try {
917 if (flagStr_1_1 && !flagStr_1_1.done && (_a = flagStr_1.return)) _a.call(flagStr_1);
918 }
919 finally { if (e_1) throw e_1.error; }
920 }
921 var ret = String(convert(d, { flags: flags, width: width, modifier: modifier }));
922 var padChar = padChars[conversion] || '0';
923 var padWidth = width || padWidths[conversion] || 0;
924 if (flags['^'])
925 ret = ret.toUpperCase();
926 else if (flags['#'])
927 ret = changeCase(ret);
928 if (flags['_'])
929 padChar = ' ';
930 else if (flags['0'])
931 padChar = '0';
932 if (flags['-'])
933 padWidth = 0;
934 return padStart(ret, padWidth, padChar);
935 }
936
937 // one minute in milliseconds
938 var OneMinute = 60000;
939 var ISO8601_TIMEZONE_PATTERN = /([zZ]|([+-])(\d{2}):(\d{2}))$/;
940 /**
941 * A date implementation with timezone info, just like Ruby date
942 *
943 * Implementation:
944 * - create a Date offset by it's timezone difference, avoiding overriding a bunch of methods
945 * - rewrite getTimezoneOffset() to trick strftime
946 */
947 var TimezoneDate = /** @class */ (function () {
948 function TimezoneDate(init, timezone) {
949 this.date = init instanceof TimezoneDate
950 ? init.date
951 : new Date(init);
952 this.timezoneOffset = isString(timezone) ? TimezoneDate.getTimezoneOffset(timezone, this.date) : timezone;
953 this.timezoneName = isString(timezone) ? timezone : '';
954 var diff = (this.date.getTimezoneOffset() - this.timezoneOffset) * OneMinute;
955 var time = this.date.getTime() + diff;
956 this.displayDate = new Date(time);
957 }
958 TimezoneDate.prototype.getTime = function () {
959 return this.displayDate.getTime();
960 };
961 TimezoneDate.prototype.getMilliseconds = function () {
962 return this.displayDate.getMilliseconds();
963 };
964 TimezoneDate.prototype.getSeconds = function () {
965 return this.displayDate.getSeconds();
966 };
967 TimezoneDate.prototype.getMinutes = function () {
968 return this.displayDate.getMinutes();
969 };
970 TimezoneDate.prototype.getHours = function () {
971 return this.displayDate.getHours();
972 };
973 TimezoneDate.prototype.getDay = function () {
974 return this.displayDate.getDay();
975 };
976 TimezoneDate.prototype.getDate = function () {
977 return this.displayDate.getDate();
978 };
979 TimezoneDate.prototype.getMonth = function () {
980 return this.displayDate.getMonth();
981 };
982 TimezoneDate.prototype.getFullYear = function () {
983 return this.displayDate.getFullYear();
984 };
985 TimezoneDate.prototype.toLocaleString = function (locale, init) {
986 if (init === null || init === void 0 ? void 0 : init.timeZone) {
987 return this.date.toLocaleString(locale, init);
988 }
989 return this.displayDate.toLocaleString(locale, init);
990 };
991 TimezoneDate.prototype.toLocaleTimeString = function (locale) {
992 return this.displayDate.toLocaleTimeString(locale);
993 };
994 TimezoneDate.prototype.toLocaleDateString = function (locale) {
995 return this.displayDate.toLocaleDateString(locale);
996 };
997 TimezoneDate.prototype.getTimezoneOffset = function () {
998 return this.timezoneOffset;
999 };
1000 TimezoneDate.prototype.getTimezoneName = function () {
1001 return this.timezoneName;
1002 };
1003 /**
1004 * Create a Date object fixed to it's declared Timezone. Both
1005 * - 2021-08-06T02:29:00.000Z and
1006 * - 2021-08-06T02:29:00.000+08:00
1007 * will always be displayed as
1008 * - 2021-08-06 02:29:00
1009 * regardless timezoneOffset in JavaScript realm
1010 *
1011 * The implementation hack:
1012 * Instead of calling `.getMonth()`/`.getUTCMonth()` respect to `preserveTimezones`,
1013 * we create a different Date to trick strftime, it's both simpler and more performant.
1014 * Given that a template is expected to be parsed fewer times than rendered.
1015 */
1016 TimezoneDate.createDateFixedToTimezone = function (dateString) {
1017 var m = dateString.match(ISO8601_TIMEZONE_PATTERN);
1018 // representing a UTC timestamp
1019 if (m && m[1] === 'Z') {
1020 return new TimezoneDate(+new Date(dateString), 0);
1021 }
1022 // has a timezone specified
1023 if (m && m[2] && m[3] && m[4]) {
1024 var _a = __read(m, 5), sign = _a[2], hours = _a[3], minutes = _a[4];
1025 var offset = (sign === '+' ? -1 : 1) * (parseInt(hours, 10) * 60 + parseInt(minutes, 10));
1026 return new TimezoneDate(+new Date(dateString), offset);
1027 }
1028 return new Date(dateString);
1029 };
1030 TimezoneDate.getTimezoneOffset = function (timezoneName, date) {
1031 if (date === void 0) { date = new Date(); }
1032 var localDateString = date.toLocaleString('en-US', { timeZone: timezoneName });
1033 var utcDateString = date.toLocaleString('en-US', { timeZone: 'UTC' });
1034 var localDate = new Date(localDateString);
1035 var utcDate = new Date(utcDateString);
1036 return (+utcDate - +localDate) / (60 * 1000);
1037 };
1038 return TimezoneDate;
1039 }());
1040
1041 var DelimitedToken = /** @class */ (function (_super) {
1042 __extends(DelimitedToken, _super);
1043 function DelimitedToken(kind, _a, input, begin, end, trimLeft, trimRight, file) {
1044 var _b = __read(_a, 2), contentBegin = _b[0], contentEnd = _b[1];
1045 var _this = _super.call(this, kind, input, begin, end, file) || this;
1046 _this.trimLeft = false;
1047 _this.trimRight = false;
1048 var tl = input[contentBegin] === '-';
1049 var tr = input[contentEnd - 1] === '-';
1050 var l = tl ? contentBegin + 1 : contentBegin;
1051 var r = tr ? contentEnd - 1 : contentEnd;
1052 while (l < r && (TYPES[input.charCodeAt(l)] & BLANK))
1053 l++;
1054 while (r > l && (TYPES[input.charCodeAt(r - 1)] & BLANK))
1055 r--;
1056 _this.contentRange = [l, r];
1057 _this.trimLeft = tl || trimLeft;
1058 _this.trimRight = tr || trimRight;
1059 return _this;
1060 }
1061 Object.defineProperty(DelimitedToken.prototype, "content", {
1062 get: function () {
1063 return this.input.slice(this.contentRange[0], this.contentRange[1]);
1064 },
1065 enumerable: false,
1066 configurable: true
1067 });
1068 return DelimitedToken;
1069 }(Token));
1070
1071 var TagToken = /** @class */ (function (_super) {
1072 __extends(TagToken, _super);
1073 function TagToken(input, begin, end, options, file) {
1074 var _this = this;
1075 var trimTagLeft = options.trimTagLeft, trimTagRight = options.trimTagRight, tagDelimiterLeft = options.tagDelimiterLeft, tagDelimiterRight = options.tagDelimiterRight;
1076 var _a = __read([begin + tagDelimiterLeft.length, end - tagDelimiterRight.length], 2), valueBegin = _a[0], valueEnd = _a[1];
1077 _this = _super.call(this, exports.TokenKind.Tag, [valueBegin, valueEnd], input, begin, end, trimTagLeft, trimTagRight, file) || this;
1078 _this.tokenizer = new Tokenizer(input, options.operators, file, _this.contentRange);
1079 _this.name = _this.tokenizer.readTagName();
1080 _this.tokenizer.assert(_this.name, "illegal tag syntax, tag name expected");
1081 _this.tokenizer.skipBlank();
1082 return _this;
1083 }
1084 Object.defineProperty(TagToken.prototype, "args", {
1085 get: function () {
1086 return this.tokenizer.input.slice(this.tokenizer.p, this.contentRange[1]);
1087 },
1088 enumerable: false,
1089 configurable: true
1090 });
1091 return TagToken;
1092 }(DelimitedToken));
1093
1094 var OutputToken = /** @class */ (function (_super) {
1095 __extends(OutputToken, _super);
1096 function OutputToken(input, begin, end, options, file) {
1097 var trimOutputLeft = options.trimOutputLeft, trimOutputRight = options.trimOutputRight, outputDelimiterLeft = options.outputDelimiterLeft, outputDelimiterRight = options.outputDelimiterRight;
1098 var valueRange = [begin + outputDelimiterLeft.length, end - outputDelimiterRight.length];
1099 return _super.call(this, exports.TokenKind.Output, valueRange, input, begin, end, trimOutputLeft, trimOutputRight, file) || this;
1100 }
1101 return OutputToken;
1102 }(DelimitedToken));
1103
1104 var HTMLToken = /** @class */ (function (_super) {
1105 __extends(HTMLToken, _super);
1106 function HTMLToken(input, begin, end, file) {
1107 var _this = _super.call(this, exports.TokenKind.HTML, input, begin, end, file) || this;
1108 _this.input = input;
1109 _this.begin = begin;
1110 _this.end = end;
1111 _this.file = file;
1112 _this.trimLeft = 0;
1113 _this.trimRight = 0;
1114 return _this;
1115 }
1116 HTMLToken.prototype.getContent = function () {
1117 return this.input.slice(this.begin + this.trimLeft, this.end - this.trimRight);
1118 };
1119 return HTMLToken;
1120 }(Token));
1121
1122 var NumberToken = /** @class */ (function (_super) {
1123 __extends(NumberToken, _super);
1124 function NumberToken(input, begin, end, file) {
1125 var _this = _super.call(this, exports.TokenKind.Number, input, begin, end, file) || this;
1126 _this.input = input;
1127 _this.begin = begin;
1128 _this.end = end;
1129 _this.file = file;
1130 _this.content = Number(_this.getText());
1131 return _this;
1132 }
1133 return NumberToken;
1134 }(Token));
1135
1136 var IdentifierToken = /** @class */ (function (_super) {
1137 __extends(IdentifierToken, _super);
1138 function IdentifierToken(input, begin, end, file) {
1139 var _this = _super.call(this, exports.TokenKind.Word, input, begin, end, file) || this;
1140 _this.input = input;
1141 _this.begin = begin;
1142 _this.end = end;
1143 _this.file = file;
1144 _this.content = _this.getText();
1145 return _this;
1146 }
1147 IdentifierToken.prototype.isNumber = function (allowSign) {
1148 if (allowSign === void 0) { allowSign = false; }
1149 var begin = allowSign && TYPES[this.input.charCodeAt(this.begin)] & SIGN
1150 ? this.begin + 1
1151 : this.begin;
1152 for (var i = begin; i < this.end; i++) {
1153 if (!(TYPES[this.input.charCodeAt(i)] & NUMBER))
1154 return false;
1155 }
1156 return true;
1157 };
1158 return IdentifierToken;
1159 }(Token));
1160
1161 var LiteralToken = /** @class */ (function (_super) {
1162 __extends(LiteralToken, _super);
1163 function LiteralToken(input, begin, end, file) {
1164 var _this = _super.call(this, exports.TokenKind.Literal, input, begin, end, file) || this;
1165 _this.input = input;
1166 _this.begin = begin;
1167 _this.end = end;
1168 _this.file = file;
1169 _this.literal = _this.getText();
1170 _this.content = literalValues[_this.literal];
1171 return _this;
1172 }
1173 return LiteralToken;
1174 }(Token));
1175
1176 var operatorPrecedences = {
1177 '==': 2,
1178 '!=': 2,
1179 '>': 2,
1180 '<': 2,
1181 '>=': 2,
1182 '<=': 2,
1183 'contains': 2,
1184 'not': 1,
1185 'and': 0,
1186 'or': 0
1187 };
1188 var operatorTypes = {
1189 '==': 0 /* OperatorType.Binary */,
1190 '!=': 0 /* OperatorType.Binary */,
1191 '>': 0 /* OperatorType.Binary */,
1192 '<': 0 /* OperatorType.Binary */,
1193 '>=': 0 /* OperatorType.Binary */,
1194 '<=': 0 /* OperatorType.Binary */,
1195 'contains': 0 /* OperatorType.Binary */,
1196 'not': 1 /* OperatorType.Unary */,
1197 'and': 0 /* OperatorType.Binary */,
1198 'or': 0 /* OperatorType.Binary */
1199 };
1200 var OperatorToken = /** @class */ (function (_super) {
1201 __extends(OperatorToken, _super);
1202 function OperatorToken(input, begin, end, file) {
1203 var _this = _super.call(this, exports.TokenKind.Operator, input, begin, end, file) || this;
1204 _this.input = input;
1205 _this.begin = begin;
1206 _this.end = end;
1207 _this.file = file;
1208 _this.operator = _this.getText();
1209 return _this;
1210 }
1211 OperatorToken.prototype.getPrecedence = function () {
1212 var key = this.getText();
1213 return key in operatorPrecedences ? operatorPrecedences[key] : 1;
1214 };
1215 return OperatorToken;
1216 }(Token));
1217
1218 var PropertyAccessToken = /** @class */ (function (_super) {
1219 __extends(PropertyAccessToken, _super);
1220 function PropertyAccessToken(variable, props, input, begin, end, file) {
1221 var _this = _super.call(this, exports.TokenKind.PropertyAccess, input, begin, end, file) || this;
1222 _this.variable = variable;
1223 _this.props = props;
1224 return _this;
1225 }
1226 return PropertyAccessToken;
1227 }(Token));
1228
1229 var FilterToken = /** @class */ (function (_super) {
1230 __extends(FilterToken, _super);
1231 function FilterToken(name, args, input, begin, end, file) {
1232 var _this = _super.call(this, exports.TokenKind.Filter, input, begin, end, file) || this;
1233 _this.name = name;
1234 _this.args = args;
1235 return _this;
1236 }
1237 return FilterToken;
1238 }(Token));
1239
1240 var HashToken = /** @class */ (function (_super) {
1241 __extends(HashToken, _super);
1242 function HashToken(input, begin, end, name, value, file) {
1243 var _this = _super.call(this, exports.TokenKind.Hash, input, begin, end, file) || this;
1244 _this.input = input;
1245 _this.begin = begin;
1246 _this.end = end;
1247 _this.name = name;
1248 _this.value = value;
1249 _this.file = file;
1250 return _this;
1251 }
1252 return HashToken;
1253 }(Token));
1254
1255 var rHex = /[\da-fA-F]/;
1256 var rOct = /[0-7]/;
1257 var escapeChar = {
1258 b: '\b',
1259 f: '\f',
1260 n: '\n',
1261 r: '\r',
1262 t: '\t',
1263 v: '\x0B'
1264 };
1265 function hexVal(c) {
1266 var code = c.charCodeAt(0);
1267 if (code >= 97)
1268 return code - 87;
1269 if (code >= 65)
1270 return code - 55;
1271 return code - 48;
1272 }
1273 function parseStringLiteral(str) {
1274 var ret = '';
1275 for (var i = 1; i < str.length - 1; i++) {
1276 if (str[i] !== '\\') {
1277 ret += str[i];
1278 continue;
1279 }
1280 if (escapeChar[str[i + 1]] !== undefined) {
1281 ret += escapeChar[str[++i]];
1282 }
1283 else if (str[i + 1] === 'u') {
1284 var val = 0;
1285 var j = i + 2;
1286 while (j <= i + 5 && rHex.test(str[j])) {
1287 val = val * 16 + hexVal(str[j++]);
1288 }
1289 i = j - 1;
1290 ret += String.fromCharCode(val);
1291 }
1292 else if (!rOct.test(str[i + 1])) {
1293 ret += str[++i];
1294 }
1295 else {
1296 var j = i + 1;
1297 var val = 0;
1298 while (j <= i + 3 && rOct.test(str[j])) {
1299 val = val * 8 + hexVal(str[j++]);
1300 }
1301 i = j - 1;
1302 ret += String.fromCharCode(val);
1303 }
1304 }
1305 return ret;
1306 }
1307
1308 var QuotedToken = /** @class */ (function (_super) {
1309 __extends(QuotedToken, _super);
1310 function QuotedToken(input, begin, end, file) {
1311 var _this = _super.call(this, exports.TokenKind.Quoted, input, begin, end, file) || this;
1312 _this.input = input;
1313 _this.begin = begin;
1314 _this.end = end;
1315 _this.file = file;
1316 _this.content = parseStringLiteral(_this.getText());
1317 return _this;
1318 }
1319 return QuotedToken;
1320 }(Token));
1321
1322 var RangeToken = /** @class */ (function (_super) {
1323 __extends(RangeToken, _super);
1324 function RangeToken(input, begin, end, lhs, rhs, file) {
1325 var _this = _super.call(this, exports.TokenKind.Range, input, begin, end, file) || this;
1326 _this.input = input;
1327 _this.begin = begin;
1328 _this.end = end;
1329 _this.lhs = lhs;
1330 _this.rhs = rhs;
1331 _this.file = file;
1332 return _this;
1333 }
1334 return RangeToken;
1335 }(Token));
1336
1337 /**
1338 * LiquidTagToken is different from TagToken by not having delimiters `{%` or `%}`
1339 */
1340 var LiquidTagToken = /** @class */ (function (_super) {
1341 __extends(LiquidTagToken, _super);
1342 function LiquidTagToken(input, begin, end, options, file) {
1343 var _this = _super.call(this, exports.TokenKind.Tag, [begin, end], input, begin, end, false, false, file) || this;
1344 _this.tokenizer = new Tokenizer(input, options.operators, file, _this.contentRange);
1345 _this.name = _this.tokenizer.readTagName();
1346 _this.tokenizer.assert(_this.name, 'illegal liquid tag syntax');
1347 _this.tokenizer.skipBlank();
1348 _this.args = _this.tokenizer.remaining();
1349 return _this;
1350 }
1351 return LiquidTagToken;
1352 }(DelimitedToken));
1353
1354 /**
1355 * value expression with optional filters
1356 * e.g.
1357 * {% assign foo="bar" | append: "coo" %}
1358 */
1359 var FilteredValueToken = /** @class */ (function (_super) {
1360 __extends(FilteredValueToken, _super);
1361 function FilteredValueToken(initial, filters, input, begin, end, file) {
1362 var _this = _super.call(this, exports.TokenKind.FilteredValue, input, begin, end, file) || this;
1363 _this.initial = initial;
1364 _this.filters = filters;
1365 _this.input = input;
1366 _this.begin = begin;
1367 _this.end = end;
1368 _this.file = file;
1369 return _this;
1370 }
1371 return FilteredValueToken;
1372 }(Token));
1373
1374 var SimpleEmitter = /** @class */ (function () {
1375 function SimpleEmitter() {
1376 this.buffer = '';
1377 }
1378 SimpleEmitter.prototype.write = function (html) {
1379 this.buffer += stringify(html);
1380 };
1381 return SimpleEmitter;
1382 }());
1383
1384 var StreamedEmitter = /** @class */ (function () {
1385 function StreamedEmitter() {
1386 this.buffer = '';
1387 this.stream = null;
1388 throw new Error('streaming not supported in browser');
1389 }
1390 return StreamedEmitter;
1391 }());
1392
1393 var KeepingTypeEmitter = /** @class */ (function () {
1394 function KeepingTypeEmitter() {
1395 this.buffer = '';
1396 }
1397 KeepingTypeEmitter.prototype.write = function (html) {
1398 html = toValue(html);
1399 // This will only preserve the type if the value is isolated.
1400 // I.E:
1401 // {{ my-port }} -> 42
1402 // {{ my-host }}:{{ my-port }} -> 'host:42'
1403 if (typeof html !== 'string' && this.buffer === '') {
1404 this.buffer = html;
1405 }
1406 else {
1407 this.buffer = stringify(this.buffer) + stringify(html);
1408 }
1409 };
1410 return KeepingTypeEmitter;
1411 }());
1412
1413 var Render = /** @class */ (function () {
1414 function Render() {
1415 }
1416 Render.prototype.renderTemplatesToNodeStream = function (templates, ctx) {
1417 var _this = this;
1418 var emitter = new StreamedEmitter();
1419 Promise.resolve().then(function () { return toPromise(_this.renderTemplates(templates, ctx, emitter)); })
1420 .then(function () { return emitter.end(); }, function (err) { return emitter.error(err); });
1421 return emitter.stream;
1422 };
1423 Render.prototype.renderTemplates = function (templates, ctx, emitter) {
1424 var errors, templates_1, templates_1_1, tpl, html, e_1, err, e_2_1;
1425 var e_2, _a;
1426 return __generator(this, function (_b) {
1427 switch (_b.label) {
1428 case 0:
1429 if (!emitter) {
1430 emitter = ctx.opts.keepOutputType ? new KeepingTypeEmitter() : new SimpleEmitter();
1431 }
1432 errors = [];
1433 _b.label = 1;
1434 case 1:
1435 _b.trys.push([1, 8, 9, 10]);
1436 templates_1 = __values(templates), templates_1_1 = templates_1.next();
1437 _b.label = 2;
1438 case 2:
1439 if (!!templates_1_1.done) return [3 /*break*/, 7];
1440 tpl = templates_1_1.value;
1441 _b.label = 3;
1442 case 3:
1443 _b.trys.push([3, 5, , 6]);
1444 return [4 /*yield*/, tpl.render(ctx, emitter)
1445 // if not, it'll return an `html`, write to the emitter for it
1446 ];
1447 case 4:
1448 html = _b.sent();
1449 // if not, it'll return an `html`, write to the emitter for it
1450 html && emitter.write(html);
1451 if (emitter['break'] || emitter['continue'])
1452 return [3 /*break*/, 7];
1453 return [3 /*break*/, 6];
1454 case 5:
1455 e_1 = _b.sent();
1456 err = LiquidError.is(e_1) ? e_1 : new RenderError(e_1, tpl);
1457 if (ctx.opts.catchAllErrors)
1458 errors.push(err);
1459 else
1460 throw err;
1461 return [3 /*break*/, 6];
1462 case 6:
1463 templates_1_1 = templates_1.next();
1464 return [3 /*break*/, 2];
1465 case 7: return [3 /*break*/, 10];
1466 case 8:
1467 e_2_1 = _b.sent();
1468 e_2 = { error: e_2_1 };
1469 return [3 /*break*/, 10];
1470 case 9:
1471 try {
1472 if (templates_1_1 && !templates_1_1.done && (_a = templates_1.return)) _a.call(templates_1);
1473 }
1474 finally { if (e_2) throw e_2.error; }
1475 return [7 /*endfinally*/];
1476 case 10:
1477 if (errors.length) {
1478 throw new LiquidErrors(errors);
1479 }
1480 return [2 /*return*/, emitter.buffer];
1481 }
1482 });
1483 };
1484 return Render;
1485 }());
1486
1487 var Expression = /** @class */ (function () {
1488 function Expression(tokens) {
1489 this.postfix = __spreadArray([], __read(toPostfix(tokens)), false);
1490 }
1491 Expression.prototype.evaluate = function (ctx, lenient) {
1492 var operands, _a, _b, token, r, result, l, _c, _d, e_1_1;
1493 var e_1, _e;
1494 return __generator(this, function (_f) {
1495 switch (_f.label) {
1496 case 0:
1497 assert(ctx, 'unable to evaluate: context not defined');
1498 operands = [];
1499 _f.label = 1;
1500 case 1:
1501 _f.trys.push([1, 11, 12, 13]);
1502 _a = __values(this.postfix), _b = _a.next();
1503 _f.label = 2;
1504 case 2:
1505 if (!!_b.done) return [3 /*break*/, 10];
1506 token = _b.value;
1507 if (!isOperatorToken(token)) return [3 /*break*/, 7];
1508 r = operands.pop();
1509 result = void 0;
1510 if (!(operatorTypes[token.operator] === 1 /* OperatorType.Unary */)) return [3 /*break*/, 4];
1511 return [4 /*yield*/, ctx.opts.operators[token.operator](r, ctx)];
1512 case 3:
1513 result = _f.sent();
1514 return [3 /*break*/, 6];
1515 case 4:
1516 l = operands.pop();
1517 return [4 /*yield*/, ctx.opts.operators[token.operator](l, r, ctx)];
1518 case 5:
1519 result = _f.sent();
1520 _f.label = 6;
1521 case 6:
1522 operands.push(result);
1523 return [3 /*break*/, 9];
1524 case 7:
1525 _d = (_c = operands).push;
1526 return [4 /*yield*/, evalToken(token, ctx, lenient)];
1527 case 8:
1528 _d.apply(_c, [_f.sent()]);
1529 _f.label = 9;
1530 case 9:
1531 _b = _a.next();
1532 return [3 /*break*/, 2];
1533 case 10: return [3 /*break*/, 13];
1534 case 11:
1535 e_1_1 = _f.sent();
1536 e_1 = { error: e_1_1 };
1537 return [3 /*break*/, 13];
1538 case 12:
1539 try {
1540 if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
1541 }
1542 finally { if (e_1) throw e_1.error; }
1543 return [7 /*endfinally*/];
1544 case 13: return [2 /*return*/, operands[0]];
1545 }
1546 });
1547 };
1548 Expression.prototype.valid = function () {
1549 return !!this.postfix.length;
1550 };
1551 return Expression;
1552 }());
1553 function evalToken(token, ctx, lenient) {
1554 if (lenient === void 0) { lenient = false; }
1555 return __generator(this, function (_a) {
1556 switch (_a.label) {
1557 case 0:
1558 if (!token)
1559 return [2 /*return*/];
1560 if ('content' in token)
1561 return [2 /*return*/, token.content];
1562 if (!isPropertyAccessToken(token)) return [3 /*break*/, 2];
1563 return [4 /*yield*/, evalPropertyAccessToken(token, ctx, lenient)];
1564 case 1: return [2 /*return*/, _a.sent()];
1565 case 2:
1566 if (!isRangeToken(token)) return [3 /*break*/, 4];
1567 return [4 /*yield*/, evalRangeToken(token, ctx)];
1568 case 3: return [2 /*return*/, _a.sent()];
1569 case 4: return [2 /*return*/];
1570 }
1571 });
1572 }
1573 function evalPropertyAccessToken(token, ctx, lenient) {
1574 var props, _a, _b, prop, _c, _d, e_2_1, variable, e_3;
1575 var e_2, _e;
1576 return __generator(this, function (_f) {
1577 switch (_f.label) {
1578 case 0:
1579 props = [];
1580 _f.label = 1;
1581 case 1:
1582 _f.trys.push([1, 6, 7, 8]);
1583 _a = __values(token.props), _b = _a.next();
1584 _f.label = 2;
1585 case 2:
1586 if (!!_b.done) return [3 /*break*/, 5];
1587 prop = _b.value;
1588 _d = (_c = props).push;
1589 return [4 /*yield*/, evalToken(prop, ctx, false)];
1590 case 3:
1591 _d.apply(_c, [(_f.sent())]);
1592 _f.label = 4;
1593 case 4:
1594 _b = _a.next();
1595 return [3 /*break*/, 2];
1596 case 5: return [3 /*break*/, 8];
1597 case 6:
1598 e_2_1 = _f.sent();
1599 e_2 = { error: e_2_1 };
1600 return [3 /*break*/, 8];
1601 case 7:
1602 try {
1603 if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
1604 }
1605 finally { if (e_2) throw e_2.error; }
1606 return [7 /*endfinally*/];
1607 case 8:
1608 _f.trys.push([8, 14, , 15]);
1609 if (!token.variable) return [3 /*break*/, 11];
1610 return [4 /*yield*/, evalToken(token.variable, ctx, lenient)];
1611 case 9:
1612 variable = _f.sent();
1613 return [4 /*yield*/, ctx._getFromScope(variable, props)];
1614 case 10: return [2 /*return*/, _f.sent()];
1615 case 11: return [4 /*yield*/, ctx._get(props)];
1616 case 12: return [2 /*return*/, _f.sent()];
1617 case 13: return [3 /*break*/, 15];
1618 case 14:
1619 e_3 = _f.sent();
1620 if (lenient && e_3.name === 'InternalUndefinedVariableError')
1621 return [2 /*return*/, null];
1622 throw (new UndefinedVariableError(e_3, token));
1623 case 15: return [2 /*return*/];
1624 }
1625 });
1626 }
1627 function evalQuotedToken(token) {
1628 return token.content;
1629 }
1630 function evalRangeToken(token, ctx) {
1631 var low, high;
1632 return __generator(this, function (_a) {
1633 switch (_a.label) {
1634 case 0: return [4 /*yield*/, evalToken(token.lhs, ctx)];
1635 case 1:
1636 low = _a.sent();
1637 return [4 /*yield*/, evalToken(token.rhs, ctx)];
1638 case 2:
1639 high = _a.sent();
1640 return [2 /*return*/, range(+low, +high + 1)];
1641 }
1642 });
1643 }
1644 function toPostfix(tokens) {
1645 var ops, tokens_1, tokens_1_1, token, e_4_1;
1646 var e_4, _a;
1647 return __generator(this, function (_b) {
1648 switch (_b.label) {
1649 case 0:
1650 ops = [];
1651 _b.label = 1;
1652 case 1:
1653 _b.trys.push([1, 10, 11, 12]);
1654 tokens_1 = __values(tokens), tokens_1_1 = tokens_1.next();
1655 _b.label = 2;
1656 case 2:
1657 if (!!tokens_1_1.done) return [3 /*break*/, 9];
1658 token = tokens_1_1.value;
1659 if (!isOperatorToken(token)) return [3 /*break*/, 6];
1660 _b.label = 3;
1661 case 3:
1662 if (!(ops.length && ops[ops.length - 1].getPrecedence() > token.getPrecedence())) return [3 /*break*/, 5];
1663 return [4 /*yield*/, ops.pop()];
1664 case 4:
1665 _b.sent();
1666 return [3 /*break*/, 3];
1667 case 5:
1668 ops.push(token);
1669 return [3 /*break*/, 8];
1670 case 6: return [4 /*yield*/, token];
1671 case 7:
1672 _b.sent();
1673 _b.label = 8;
1674 case 8:
1675 tokens_1_1 = tokens_1.next();
1676 return [3 /*break*/, 2];
1677 case 9: return [3 /*break*/, 12];
1678 case 10:
1679 e_4_1 = _b.sent();
1680 e_4 = { error: e_4_1 };
1681 return [3 /*break*/, 12];
1682 case 11:
1683 try {
1684 if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
1685 }
1686 finally { if (e_4) throw e_4.error; }
1687 return [7 /*endfinally*/];
1688 case 12:
1689 if (!ops.length) return [3 /*break*/, 14];
1690 return [4 /*yield*/, ops.pop()];
1691 case 13:
1692 _b.sent();
1693 return [3 /*break*/, 12];
1694 case 14: return [2 /*return*/];
1695 }
1696 });
1697 }
1698
1699 function isTruthy(val, ctx) {
1700 return !isFalsy(val, ctx);
1701 }
1702 function isFalsy(val, ctx) {
1703 val = toValue(val);
1704 if (ctx.opts.jsTruthy) {
1705 return !val;
1706 }
1707 else {
1708 return val === false || undefined === val || val === null;
1709 }
1710 }
1711
1712 var defaultOperators = {
1713 '==': equals,
1714 '!=': function (l, r) { return !equals(l, r); },
1715 '>': function (l, r) {
1716 if (isComparable(l))
1717 return l.gt(r);
1718 if (isComparable(r))
1719 return r.lt(l);
1720 return toValue(l) > toValue(r);
1721 },
1722 '<': function (l, r) {
1723 if (isComparable(l))
1724 return l.lt(r);
1725 if (isComparable(r))
1726 return r.gt(l);
1727 return toValue(l) < toValue(r);
1728 },
1729 '>=': function (l, r) {
1730 if (isComparable(l))
1731 return l.geq(r);
1732 if (isComparable(r))
1733 return r.leq(l);
1734 return toValue(l) >= toValue(r);
1735 },
1736 '<=': function (l, r) {
1737 if (isComparable(l))
1738 return l.leq(r);
1739 if (isComparable(r))
1740 return r.geq(l);
1741 return toValue(l) <= toValue(r);
1742 },
1743 'contains': function (l, r) {
1744 l = toValue(l);
1745 if (isArray(l))
1746 return l.some(function (i) { return equals(i, r); });
1747 if (isFunction(l === null || l === void 0 ? void 0 : l.indexOf))
1748 return l.indexOf(toValue(r)) > -1;
1749 return false;
1750 },
1751 'not': function (v, ctx) { return isFalsy(toValue(v), ctx); },
1752 'and': function (l, r, ctx) { return isTruthy(toValue(l), ctx) && isTruthy(toValue(r), ctx); },
1753 'or': function (l, r, ctx) { return isTruthy(toValue(l), ctx) || isTruthy(toValue(r), ctx); }
1754 };
1755 function equals(lhs, rhs) {
1756 if (isComparable(lhs))
1757 return lhs.equals(rhs);
1758 if (isComparable(rhs))
1759 return rhs.equals(lhs);
1760 lhs = toValue(lhs);
1761 rhs = toValue(rhs);
1762 if (isArray(lhs)) {
1763 return isArray(rhs) && arrayEquals(lhs, rhs);
1764 }
1765 return lhs === rhs;
1766 }
1767 function arrayEquals(lhs, rhs) {
1768 if (lhs.length !== rhs.length)
1769 return false;
1770 return !lhs.some(function (value, i) { return !equals(value, rhs[i]); });
1771 }
1772
1773 var Node = /** @class */ (function () {
1774 function Node(key, value, next, prev) {
1775 this.key = key;
1776 this.value = value;
1777 this.next = next;
1778 this.prev = prev;
1779 }
1780 return Node;
1781 }());
1782 var LRU = /** @class */ (function () {
1783 function LRU(limit, size) {
1784 if (size === void 0) { size = 0; }
1785 this.limit = limit;
1786 this.size = size;
1787 this.cache = {};
1788 this.head = new Node('HEAD', null, null, null);
1789 this.tail = new Node('TAIL', null, null, null);
1790 this.head.next = this.tail;
1791 this.tail.prev = this.head;
1792 }
1793 LRU.prototype.write = function (key, value) {
1794 if (this.cache[key]) {
1795 this.cache[key].value = value;
1796 }
1797 else {
1798 var node = new Node(key, value, this.head.next, this.head);
1799 this.head.next.prev = node;
1800 this.head.next = node;
1801 this.cache[key] = node;
1802 this.size++;
1803 this.ensureLimit();
1804 }
1805 };
1806 LRU.prototype.read = function (key) {
1807 if (!this.cache[key])
1808 return;
1809 var value = this.cache[key].value;
1810 this.remove(key);
1811 this.write(key, value);
1812 return value;
1813 };
1814 LRU.prototype.remove = function (key) {
1815 var node = this.cache[key];
1816 node.prev.next = node.next;
1817 node.next.prev = node.prev;
1818 delete this.cache[key];
1819 this.size--;
1820 };
1821 LRU.prototype.clear = function () {
1822 this.head.next = this.tail;
1823 this.tail.prev = this.head;
1824 this.size = 0;
1825 this.cache = {};
1826 };
1827 LRU.prototype.ensureLimit = function () {
1828 if (this.size > this.limit)
1829 this.remove(this.tail.prev.key);
1830 };
1831 return LRU;
1832 }());
1833
1834 function domResolve(root, path) {
1835 var base = document.createElement('base');
1836 base.href = root;
1837 var head = document.getElementsByTagName('head')[0];
1838 head.insertBefore(base, head.firstChild);
1839 var a = document.createElement('a');
1840 a.href = path;
1841 var resolved = a.href;
1842 head.removeChild(base);
1843 return resolved;
1844 }
1845 function resolve(root, filepath, ext) {
1846 if (root.length && last(root) !== '/')
1847 root += '/';
1848 var url = domResolve(root, filepath);
1849 return url.replace(/^(\w+:\/\/[^/]+)(\/[^?]+)/, function (str, origin, path) {
1850 var last = path.split('/').pop();
1851 if (/\.\w+$/.test(last))
1852 return str;
1853 return origin + path + ext;
1854 });
1855 }
1856 function readFile(url) {
1857 return __awaiter(this, void 0, void 0, function () {
1858 return __generator(this, function (_a) {
1859 return [2 /*return*/, new Promise(function (resolve, reject) {
1860 var xhr = new XMLHttpRequest();
1861 xhr.onload = function () {
1862 if (xhr.status >= 200 && xhr.status < 300) {
1863 resolve(xhr.responseText);
1864 }
1865 else {
1866 reject(new Error(xhr.statusText));
1867 }
1868 };
1869 xhr.onerror = function () {
1870 reject(new Error('An error occurred whilst receiving the response.'));
1871 };
1872 xhr.open('GET', url);
1873 xhr.send();
1874 })];
1875 });
1876 });
1877 }
1878 function readFileSync(url) {
1879 var xhr = new XMLHttpRequest();
1880 xhr.open('GET', url, false);
1881 xhr.send();
1882 if (xhr.status < 200 || xhr.status >= 300) {
1883 throw new Error(xhr.statusText);
1884 }
1885 return xhr.responseText;
1886 }
1887 function exists(filepath) {
1888 return __awaiter(this, void 0, void 0, function () {
1889 return __generator(this, function (_a) {
1890 return [2 /*return*/, true];
1891 });
1892 });
1893 }
1894 function existsSync(filepath) {
1895 return true;
1896 }
1897 function dirname(filepath) {
1898 return domResolve(filepath, '.');
1899 }
1900 var sep = '/';
1901
1902 var fs = /*#__PURE__*/Object.freeze({
1903 __proto__: null,
1904 resolve: resolve,
1905 readFile: readFile,
1906 readFileSync: readFileSync,
1907 exists: exists,
1908 existsSync: existsSync,
1909 dirname: dirname,
1910 sep: sep
1911 });
1912
1913 function defaultFilter(value, defaultValue) {
1914 var args = [];
1915 for (var _i = 2; _i < arguments.length; _i++) {
1916 args[_i - 2] = arguments[_i];
1917 }
1918 value = toValue(value);
1919 if (isArray(value) || isString(value))
1920 return value.length ? value : defaultValue;
1921 if (value === false && (new Map(args)).get('allow_false'))
1922 return false;
1923 return isFalsy(value, this.context) ? defaultValue : value;
1924 }
1925 function json(value, space) {
1926 if (space === void 0) { space = 0; }
1927 return JSON.stringify(value, null, space);
1928 }
1929 function inspect(value, space) {
1930 if (space === void 0) { space = 0; }
1931 var ancestors = [];
1932 return JSON.stringify(value, function (_key, value) {
1933 if (typeof value !== 'object' || value === null)
1934 return value;
1935 // `this` is the object that value is contained in, i.e., its direct parent.
1936 while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this)
1937 ancestors.pop();
1938 if (ancestors.includes(value))
1939 return '[Circular]';
1940 ancestors.push(value);
1941 return value;
1942 }, space);
1943 }
1944 function to_integer(value) {
1945 return Number(value);
1946 }
1947 var raw = {
1948 raw: true,
1949 handler: identify
1950 };
1951 var misc = {
1952 default: defaultFilter,
1953 raw: raw,
1954 jsonify: json,
1955 to_integer: to_integer,
1956 json: json,
1957 inspect: inspect
1958 };
1959
1960 var escapeMap = {
1961 '&': '&amp;',
1962 '<': '&lt;',
1963 '>': '&gt;',
1964 '"': '&#34;',
1965 "'": '&#39;'
1966 };
1967 var unescapeMap = {
1968 '&amp;': '&',
1969 '&lt;': '<',
1970 '&gt;': '>',
1971 '&#34;': '"',
1972 '&#39;': "'"
1973 };
1974 function escape(str) {
1975 return stringify(str).replace(/&|<|>|"|'/g, function (m) { return escapeMap[m]; });
1976 }
1977 function xml_escape(str) {
1978 return escape(str);
1979 }
1980 function unescape(str) {
1981 return stringify(str).replace(/&(amp|lt|gt|#34|#39);/g, function (m) { return unescapeMap[m]; });
1982 }
1983 function escape_once(str) {
1984 return escape(unescape(stringify(str)));
1985 }
1986 function newline_to_br(v) {
1987 return stringify(v).replace(/\r?\n/gm, '<br />\n');
1988 }
1989 function strip_html(v) {
1990 return stringify(v).replace(/<script[\s\S]*?<\/script>|<style[\s\S]*?<\/style>|<.*?>|<!--[\s\S]*?-->/g, '');
1991 }
1992
1993 var htmlFilters = /*#__PURE__*/Object.freeze({
1994 __proto__: null,
1995 escape: escape,
1996 xml_escape: xml_escape,
1997 escape_once: escape_once,
1998 newline_to_br: newline_to_br,
1999 strip_html: strip_html
2000 });
2001
2002 var defaultOptions = {
2003 root: ['.'],
2004 layouts: ['.'],
2005 partials: ['.'],
2006 relativeReference: true,
2007 jekyllInclude: false,
2008 cache: undefined,
2009 extname: '',
2010 fs: fs,
2011 dynamicPartials: true,
2012 jsTruthy: false,
2013 dateFormat: '%A, %B %-e, %Y at %-l:%M %P %z',
2014 trimTagRight: false,
2015 trimTagLeft: false,
2016 trimOutputRight: false,
2017 trimOutputLeft: false,
2018 greedy: true,
2019 tagDelimiterLeft: '{%',
2020 tagDelimiterRight: '%}',
2021 outputDelimiterLeft: '{{',
2022 outputDelimiterRight: '}}',
2023 preserveTimezones: false,
2024 strictFilters: false,
2025 strictVariables: false,
2026 ownPropertyOnly: true,
2027 lenientIf: false,
2028 globals: {},
2029 keepOutputType: false,
2030 operators: defaultOperators
2031 };
2032 function normalize(options) {
2033 if (options.hasOwnProperty('root')) {
2034 if (!options.hasOwnProperty('partials'))
2035 options.partials = options.root;
2036 if (!options.hasOwnProperty('layouts'))
2037 options.layouts = options.root;
2038 }
2039 if (options.hasOwnProperty('cache')) {
2040 var cache = void 0;
2041 if (typeof options.cache === 'number')
2042 cache = options.cache > 0 ? new LRU(options.cache) : undefined;
2043 else if (typeof options.cache === 'object')
2044 cache = options.cache;
2045 else
2046 cache = options.cache ? new LRU(1024) : undefined;
2047 options.cache = cache;
2048 }
2049 options = __assign(__assign(__assign({}, defaultOptions), (options.jekyllInclude ? { dynamicPartials: false } : {})), options);
2050 if ((!options.fs.dirname || !options.fs.sep) && options.relativeReference) {
2051 console.warn('[LiquidJS] `fs.dirname` and `fs.sep` are required for relativeReference, set relativeReference to `false` to suppress this warning');
2052 options.relativeReference = false;
2053 }
2054 options.root = normalizeDirectoryList(options.root);
2055 options.partials = normalizeDirectoryList(options.partials);
2056 options.layouts = normalizeDirectoryList(options.layouts);
2057 options.outputEscape = options.outputEscape && getOutputEscapeFunction(options.outputEscape);
2058 return options;
2059 }
2060 function getOutputEscapeFunction(nameOrFunction) {
2061 if (nameOrFunction === 'escape')
2062 return escape;
2063 if (nameOrFunction === 'json')
2064 return misc.json;
2065 assert(isFunction(nameOrFunction), '`outputEscape` need to be of type string or function');
2066 return nameOrFunction;
2067 }
2068 function normalizeDirectoryList(value) {
2069 var list = [];
2070 if (isArray(value))
2071 list = value;
2072 if (isString(value))
2073 list = [value];
2074 return list;
2075 }
2076
2077 function whiteSpaceCtrl(tokens, options) {
2078 var inRaw = false;
2079 for (var i = 0; i < tokens.length; i++) {
2080 var token = tokens[i];
2081 if (!isDelimitedToken(token))
2082 continue;
2083 if (!inRaw && token.trimLeft) {
2084 trimLeft(tokens[i - 1], options.greedy);
2085 }
2086 if (isTagToken(token)) {
2087 if (token.name === 'raw')
2088 inRaw = true;
2089 else if (token.name === 'endraw')
2090 inRaw = false;
2091 }
2092 if (!inRaw && token.trimRight) {
2093 trimRight(tokens[i + 1], options.greedy);
2094 }
2095 }
2096 }
2097 function trimLeft(token, greedy) {
2098 if (!token || !isHTMLToken(token))
2099 return;
2100 var mask = greedy ? BLANK : INLINE_BLANK;
2101 while (TYPES[token.input.charCodeAt(token.end - 1 - token.trimRight)] & mask)
2102 token.trimRight++;
2103 }
2104 function trimRight(token, greedy) {
2105 if (!token || !isHTMLToken(token))
2106 return;
2107 var mask = greedy ? BLANK : INLINE_BLANK;
2108 while (TYPES[token.input.charCodeAt(token.begin + token.trimLeft)] & mask)
2109 token.trimLeft++;
2110 if (token.input.charAt(token.begin + token.trimLeft) === '\n')
2111 token.trimLeft++;
2112 }
2113
2114 var Tokenizer = /** @class */ (function () {
2115 function Tokenizer(input, operators, file, range) {
2116 if (operators === void 0) { operators = defaultOptions.operators; }
2117 this.input = input;
2118 this.file = file;
2119 this.rawBeginAt = -1;
2120 this.p = range ? range[0] : 0;
2121 this.N = range ? range[1] : input.length;
2122 this.opTrie = createTrie(operators);
2123 this.literalTrie = createTrie(literalValues);
2124 }
2125 Tokenizer.prototype.readExpression = function () {
2126 return new Expression(this.readExpressionTokens());
2127 };
2128 Tokenizer.prototype.readExpressionTokens = function () {
2129 var operator, operand;
2130 return __generator(this, function (_a) {
2131 switch (_a.label) {
2132 case 0:
2133 if (!(this.p < this.N)) return [3 /*break*/, 5];
2134 operator = this.readOperator();
2135 if (!operator) return [3 /*break*/, 2];
2136 return [4 /*yield*/, operator];
2137 case 1:
2138 _a.sent();
2139 return [3 /*break*/, 0];
2140 case 2:
2141 operand = this.readValue();
2142 if (!operand) return [3 /*break*/, 4];
2143 return [4 /*yield*/, operand];
2144 case 3:
2145 _a.sent();
2146 return [3 /*break*/, 0];
2147 case 4: return [2 /*return*/];
2148 case 5: return [2 /*return*/];
2149 }
2150 });
2151 };
2152 Tokenizer.prototype.readOperator = function () {
2153 this.skipBlank();
2154 var end = this.matchTrie(this.opTrie);
2155 if (end === -1)
2156 return;
2157 return new OperatorToken(this.input, this.p, (this.p = end), this.file);
2158 };
2159 Tokenizer.prototype.matchTrie = function (trie) {
2160 var node = trie;
2161 var i = this.p;
2162 var info;
2163 while (node[this.input[i]] && i < this.N) {
2164 node = node[this.input[i++]];
2165 if (node['end'])
2166 info = node;
2167 }
2168 if (!info)
2169 return -1;
2170 if (info['needBoundary'] && isWord(this.peek(i - this.p)))
2171 return -1;
2172 return i;
2173 };
2174 Tokenizer.prototype.readFilteredValue = function () {
2175 var begin = this.p;
2176 var initial = this.readExpression();
2177 this.assert(initial.valid(), "invalid value expression: ".concat(this.snapshot()));
2178 var filters = this.readFilters();
2179 return new FilteredValueToken(initial, filters, this.input, begin, this.p, this.file);
2180 };
2181 Tokenizer.prototype.readFilters = function () {
2182 var filters = [];
2183 while (true) {
2184 var filter = this.readFilter();
2185 if (!filter)
2186 return filters;
2187 filters.push(filter);
2188 }
2189 };
2190 Tokenizer.prototype.readFilter = function () {
2191 var _this = this;
2192 this.skipBlank();
2193 if (this.end())
2194 return null;
2195 this.assert(this.peek() === '|', "expected \"|\" before filter");
2196 this.p++;
2197 var begin = this.p;
2198 var name = this.readIdentifier();
2199 if (!name.size()) {
2200 this.assert(this.end(), "expected filter name");
2201 return null;
2202 }
2203 var args = [];
2204 this.skipBlank();
2205 if (this.peek() === ':') {
2206 do {
2207 ++this.p;
2208 var arg = this.readFilterArg();
2209 arg && args.push(arg);
2210 this.skipBlank();
2211 this.assert(this.end() || this.peek() === ',' || this.peek() === '|', function () { return "unexpected character ".concat(_this.snapshot()); });
2212 } while (this.peek() === ',');
2213 }
2214 else if (this.peek() === '|' || this.end()) ;
2215 else {
2216 throw this.error('expected ":" after filter name');
2217 }
2218 return new FilterToken(name.getText(), args, this.input, begin, this.p, this.file);
2219 };
2220 Tokenizer.prototype.readFilterArg = function () {
2221 var key = this.readValue();
2222 if (!key)
2223 return;
2224 this.skipBlank();
2225 if (this.peek() !== ':')
2226 return key;
2227 ++this.p;
2228 var value = this.readValue();
2229 return [key.getText(), value];
2230 };
2231 Tokenizer.prototype.readTopLevelTokens = function (options) {
2232 if (options === void 0) { options = defaultOptions; }
2233 var tokens = [];
2234 while (this.p < this.N) {
2235 var token = this.readTopLevelToken(options);
2236 tokens.push(token);
2237 }
2238 whiteSpaceCtrl(tokens, options);
2239 return tokens;
2240 };
2241 Tokenizer.prototype.readTopLevelToken = function (options) {
2242 var tagDelimiterLeft = options.tagDelimiterLeft, outputDelimiterLeft = options.outputDelimiterLeft;
2243 if (this.rawBeginAt > -1)
2244 return this.readEndrawOrRawContent(options);
2245 if (this.match(tagDelimiterLeft))
2246 return this.readTagToken(options);
2247 if (this.match(outputDelimiterLeft))
2248 return this.readOutputToken(options);
2249 return this.readHTMLToken([tagDelimiterLeft, outputDelimiterLeft]);
2250 };
2251 Tokenizer.prototype.readHTMLToken = function (stopStrings) {
2252 var _this = this;
2253 var begin = this.p;
2254 while (this.p < this.N) {
2255 if (stopStrings.some(function (str) { return _this.match(str); }))
2256 break;
2257 ++this.p;
2258 }
2259 return new HTMLToken(this.input, begin, this.p, this.file);
2260 };
2261 Tokenizer.prototype.readTagToken = function (options) {
2262 if (options === void 0) { options = defaultOptions; }
2263 var _a = this, file = _a.file, input = _a.input;
2264 var begin = this.p;
2265 if (this.readToDelimiter(options.tagDelimiterRight) === -1) {
2266 throw this.error("tag ".concat(this.snapshot(begin), " not closed"), begin);
2267 }
2268 var token = new TagToken(input, begin, this.p, options, file);
2269 if (token.name === 'raw')
2270 this.rawBeginAt = begin;
2271 return token;
2272 };
2273 Tokenizer.prototype.readToDelimiter = function (delimiter, respectQuoted) {
2274 if (respectQuoted === void 0) { respectQuoted = false; }
2275 this.skipBlank();
2276 while (this.p < this.N) {
2277 if (respectQuoted && (this.peekType() & QUOTE)) {
2278 this.readQuoted();
2279 continue;
2280 }
2281 ++this.p;
2282 if (this.rmatch(delimiter))
2283 return this.p;
2284 }
2285 return -1;
2286 };
2287 Tokenizer.prototype.readOutputToken = function (options) {
2288 if (options === void 0) { options = defaultOptions; }
2289 var _a = this, file = _a.file, input = _a.input;
2290 var outputDelimiterRight = options.outputDelimiterRight;
2291 var begin = this.p;
2292 if (this.readToDelimiter(outputDelimiterRight, true) === -1) {
2293 throw this.error("output ".concat(this.snapshot(begin), " not closed"), begin);
2294 }
2295 return new OutputToken(input, begin, this.p, options, file);
2296 };
2297 Tokenizer.prototype.readEndrawOrRawContent = function (options) {
2298 var tagDelimiterLeft = options.tagDelimiterLeft, tagDelimiterRight = options.tagDelimiterRight;
2299 var begin = this.p;
2300 var leftPos = this.readTo(tagDelimiterLeft) - tagDelimiterLeft.length;
2301 while (this.p < this.N) {
2302 if (this.readIdentifier().getText() !== 'endraw') {
2303 leftPos = this.readTo(tagDelimiterLeft) - tagDelimiterLeft.length;
2304 continue;
2305 }
2306 while (this.p <= this.N) {
2307 if (this.rmatch(tagDelimiterRight)) {
2308 var end = this.p;
2309 if (begin === leftPos) {
2310 this.rawBeginAt = -1;
2311 return new TagToken(this.input, begin, end, options, this.file);
2312 }
2313 else {
2314 this.p = leftPos;
2315 return new HTMLToken(this.input, begin, leftPos, this.file);
2316 }
2317 }
2318 if (this.rmatch(tagDelimiterLeft))
2319 break;
2320 this.p++;
2321 }
2322 }
2323 throw this.error("raw ".concat(this.snapshot(this.rawBeginAt), " not closed"), begin);
2324 };
2325 Tokenizer.prototype.readLiquidTagTokens = function (options) {
2326 if (options === void 0) { options = defaultOptions; }
2327 var tokens = [];
2328 while (this.p < this.N) {
2329 var token = this.readLiquidTagToken(options);
2330 token && tokens.push(token);
2331 }
2332 return tokens;
2333 };
2334 Tokenizer.prototype.readLiquidTagToken = function (options) {
2335 this.skipBlank();
2336 if (this.end())
2337 return;
2338 var begin = this.p;
2339 this.readToDelimiter('\n');
2340 var end = this.p;
2341 return new LiquidTagToken(this.input, begin, end, options, this.file);
2342 };
2343 Tokenizer.prototype.error = function (msg, pos) {
2344 if (pos === void 0) { pos = this.p; }
2345 return new TokenizationError(msg, new IdentifierToken(this.input, pos, this.N, this.file));
2346 };
2347 Tokenizer.prototype.assert = function (pred, msg, pos) {
2348 if (!pred)
2349 throw this.error(typeof msg === 'function' ? msg() : msg, pos);
2350 };
2351 Tokenizer.prototype.snapshot = function (begin) {
2352 if (begin === void 0) { begin = this.p; }
2353 return JSON.stringify(ellipsis(this.input.slice(begin, this.N), 32));
2354 };
2355 /**
2356 * @deprecated use #readIdentifier instead
2357 */
2358 Tokenizer.prototype.readWord = function () {
2359 return this.readIdentifier();
2360 };
2361 Tokenizer.prototype.readIdentifier = function () {
2362 this.skipBlank();
2363 var begin = this.p;
2364 while (!this.end() && isWord(this.peek()))
2365 ++this.p;
2366 return new IdentifierToken(this.input, begin, this.p, this.file);
2367 };
2368 Tokenizer.prototype.readNonEmptyIdentifier = function () {
2369 var id = this.readIdentifier();
2370 return id.size() ? id : undefined;
2371 };
2372 Tokenizer.prototype.readTagName = function () {
2373 this.skipBlank();
2374 // Handle inline comment tags
2375 if (this.input[this.p] === '#')
2376 return this.input.slice(this.p, ++this.p);
2377 return this.readIdentifier().getText();
2378 };
2379 Tokenizer.prototype.readHashes = function (jekyllStyle) {
2380 var hashes = [];
2381 while (true) {
2382 var hash = this.readHash(jekyllStyle);
2383 if (!hash)
2384 return hashes;
2385 hashes.push(hash);
2386 }
2387 };
2388 Tokenizer.prototype.readHash = function (jekyllStyle) {
2389 this.skipBlank();
2390 if (this.peek() === ',')
2391 ++this.p;
2392 var begin = this.p;
2393 var name = this.readNonEmptyIdentifier();
2394 if (!name)
2395 return;
2396 var value;
2397 this.skipBlank();
2398 var sep = jekyllStyle ? '=' : ':';
2399 if (this.peek() === sep) {
2400 ++this.p;
2401 value = this.readValue();
2402 }
2403 return new HashToken(this.input, begin, this.p, name, value, this.file);
2404 };
2405 Tokenizer.prototype.remaining = function () {
2406 return this.input.slice(this.p, this.N);
2407 };
2408 Tokenizer.prototype.advance = function (step) {
2409 if (step === void 0) { step = 1; }
2410 this.p += step;
2411 };
2412 Tokenizer.prototype.end = function () {
2413 return this.p >= this.N;
2414 };
2415 Tokenizer.prototype.readTo = function (end) {
2416 while (this.p < this.N) {
2417 ++this.p;
2418 if (this.rmatch(end))
2419 return this.p;
2420 }
2421 return -1;
2422 };
2423 Tokenizer.prototype.readValue = function () {
2424 this.skipBlank();
2425 var begin = this.p;
2426 var variable = this.readLiteral() || this.readQuoted() || this.readRange() || this.readNumber();
2427 var props = this.readProperties(!variable);
2428 if (!props.length)
2429 return variable;
2430 return new PropertyAccessToken(variable, props, this.input, begin, this.p);
2431 };
2432 Tokenizer.prototype.readScopeValue = function () {
2433 this.skipBlank();
2434 var begin = this.p;
2435 var props = this.readProperties();
2436 if (!props.length)
2437 return undefined;
2438 return new PropertyAccessToken(undefined, props, this.input, begin, this.p);
2439 };
2440 Tokenizer.prototype.readProperties = function (isBegin) {
2441 if (isBegin === void 0) { isBegin = true; }
2442 var props = [];
2443 while (true) {
2444 if (this.peek() === '[') {
2445 this.p++;
2446 var prop = this.readValue() || new IdentifierToken(this.input, this.p, this.p, this.file);
2447 this.assert(this.readTo(']') !== -1, '[ not closed');
2448 props.push(prop);
2449 continue;
2450 }
2451 if (isBegin && !props.length) {
2452 var prop = this.readNonEmptyIdentifier();
2453 if (prop) {
2454 props.push(prop);
2455 continue;
2456 }
2457 }
2458 if (this.peek() === '.' && this.peek(1) !== '.') { // skip range syntax
2459 this.p++;
2460 var prop = this.readNonEmptyIdentifier();
2461 if (!prop)
2462 break;
2463 props.push(prop);
2464 continue;
2465 }
2466 break;
2467 }
2468 return props;
2469 };
2470 Tokenizer.prototype.readNumber = function () {
2471 this.skipBlank();
2472 var decimalFound = false;
2473 var digitFound = false;
2474 var n = 0;
2475 if (this.peekType() & SIGN)
2476 n++;
2477 while (this.p + n <= this.N) {
2478 if (this.peekType(n) & NUMBER) {
2479 digitFound = true;
2480 n++;
2481 }
2482 else if (this.peek(n) === '.' && this.peek(n + 1) !== '.') {
2483 if (decimalFound || !digitFound)
2484 return;
2485 decimalFound = true;
2486 n++;
2487 }
2488 else
2489 break;
2490 }
2491 if (digitFound && !isWord(this.peek(n))) {
2492 var num = new NumberToken(this.input, this.p, this.p + n, this.file);
2493 this.advance(n);
2494 return num;
2495 }
2496 };
2497 Tokenizer.prototype.readLiteral = function () {
2498 this.skipBlank();
2499 var end = this.matchTrie(this.literalTrie);
2500 if (end === -1)
2501 return;
2502 var literal = new LiteralToken(this.input, this.p, end, this.file);
2503 this.p = end;
2504 return literal;
2505 };
2506 Tokenizer.prototype.readRange = function () {
2507 this.skipBlank();
2508 var begin = this.p;
2509 if (this.peek() !== '(')
2510 return;
2511 ++this.p;
2512 var lhs = this.readValueOrThrow();
2513 this.p += 2;
2514 var rhs = this.readValueOrThrow();
2515 ++this.p;
2516 return new RangeToken(this.input, begin, this.p, lhs, rhs, this.file);
2517 };
2518 Tokenizer.prototype.readValueOrThrow = function () {
2519 var _this = this;
2520 var value = this.readValue();
2521 this.assert(value, function () { return "unexpected token ".concat(_this.snapshot(), ", value expected"); });
2522 return value;
2523 };
2524 Tokenizer.prototype.readQuoted = function () {
2525 this.skipBlank();
2526 var begin = this.p;
2527 if (!(this.peekType() & QUOTE))
2528 return;
2529 ++this.p;
2530 var escaped = false;
2531 while (this.p < this.N) {
2532 ++this.p;
2533 if (this.input[this.p - 1] === this.input[begin] && !escaped)
2534 break;
2535 if (escaped)
2536 escaped = false;
2537 else if (this.input[this.p - 1] === '\\')
2538 escaped = true;
2539 }
2540 return new QuotedToken(this.input, begin, this.p, this.file);
2541 };
2542 Tokenizer.prototype.readFileNameTemplate = function (options) {
2543 var outputDelimiterLeft, htmlStopStrings, htmlStopStringSet;
2544 return __generator(this, function (_a) {
2545 switch (_a.label) {
2546 case 0:
2547 outputDelimiterLeft = options.outputDelimiterLeft;
2548 htmlStopStrings = [',', ' ', outputDelimiterLeft];
2549 htmlStopStringSet = new Set(htmlStopStrings);
2550 _a.label = 1;
2551 case 1:
2552 if (!(this.p < this.N && !htmlStopStringSet.has(this.peek()))) return [3 /*break*/, 3];
2553 return [4 /*yield*/, this.match(outputDelimiterLeft)
2554 ? this.readOutputToken(options)
2555 : this.readHTMLToken(htmlStopStrings)];
2556 case 2:
2557 _a.sent();
2558 return [3 /*break*/, 1];
2559 case 3: return [2 /*return*/];
2560 }
2561 });
2562 };
2563 Tokenizer.prototype.match = function (word) {
2564 for (var i = 0; i < word.length; i++) {
2565 if (word[i] !== this.input[this.p + i])
2566 return false;
2567 }
2568 return true;
2569 };
2570 Tokenizer.prototype.rmatch = function (pattern) {
2571 for (var i = 0; i < pattern.length; i++) {
2572 if (pattern[pattern.length - 1 - i] !== this.input[this.p - 1 - i])
2573 return false;
2574 }
2575 return true;
2576 };
2577 Tokenizer.prototype.peekType = function (n) {
2578 if (n === void 0) { n = 0; }
2579 return this.p + n >= this.N ? 0 : TYPES[this.input.charCodeAt(this.p + n)];
2580 };
2581 Tokenizer.prototype.peek = function (n) {
2582 if (n === void 0) { n = 0; }
2583 return this.p + n >= this.N ? '' : this.input[this.p + n];
2584 };
2585 Tokenizer.prototype.skipBlank = function () {
2586 while (this.peekType() & BLANK)
2587 ++this.p;
2588 };
2589 return Tokenizer;
2590 }());
2591
2592 var ParseStream = /** @class */ (function () {
2593 function ParseStream(tokens, parseToken) {
2594 this.handlers = {};
2595 this.stopRequested = false;
2596 this.tokens = tokens;
2597 this.parseToken = parseToken;
2598 }
2599 ParseStream.prototype.on = function (name, cb) {
2600 this.handlers[name] = cb;
2601 return this;
2602 };
2603 ParseStream.prototype.trigger = function (event, arg) {
2604 var h = this.handlers[event];
2605 return h ? (h.call(this, arg), true) : false;
2606 };
2607 ParseStream.prototype.start = function () {
2608 this.trigger('start');
2609 var token;
2610 while (!this.stopRequested && (token = this.tokens.shift())) {
2611 if (this.trigger('token', token))
2612 continue;
2613 if (isTagToken(token) && this.trigger("tag:".concat(token.name), token)) {
2614 continue;
2615 }
2616 var template = this.parseToken(token, this.tokens);
2617 this.trigger('template', template);
2618 }
2619 if (!this.stopRequested)
2620 this.trigger('end');
2621 return this;
2622 };
2623 ParseStream.prototype.stop = function () {
2624 this.stopRequested = true;
2625 return this;
2626 };
2627 return ParseStream;
2628 }());
2629
2630 var TemplateImpl = /** @class */ (function () {
2631 function TemplateImpl(token) {
2632 this.token = token;
2633 }
2634 return TemplateImpl;
2635 }());
2636
2637 var Tag = /** @class */ (function (_super) {
2638 __extends(Tag, _super);
2639 function Tag(token, remainTokens, liquid) {
2640 var _this = _super.call(this, token) || this;
2641 _this.name = token.name;
2642 _this.liquid = liquid;
2643 _this.tokenizer = token.tokenizer;
2644 return _this;
2645 }
2646 return Tag;
2647 }(TemplateImpl));
2648
2649 /**
2650 * Key-Value Pairs Representing Tag Arguments
2651 * Example:
2652 * For the markup `, foo:'bar', coo:2 reversed %}`,
2653 * hash['foo'] === 'bar'
2654 * hash['coo'] === 2
2655 * hash['reversed'] === undefined
2656 */
2657 var Hash = /** @class */ (function () {
2658 function Hash(markup, jekyllStyle) {
2659 var e_1, _a;
2660 this.hash = {};
2661 var tokenizer = new Tokenizer(markup, {});
2662 try {
2663 for (var _b = __values(tokenizer.readHashes(jekyllStyle)), _c = _b.next(); !_c.done; _c = _b.next()) {
2664 var hash = _c.value;
2665 this.hash[hash.name.content] = hash.value;
2666 }
2667 }
2668 catch (e_1_1) { e_1 = { error: e_1_1 }; }
2669 finally {
2670 try {
2671 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2672 }
2673 finally { if (e_1) throw e_1.error; }
2674 }
2675 }
2676 Hash.prototype.render = function (ctx) {
2677 var hash, _a, _b, key, _c, _d, _e, e_2_1;
2678 var e_2, _f;
2679 return __generator(this, function (_g) {
2680 switch (_g.label) {
2681 case 0:
2682 hash = {};
2683 _g.label = 1;
2684 case 1:
2685 _g.trys.push([1, 8, 9, 10]);
2686 _a = __values(Object.keys(this.hash)), _b = _a.next();
2687 _g.label = 2;
2688 case 2:
2689 if (!!_b.done) return [3 /*break*/, 7];
2690 key = _b.value;
2691 _c = hash;
2692 _d = key;
2693 if (!(this.hash[key] === undefined)) return [3 /*break*/, 3];
2694 _e = true;
2695 return [3 /*break*/, 5];
2696 case 3: return [4 /*yield*/, evalToken(this.hash[key], ctx)];
2697 case 4:
2698 _e = _g.sent();
2699 _g.label = 5;
2700 case 5:
2701 _c[_d] = _e;
2702 _g.label = 6;
2703 case 6:
2704 _b = _a.next();
2705 return [3 /*break*/, 2];
2706 case 7: return [3 /*break*/, 10];
2707 case 8:
2708 e_2_1 = _g.sent();
2709 e_2 = { error: e_2_1 };
2710 return [3 /*break*/, 10];
2711 case 9:
2712 try {
2713 if (_b && !_b.done && (_f = _a.return)) _f.call(_a);
2714 }
2715 finally { if (e_2) throw e_2.error; }
2716 return [7 /*endfinally*/];
2717 case 10: return [2 /*return*/, hash];
2718 }
2719 });
2720 };
2721 return Hash;
2722 }());
2723
2724 function createTagClass(options) {
2725 return /** @class */ (function (_super) {
2726 __extends(class_1, _super);
2727 function class_1(token, tokens, liquid) {
2728 var _this = _super.call(this, token, tokens, liquid) || this;
2729 if (isFunction(options.parse)) {
2730 options.parse.call(_this, token, tokens);
2731 }
2732 return _this;
2733 }
2734 class_1.prototype.render = function (ctx, emitter) {
2735 var hash;
2736 return __generator(this, function (_a) {
2737 switch (_a.label) {
2738 case 0: return [4 /*yield*/, new Hash(this.token.args).render(ctx)];
2739 case 1:
2740 hash = (_a.sent());
2741 return [4 /*yield*/, options.render.call(this, ctx, emitter, hash)];
2742 case 2: return [2 /*return*/, _a.sent()];
2743 }
2744 });
2745 };
2746 return class_1;
2747 }(Tag));
2748 }
2749
2750 function isKeyValuePair(arr) {
2751 return isArray(arr);
2752 }
2753
2754 var Filter = /** @class */ (function () {
2755 function Filter(name, options, args, liquid) {
2756 this.name = name;
2757 this.handler = isFunction(options)
2758 ? options
2759 : (isFunction(options === null || options === void 0 ? void 0 : options.handler) ? options.handler : identify);
2760 this.raw = !isFunction(options) && !!(options === null || options === void 0 ? void 0 : options.raw);
2761 this.args = args;
2762 this.liquid = liquid;
2763 }
2764 Filter.prototype.render = function (value, context) {
2765 var argv, _a, _b, arg, _c, _d, _e, _f, _g, e_1_1;
2766 var e_1, _h;
2767 return __generator(this, function (_j) {
2768 switch (_j.label) {
2769 case 0:
2770 argv = [];
2771 _j.label = 1;
2772 case 1:
2773 _j.trys.push([1, 8, 9, 10]);
2774 _a = __values(this.args), _b = _a.next();
2775 _j.label = 2;
2776 case 2:
2777 if (!!_b.done) return [3 /*break*/, 7];
2778 arg = _b.value;
2779 if (!isKeyValuePair(arg)) return [3 /*break*/, 4];
2780 _d = (_c = argv).push;
2781 _e = [arg[0]];
2782 return [4 /*yield*/, evalToken(arg[1], context)];
2783 case 3:
2784 _d.apply(_c, [_e.concat([_j.sent()])]);
2785 return [3 /*break*/, 6];
2786 case 4:
2787 _g = (_f = argv).push;
2788 return [4 /*yield*/, evalToken(arg, context)];
2789 case 5:
2790 _g.apply(_f, [_j.sent()]);
2791 _j.label = 6;
2792 case 6:
2793 _b = _a.next();
2794 return [3 /*break*/, 2];
2795 case 7: return [3 /*break*/, 10];
2796 case 8:
2797 e_1_1 = _j.sent();
2798 e_1 = { error: e_1_1 };
2799 return [3 /*break*/, 10];
2800 case 9:
2801 try {
2802 if (_b && !_b.done && (_h = _a.return)) _h.call(_a);
2803 }
2804 finally { if (e_1) throw e_1.error; }
2805 return [7 /*endfinally*/];
2806 case 10: return [4 /*yield*/, this.handler.apply({ context: context, liquid: this.liquid }, __spreadArray([value], __read(argv), false))];
2807 case 11: return [2 /*return*/, _j.sent()];
2808 }
2809 });
2810 };
2811 return Filter;
2812 }());
2813
2814 var Value = /** @class */ (function () {
2815 /**
2816 * @param str the value to be valuated, eg.: "foobar" | truncate: 3
2817 */
2818 function Value(input, liquid) {
2819 var _this = this;
2820 this.filters = [];
2821 var token = typeof input === 'string'
2822 ? new Tokenizer(input, liquid.options.operators).readFilteredValue()
2823 : input;
2824 this.initial = token.initial;
2825 this.filters = token.filters.map(function (_a) {
2826 var name = _a.name, args = _a.args;
2827 return new Filter(name, _this.getFilter(liquid, name), args, liquid);
2828 });
2829 }
2830 Value.prototype.value = function (ctx, lenient) {
2831 var val, _a, _b, filter, e_1_1;
2832 var e_1, _c;
2833 return __generator(this, function (_d) {
2834 switch (_d.label) {
2835 case 0:
2836 lenient = lenient || (ctx.opts.lenientIf && this.filters.length > 0 && this.filters[0].name === 'default');
2837 return [4 /*yield*/, this.initial.evaluate(ctx, lenient)];
2838 case 1:
2839 val = _d.sent();
2840 _d.label = 2;
2841 case 2:
2842 _d.trys.push([2, 7, 8, 9]);
2843 _a = __values(this.filters), _b = _a.next();
2844 _d.label = 3;
2845 case 3:
2846 if (!!_b.done) return [3 /*break*/, 6];
2847 filter = _b.value;
2848 return [4 /*yield*/, filter.render(val, ctx)];
2849 case 4:
2850 val = _d.sent();
2851 _d.label = 5;
2852 case 5:
2853 _b = _a.next();
2854 return [3 /*break*/, 3];
2855 case 6: return [3 /*break*/, 9];
2856 case 7:
2857 e_1_1 = _d.sent();
2858 e_1 = { error: e_1_1 };
2859 return [3 /*break*/, 9];
2860 case 8:
2861 try {
2862 if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2863 }
2864 finally { if (e_1) throw e_1.error; }
2865 return [7 /*endfinally*/];
2866 case 9: return [2 /*return*/, val];
2867 }
2868 });
2869 };
2870 Value.prototype.getFilter = function (liquid, name) {
2871 var impl = liquid.filters[name];
2872 assert(impl || !liquid.options.strictFilters, function () { return "undefined filter: ".concat(name); });
2873 return impl;
2874 };
2875 return Value;
2876 }());
2877
2878 var Output = /** @class */ (function (_super) {
2879 __extends(Output, _super);
2880 function Output(token, liquid) {
2881 var _this = this;
2882 var _a;
2883 _this = _super.call(this, token) || this;
2884 var tokenizer = new Tokenizer(token.input, liquid.options.operators, token.file, token.contentRange);
2885 _this.value = new Value(tokenizer.readFilteredValue(), liquid);
2886 var filters = _this.value.filters;
2887 var outputEscape = liquid.options.outputEscape;
2888 if (!((_a = filters[filters.length - 1]) === null || _a === void 0 ? void 0 : _a.raw) && outputEscape) {
2889 filters.push(new Filter(toString.call(outputEscape), outputEscape, [], liquid));
2890 }
2891 return _this;
2892 }
2893 Output.prototype.render = function (ctx, emitter) {
2894 var val;
2895 return __generator(this, function (_a) {
2896 switch (_a.label) {
2897 case 0: return [4 /*yield*/, this.value.value(ctx, false)];
2898 case 1:
2899 val = _a.sent();
2900 emitter.write(val);
2901 return [2 /*return*/];
2902 }
2903 });
2904 };
2905 return Output;
2906 }(TemplateImpl));
2907
2908 var HTML = /** @class */ (function (_super) {
2909 __extends(HTML, _super);
2910 function HTML(token) {
2911 var _this = _super.call(this, token) || this;
2912 _this.str = token.getContent();
2913 return _this;
2914 }
2915 HTML.prototype.render = function (ctx, emitter) {
2916 return __generator(this, function (_a) {
2917 emitter.write(this.str);
2918 return [2 /*return*/];
2919 });
2920 };
2921 return HTML;
2922 }(TemplateImpl));
2923
2924 var LookupType;
2925 (function (LookupType) {
2926 LookupType["Partials"] = "partials";
2927 LookupType["Layouts"] = "layouts";
2928 LookupType["Root"] = "root";
2929 })(LookupType || (LookupType = {}));
2930 var Loader = /** @class */ (function () {
2931 function Loader(options) {
2932 this.options = options;
2933 if (options.relativeReference) {
2934 var sep = options.fs.sep;
2935 assert(sep, '`fs.sep` is required for relative reference');
2936 var rRelativePath_1 = new RegExp(['.' + sep, '..' + sep, './', '../'].map(function (prefix) { return escapeRegex(prefix); }).join('|'));
2937 this.shouldLoadRelative = function (referencedFile) { return rRelativePath_1.test(referencedFile); };
2938 }
2939 else {
2940 this.shouldLoadRelative = function (referencedFile) { return false; };
2941 }
2942 this.contains = this.options.fs.contains || (function () { return true; });
2943 }
2944 Loader.prototype.lookup = function (file, type, sync, currentFile) {
2945 var fs, dirs, _a, _b, filepath, _c, e_1_1;
2946 var e_1, _d;
2947 return __generator(this, function (_e) {
2948 switch (_e.label) {
2949 case 0:
2950 fs = this.options.fs;
2951 dirs = this.options[type];
2952 _e.label = 1;
2953 case 1:
2954 _e.trys.push([1, 8, 9, 10]);
2955 _a = __values(this.candidates(file, dirs, currentFile, type !== LookupType.Root)), _b = _a.next();
2956 _e.label = 2;
2957 case 2:
2958 if (!!_b.done) return [3 /*break*/, 7];
2959 filepath = _b.value;
2960 if (!sync) return [3 /*break*/, 3];
2961 _c = fs.existsSync(filepath);
2962 return [3 /*break*/, 5];
2963 case 3: return [4 /*yield*/, fs.exists(filepath)];
2964 case 4:
2965 _c = _e.sent();
2966 _e.label = 5;
2967 case 5:
2968 if (_c)
2969 return [2 /*return*/, filepath];
2970 _e.label = 6;
2971 case 6:
2972 _b = _a.next();
2973 return [3 /*break*/, 2];
2974 case 7: return [3 /*break*/, 10];
2975 case 8:
2976 e_1_1 = _e.sent();
2977 e_1 = { error: e_1_1 };
2978 return [3 /*break*/, 10];
2979 case 9:
2980 try {
2981 if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
2982 }
2983 finally { if (e_1) throw e_1.error; }
2984 return [7 /*endfinally*/];
2985 case 10: throw this.lookupError(file, dirs);
2986 }
2987 });
2988 };
2989 Loader.prototype.candidates = function (file, dirs, currentFile, enforceRoot) {
2990 var _a, fs, extname, referenced, dirs_1, dirs_1_1, dir, e_2_1, dirs_2, dirs_2_1, dir, referenced, e_3_1, filepath;
2991 var e_2, _b, e_3, _c;
2992 return __generator(this, function (_d) {
2993 switch (_d.label) {
2994 case 0:
2995 _a = this.options, fs = _a.fs, extname = _a.extname;
2996 if (!(this.shouldLoadRelative(file) && currentFile)) return [3 /*break*/, 8];
2997 referenced = fs.resolve(this.dirname(currentFile), file, extname);
2998 _d.label = 1;
2999 case 1:
3000 _d.trys.push([1, 6, 7, 8]);
3001 dirs_1 = __values(dirs), dirs_1_1 = dirs_1.next();
3002 _d.label = 2;
3003 case 2:
3004 if (!!dirs_1_1.done) return [3 /*break*/, 5];
3005 dir = dirs_1_1.value;
3006 if (!(!enforceRoot || this.contains(dir, referenced))) return [3 /*break*/, 4];
3007 // the relatively referenced file is within one of root dirs
3008 return [4 /*yield*/, referenced];
3009 case 3:
3010 // the relatively referenced file is within one of root dirs
3011 _d.sent();
3012 return [3 /*break*/, 5];
3013 case 4:
3014 dirs_1_1 = dirs_1.next();
3015 return [3 /*break*/, 2];
3016 case 5: return [3 /*break*/, 8];
3017 case 6:
3018 e_2_1 = _d.sent();
3019 e_2 = { error: e_2_1 };
3020 return [3 /*break*/, 8];
3021 case 7:
3022 try {
3023 if (dirs_1_1 && !dirs_1_1.done && (_b = dirs_1.return)) _b.call(dirs_1);
3024 }
3025 finally { if (e_2) throw e_2.error; }
3026 return [7 /*endfinally*/];
3027 case 8:
3028 _d.trys.push([8, 13, 14, 15]);
3029 dirs_2 = __values(dirs), dirs_2_1 = dirs_2.next();
3030 _d.label = 9;
3031 case 9:
3032 if (!!dirs_2_1.done) return [3 /*break*/, 12];
3033 dir = dirs_2_1.value;
3034 referenced = fs.resolve(dir, file, extname);
3035 if (!(!enforceRoot || this.contains(dir, referenced))) return [3 /*break*/, 11];
3036 return [4 /*yield*/, referenced];
3037 case 10:
3038 _d.sent();
3039 _d.label = 11;
3040 case 11:
3041 dirs_2_1 = dirs_2.next();
3042 return [3 /*break*/, 9];
3043 case 12: return [3 /*break*/, 15];
3044 case 13:
3045 e_3_1 = _d.sent();
3046 e_3 = { error: e_3_1 };
3047 return [3 /*break*/, 15];
3048 case 14:
3049 try {
3050 if (dirs_2_1 && !dirs_2_1.done && (_c = dirs_2.return)) _c.call(dirs_2);
3051 }
3052 finally { if (e_3) throw e_3.error; }
3053 return [7 /*endfinally*/];
3054 case 15:
3055 if (!(fs.fallback !== undefined)) return [3 /*break*/, 17];
3056 filepath = fs.fallback(file);
3057 if (!(filepath !== undefined)) return [3 /*break*/, 17];
3058 return [4 /*yield*/, filepath];
3059 case 16:
3060 _d.sent();
3061 _d.label = 17;
3062 case 17: return [2 /*return*/];
3063 }
3064 });
3065 };
3066 Loader.prototype.dirname = function (path) {
3067 var fs = this.options.fs;
3068 assert(fs.dirname, '`fs.dirname` is required for relative reference');
3069 return fs.dirname(path);
3070 };
3071 Loader.prototype.lookupError = function (file, roots) {
3072 var err = new Error('ENOENT');
3073 err.message = "ENOENT: Failed to lookup \"".concat(file, "\" in \"").concat(roots, "\"");
3074 err.code = 'ENOENT';
3075 return err;
3076 };
3077 return Loader;
3078 }());
3079
3080 var Parser = /** @class */ (function () {
3081 function Parser(liquid) {
3082 this.liquid = liquid;
3083 this.cache = this.liquid.options.cache;
3084 this.fs = this.liquid.options.fs;
3085 this.parseFile = this.cache ? this._parseFileCached : this._parseFile;
3086 this.loader = new Loader(this.liquid.options);
3087 }
3088 Parser.prototype.parse = function (html, filepath) {
3089 var tokenizer = new Tokenizer(html, this.liquid.options.operators, filepath);
3090 var tokens = tokenizer.readTopLevelTokens(this.liquid.options);
3091 return this.parseTokens(tokens);
3092 };
3093 Parser.prototype.parseTokens = function (tokens) {
3094 var token;
3095 var templates = [];
3096 var errors = [];
3097 while ((token = tokens.shift())) {
3098 try {
3099 templates.push(this.parseToken(token, tokens));
3100 }
3101 catch (err) {
3102 if (this.liquid.options.catchAllErrors)
3103 errors.push(err);
3104 else
3105 throw err;
3106 }
3107 }
3108 if (errors.length)
3109 throw new LiquidErrors(errors);
3110 return templates;
3111 };
3112 Parser.prototype.parseToken = function (token, remainTokens) {
3113 try {
3114 if (isTagToken(token)) {
3115 var TagClass = this.liquid.tags[token.name];
3116 assert(TagClass, "tag \"".concat(token.name, "\" not found"));
3117 return new TagClass(token, remainTokens, this.liquid);
3118 }
3119 if (isOutputToken(token)) {
3120 return new Output(token, this.liquid);
3121 }
3122 return new HTML(token);
3123 }
3124 catch (e) {
3125 if (LiquidError.is(e))
3126 throw e;
3127 throw new ParseError(e, token);
3128 }
3129 };
3130 Parser.prototype.parseStream = function (tokens) {
3131 var _this = this;
3132 return new ParseStream(tokens, function (token, tokens) { return _this.parseToken(token, tokens); });
3133 };
3134 Parser.prototype._parseFileCached = function (file, sync, type, currentFile) {
3135 var cache, key, tpls, task, taskOrTpl, _a, err_1;
3136 if (type === void 0) { type = LookupType.Root; }
3137 return __generator(this, function (_b) {
3138 switch (_b.label) {
3139 case 0:
3140 cache = this.cache;
3141 key = this.loader.shouldLoadRelative(file) ? currentFile + ',' + file : type + ':' + file;
3142 return [4 /*yield*/, cache.read(key)];
3143 case 1:
3144 tpls = _b.sent();
3145 if (tpls)
3146 return [2 /*return*/, tpls];
3147 task = this._parseFile(file, sync, type, currentFile);
3148 if (!sync) return [3 /*break*/, 3];
3149 return [4 /*yield*/, task];
3150 case 2:
3151 _a = _b.sent();
3152 return [3 /*break*/, 4];
3153 case 3:
3154 _a = toPromise(task);
3155 _b.label = 4;
3156 case 4:
3157 taskOrTpl = _a;
3158 cache.write(key, taskOrTpl);
3159 _b.label = 5;
3160 case 5:
3161 _b.trys.push([5, 7, , 8]);
3162 return [4 /*yield*/, taskOrTpl];
3163 case 6: return [2 /*return*/, _b.sent()];
3164 case 7:
3165 err_1 = _b.sent();
3166 cache.remove(key);
3167 throw err_1;
3168 case 8: return [2 /*return*/];
3169 }
3170 });
3171 };
3172 Parser.prototype._parseFile = function (file, sync, type, currentFile) {
3173 var filepath, _a, _b, _c;
3174 if (type === void 0) { type = LookupType.Root; }
3175 return __generator(this, function (_d) {
3176 switch (_d.label) {
3177 case 0: return [4 /*yield*/, this.loader.lookup(file, type, sync, currentFile)];
3178 case 1:
3179 filepath = _d.sent();
3180 _b = (_a = this.liquid).parse;
3181 if (!sync) return [3 /*break*/, 2];
3182 _c = this.fs.readFileSync(filepath);
3183 return [3 /*break*/, 4];
3184 case 2: return [4 /*yield*/, this.fs.readFile(filepath)];
3185 case 3:
3186 _c = _d.sent();
3187 _d.label = 4;
3188 case 4: return [2 /*return*/, _b.apply(_a, [_c, filepath])];
3189 }
3190 });
3191 };
3192 return Parser;
3193 }());
3194
3195 (function (TokenKind) {
3196 TokenKind[TokenKind["Number"] = 1] = "Number";
3197 TokenKind[TokenKind["Literal"] = 2] = "Literal";
3198 TokenKind[TokenKind["Tag"] = 4] = "Tag";
3199 TokenKind[TokenKind["Output"] = 8] = "Output";
3200 TokenKind[TokenKind["HTML"] = 16] = "HTML";
3201 TokenKind[TokenKind["Filter"] = 32] = "Filter";
3202 TokenKind[TokenKind["Hash"] = 64] = "Hash";
3203 TokenKind[TokenKind["PropertyAccess"] = 128] = "PropertyAccess";
3204 TokenKind[TokenKind["Word"] = 256] = "Word";
3205 TokenKind[TokenKind["Range"] = 512] = "Range";
3206 TokenKind[TokenKind["Quoted"] = 1024] = "Quoted";
3207 TokenKind[TokenKind["Operator"] = 2048] = "Operator";
3208 TokenKind[TokenKind["FilteredValue"] = 4096] = "FilteredValue";
3209 TokenKind[TokenKind["Delimited"] = 12] = "Delimited";
3210 })(exports.TokenKind || (exports.TokenKind = {}));
3211
3212 function isDelimitedToken(val) {
3213 return !!(getKind(val) & exports.TokenKind.Delimited);
3214 }
3215 function isOperatorToken(val) {
3216 return getKind(val) === exports.TokenKind.Operator;
3217 }
3218 function isHTMLToken(val) {
3219 return getKind(val) === exports.TokenKind.HTML;
3220 }
3221 function isOutputToken(val) {
3222 return getKind(val) === exports.TokenKind.Output;
3223 }
3224 function isTagToken(val) {
3225 return getKind(val) === exports.TokenKind.Tag;
3226 }
3227 function isQuotedToken(val) {
3228 return getKind(val) === exports.TokenKind.Quoted;
3229 }
3230 function isLiteralToken(val) {
3231 return getKind(val) === exports.TokenKind.Literal;
3232 }
3233 function isNumberToken(val) {
3234 return getKind(val) === exports.TokenKind.Number;
3235 }
3236 function isPropertyAccessToken(val) {
3237 return getKind(val) === exports.TokenKind.PropertyAccess;
3238 }
3239 function isWordToken(val) {
3240 return getKind(val) === exports.TokenKind.Word;
3241 }
3242 function isRangeToken(val) {
3243 return getKind(val) === exports.TokenKind.Range;
3244 }
3245 function getKind(val) {
3246 return val ? val.kind : -1;
3247 }
3248
3249 var typeGuards = /*#__PURE__*/Object.freeze({
3250 __proto__: null,
3251 isDelimitedToken: isDelimitedToken,
3252 isOperatorToken: isOperatorToken,
3253 isHTMLToken: isHTMLToken,
3254 isOutputToken: isOutputToken,
3255 isTagToken: isTagToken,
3256 isQuotedToken: isQuotedToken,
3257 isLiteralToken: isLiteralToken,
3258 isNumberToken: isNumberToken,
3259 isPropertyAccessToken: isPropertyAccessToken,
3260 isWordToken: isWordToken,
3261 isRangeToken: isRangeToken
3262 });
3263
3264 var Context = /** @class */ (function () {
3265 function Context(env, opts, renderOptions) {
3266 if (env === void 0) { env = {}; }
3267 if (opts === void 0) { opts = defaultOptions; }
3268 if (renderOptions === void 0) { renderOptions = {}; }
3269 var _a, _b, _c;
3270 /**
3271 * insert a Context-level empty scope,
3272 * for tags like `{% capture %}` `{% assign %}` to operate
3273 */
3274 this.scopes = [{}];
3275 this.registers = {};
3276 this.sync = !!renderOptions.sync;
3277 this.opts = opts;
3278 this.globals = (_a = renderOptions.globals) !== null && _a !== void 0 ? _a : opts.globals;
3279 this.environments = isObject(env) ? env : Object(env);
3280 this.strictVariables = (_b = renderOptions.strictVariables) !== null && _b !== void 0 ? _b : this.opts.strictVariables;
3281 this.ownPropertyOnly = (_c = renderOptions.ownPropertyOnly) !== null && _c !== void 0 ? _c : opts.ownPropertyOnly;
3282 }
3283 Context.prototype.getRegister = function (key) {
3284 return (this.registers[key] = this.registers[key] || {});
3285 };
3286 Context.prototype.setRegister = function (key, value) {
3287 return (this.registers[key] = value);
3288 };
3289 Context.prototype.saveRegister = function () {
3290 var _this = this;
3291 var keys = [];
3292 for (var _i = 0; _i < arguments.length; _i++) {
3293 keys[_i] = arguments[_i];
3294 }
3295 return keys.map(function (key) { return [key, _this.getRegister(key)]; });
3296 };
3297 Context.prototype.restoreRegister = function (keyValues) {
3298 var _this = this;
3299 return keyValues.forEach(function (_a) {
3300 var _b = __read(_a, 2), key = _b[0], value = _b[1];
3301 return _this.setRegister(key, value);
3302 });
3303 };
3304 Context.prototype.getAll = function () {
3305 return __spreadArray([this.globals, this.environments], __read(this.scopes), false).reduce(function (ctx, val) { return __assign(ctx, val); }, {});
3306 };
3307 /**
3308 * @deprecated use `_get()` or `getSync()` instead
3309 */
3310 Context.prototype.get = function (paths) {
3311 return this.getSync(paths);
3312 };
3313 Context.prototype.getSync = function (paths) {
3314 return toValueSync(this._get(paths));
3315 };
3316 Context.prototype._get = function (paths) {
3317 var scope;
3318 return __generator(this, function (_a) {
3319 switch (_a.label) {
3320 case 0:
3321 scope = this.findScope(paths[0]);
3322 return [4 /*yield*/, this._getFromScope(scope, paths)];
3323 case 1: return [2 /*return*/, _a.sent()];
3324 }
3325 });
3326 };
3327 /**
3328 * @deprecated use `_get()` instead
3329 */
3330 Context.prototype.getFromScope = function (scope, paths) {
3331 return toValueSync(this._getFromScope(scope, paths));
3332 };
3333 Context.prototype._getFromScope = function (scope, paths, strictVariables) {
3334 var i;
3335 if (strictVariables === void 0) { strictVariables = this.strictVariables; }
3336 return __generator(this, function (_a) {
3337 switch (_a.label) {
3338 case 0:
3339 if (isString(paths))
3340 paths = paths.split('.');
3341 i = 0;
3342 _a.label = 1;
3343 case 1:
3344 if (!(i < paths.length)) return [3 /*break*/, 4];
3345 return [4 /*yield*/, readProperty(scope, paths[i], this.ownPropertyOnly)];
3346 case 2:
3347 scope = _a.sent();
3348 if (strictVariables && isUndefined(scope)) {
3349 throw new InternalUndefinedVariableError(paths.slice(0, i + 1).join('.'));
3350 }
3351 _a.label = 3;
3352 case 3:
3353 i++;
3354 return [3 /*break*/, 1];
3355 case 4: return [2 /*return*/, scope];
3356 }
3357 });
3358 };
3359 Context.prototype.push = function (ctx) {
3360 return this.scopes.push(ctx);
3361 };
3362 Context.prototype.pop = function () {
3363 return this.scopes.pop();
3364 };
3365 Context.prototype.bottom = function () {
3366 return this.scopes[0];
3367 };
3368 Context.prototype.findScope = function (key) {
3369 for (var i = this.scopes.length - 1; i >= 0; i--) {
3370 var candidate = this.scopes[i];
3371 if (key in candidate)
3372 return candidate;
3373 }
3374 if (key in this.environments)
3375 return this.environments;
3376 return this.globals;
3377 };
3378 return Context;
3379 }());
3380 function readProperty(obj, key, ownPropertyOnly) {
3381 obj = toLiquid(obj);
3382 if (isNil(obj))
3383 return obj;
3384 if (isArray(obj) && key < 0)
3385 return obj[obj.length + +key];
3386 var value = readJSProperty(obj, key, ownPropertyOnly);
3387 if (value === undefined && obj instanceof Drop)
3388 return obj.liquidMethodMissing(key);
3389 if (isFunction(value))
3390 return value.call(obj);
3391 if (key === 'size')
3392 return readSize(obj);
3393 else if (key === 'first')
3394 return readFirst(obj);
3395 else if (key === 'last')
3396 return readLast(obj);
3397 return value;
3398 }
3399 function readJSProperty(obj, key, ownPropertyOnly) {
3400 if (ownPropertyOnly && !Object.hasOwnProperty.call(obj, key) && !(obj instanceof Drop))
3401 return undefined;
3402 return obj[key];
3403 }
3404 function readFirst(obj) {
3405 if (isArray(obj))
3406 return obj[0];
3407 return obj['first'];
3408 }
3409 function readLast(obj) {
3410 if (isArray(obj))
3411 return obj[obj.length - 1];
3412 return obj['last'];
3413 }
3414 function readSize(obj) {
3415 if (obj.hasOwnProperty('size') || obj['size'] !== undefined)
3416 return obj['size'];
3417 if (isArray(obj) || isString(obj))
3418 return obj.length;
3419 if (typeof obj === 'object')
3420 return Object.keys(obj).length;
3421 }
3422
3423 var BlockMode;
3424 (function (BlockMode) {
3425 /* store rendered html into blocks */
3426 BlockMode[BlockMode["OUTPUT"] = 0] = "OUTPUT";
3427 /* output rendered html directly */
3428 BlockMode[BlockMode["STORE"] = 1] = "STORE";
3429 })(BlockMode || (BlockMode = {}));
3430
3431 var abs = argumentsToValue(Math.abs);
3432 var at_least = argumentsToValue(Math.max);
3433 var at_most = argumentsToValue(Math.min);
3434 var ceil = argumentsToValue(Math.ceil);
3435 var divided_by = argumentsToValue(function (dividend, divisor, integerArithmetic) {
3436 if (integerArithmetic === void 0) { integerArithmetic = false; }
3437 return integerArithmetic ? Math.floor(dividend / divisor) : dividend / divisor;
3438 });
3439 var floor = argumentsToValue(Math.floor);
3440 var minus = argumentsToValue(function (v, arg) { return v - arg; });
3441 var modulo = argumentsToValue(function (v, arg) { return v % arg; });
3442 var times = argumentsToValue(function (v, arg) { return v * arg; });
3443 function round(v, arg) {
3444 if (arg === void 0) { arg = 0; }
3445 v = toValue(v);
3446 arg = toValue(arg);
3447 var amp = Math.pow(10, arg);
3448 return Math.round(v * amp) / amp;
3449 }
3450 function plus(v, arg) {
3451 v = toValue(v);
3452 arg = toValue(arg);
3453 return Number(v) + Number(arg);
3454 }
3455
3456 var mathFilters = /*#__PURE__*/Object.freeze({
3457 __proto__: null,
3458 abs: abs,
3459 at_least: at_least,
3460 at_most: at_most,
3461 ceil: ceil,
3462 divided_by: divided_by,
3463 floor: floor,
3464 minus: minus,
3465 modulo: modulo,
3466 times: times,
3467 round: round,
3468 plus: plus
3469 });
3470
3471 var url_decode = function (x) { return decodeURIComponent(stringify(x)).replace(/\+/g, ' '); };
3472 var url_encode = function (x) { return encodeURIComponent(stringify(x)).replace(/%20/g, '+'); };
3473 var cgi_escape = function (x) { return encodeURIComponent(stringify(x))
3474 .replace(/%20/g, '+')
3475 .replace(/[!'()*]/g, function (c) { return '%' + c.charCodeAt(0).toString(16).toUpperCase(); }); };
3476 var uri_escape = function (x) { return encodeURI(stringify(x))
3477 .replace(/%5B/g, '[')
3478 .replace(/%5D/g, ']'); };
3479 var rSlugifyDefault = /[^\p{M}\p{L}\p{Nd}]+/ug;
3480 var rSlugifyReplacers = {
3481 'raw': /\s+/g,
3482 'default': rSlugifyDefault,
3483 'pretty': /[^\p{M}\p{L}\p{Nd}._~!$&'()+,;=@]+/ug,
3484 'ascii': /[^A-Za-z0-9]+/g,
3485 'latin': rSlugifyDefault,
3486 'none': null
3487 };
3488 function slugify(str, mode, cased) {
3489 if (mode === void 0) { mode = 'default'; }
3490 if (cased === void 0) { cased = false; }
3491 str = stringify(str);
3492 var replacer = rSlugifyReplacers[mode];
3493 if (replacer) {
3494 if (mode === 'latin')
3495 str = removeAccents(str);
3496 str = str.replace(replacer, '-').replace(/^-|-$/g, '');
3497 }
3498 return cased ? str : str.toLowerCase();
3499 }
3500 function removeAccents(str) {
3501 return str.replace(/[àáâãäå]/g, 'a')
3502 .replace(/[æ]/g, 'ae')
3503 .replace(/[ç]/g, 'c')
3504 .replace(/[èéêë]/g, 'e')
3505 .replace(/[ìíîï]/g, 'i')
3506 .replace(/[ð]/g, 'd')
3507 .replace(/[ñ]/g, 'n')
3508 .replace(/[òóôõöø]/g, 'o')
3509 .replace(/[ùúûü]/g, 'u')
3510 .replace(/[ýÿ]/g, 'y')
3511 .replace(/[ß]/g, 'ss')
3512 .replace(/[œ]/g, 'oe')
3513 .replace(/[þ]/g, 'th')
3514 .replace(/[ẞ]/g, 'SS')
3515 .replace(/[Œ]/g, 'OE')
3516 .replace(/[Þ]/g, 'TH');
3517 }
3518
3519 var urlFilters = /*#__PURE__*/Object.freeze({
3520 __proto__: null,
3521 url_decode: url_decode,
3522 url_encode: url_encode,
3523 cgi_escape: cgi_escape,
3524 uri_escape: uri_escape,
3525 slugify: slugify
3526 });
3527
3528 var join = argumentsToValue(function (v, arg) { return toArray(v).join(arg === undefined ? ' ' : arg); });
3529 var last$1 = argumentsToValue(function (v) { return isArray(v) ? last(v) : ''; });
3530 var first = argumentsToValue(function (v) { return isArray(v) ? v[0] : ''; });
3531 var reverse = argumentsToValue(function (v) { return __spreadArray([], __read(toArray(v)), false).reverse(); });
3532 function sort(arr, property) {
3533 var values, _a, _b, item, _c, _d, _e, _f, e_1_1;
3534 var e_1, _g;
3535 return __generator(this, function (_h) {
3536 switch (_h.label) {
3537 case 0:
3538 values = [];
3539 _h.label = 1;
3540 case 1:
3541 _h.trys.push([1, 8, 9, 10]);
3542 _a = __values(toArray(arr)), _b = _a.next();
3543 _h.label = 2;
3544 case 2:
3545 if (!!_b.done) return [3 /*break*/, 7];
3546 item = _b.value;
3547 _d = (_c = values).push;
3548 _e = [item];
3549 if (!property) return [3 /*break*/, 4];
3550 return [4 /*yield*/, this.context._getFromScope(item, stringify(property).split('.'), false)];
3551 case 3:
3552 _f = _h.sent();
3553 return [3 /*break*/, 5];
3554 case 4:
3555 _f = item;
3556 _h.label = 5;
3557 case 5:
3558 _d.apply(_c, [_e.concat([
3559 _f
3560 ])]);
3561 _h.label = 6;
3562 case 6:
3563 _b = _a.next();
3564 return [3 /*break*/, 2];
3565 case 7: return [3 /*break*/, 10];
3566 case 8:
3567 e_1_1 = _h.sent();
3568 e_1 = { error: e_1_1 };
3569 return [3 /*break*/, 10];
3570 case 9:
3571 try {
3572 if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
3573 }
3574 finally { if (e_1) throw e_1.error; }
3575 return [7 /*endfinally*/];
3576 case 10: return [2 /*return*/, values.sort(function (lhs, rhs) {
3577 var lvalue = lhs[1];
3578 var rvalue = rhs[1];
3579 return lvalue < rvalue ? -1 : (lvalue > rvalue ? 1 : 0);
3580 }).map(function (tuple) { return tuple[0]; })];
3581 }
3582 });
3583 }
3584 function sort_natural(input, property) {
3585 var propertyString = stringify(property);
3586 var compare = property === undefined
3587 ? caseInsensitiveCompare
3588 : function (lhs, rhs) { return caseInsensitiveCompare(lhs[propertyString], rhs[propertyString]); };
3589 return __spreadArray([], __read(toArray(input)), false).sort(compare);
3590 }
3591 var size = function (v) { return (v && v.length) || 0; };
3592 function map(arr, property) {
3593 var results, _a, _b, item, _c, _d, e_2_1;
3594 var e_2, _e;
3595 return __generator(this, function (_f) {
3596 switch (_f.label) {
3597 case 0:
3598 results = [];
3599 _f.label = 1;
3600 case 1:
3601 _f.trys.push([1, 6, 7, 8]);
3602 _a = __values(toArray(arr)), _b = _a.next();
3603 _f.label = 2;
3604 case 2:
3605 if (!!_b.done) return [3 /*break*/, 5];
3606 item = _b.value;
3607 _d = (_c = results).push;
3608 return [4 /*yield*/, this.context._getFromScope(item, stringify(property), false)];
3609 case 3:
3610 _d.apply(_c, [_f.sent()]);
3611 _f.label = 4;
3612 case 4:
3613 _b = _a.next();
3614 return [3 /*break*/, 2];
3615 case 5: return [3 /*break*/, 8];
3616 case 6:
3617 e_2_1 = _f.sent();
3618 e_2 = { error: e_2_1 };
3619 return [3 /*break*/, 8];
3620 case 7:
3621 try {
3622 if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
3623 }
3624 finally { if (e_2) throw e_2.error; }
3625 return [7 /*endfinally*/];
3626 case 8: return [2 /*return*/, results];
3627 }
3628 });
3629 }
3630 function sum(arr, property) {
3631 var sum, _a, _b, item, data, _c, _d, e_3_1;
3632 var e_3, _e;
3633 return __generator(this, function (_f) {
3634 switch (_f.label) {
3635 case 0:
3636 sum = 0;
3637 _f.label = 1;
3638 case 1:
3639 _f.trys.push([1, 8, 9, 10]);
3640 _a = __values(toArray(arr)), _b = _a.next();
3641 _f.label = 2;
3642 case 2:
3643 if (!!_b.done) return [3 /*break*/, 7];
3644 item = _b.value;
3645 _c = Number;
3646 if (!property) return [3 /*break*/, 4];
3647 return [4 /*yield*/, this.context._getFromScope(item, stringify(property), false)];
3648 case 3:
3649 _d = _f.sent();
3650 return [3 /*break*/, 5];
3651 case 4:
3652 _d = item;
3653 _f.label = 5;
3654 case 5:
3655 data = _c.apply(void 0, [_d]);
3656 sum += Number.isNaN(data) ? 0 : data;
3657 _f.label = 6;
3658 case 6:
3659 _b = _a.next();
3660 return [3 /*break*/, 2];
3661 case 7: return [3 /*break*/, 10];
3662 case 8:
3663 e_3_1 = _f.sent();
3664 e_3 = { error: e_3_1 };
3665 return [3 /*break*/, 10];
3666 case 9:
3667 try {
3668 if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
3669 }
3670 finally { if (e_3) throw e_3.error; }
3671 return [7 /*endfinally*/];
3672 case 10: return [2 /*return*/, sum];
3673 }
3674 });
3675 }
3676 function compact(arr) {
3677 return toArray(arr).filter(function (x) { return !isNil(toValue(x)); });
3678 }
3679 function concat(v, arg) {
3680 if (arg === void 0) { arg = []; }
3681 return toArray(v).concat(toArray(arg));
3682 }
3683 function push(v, arg) {
3684 return concat(v, [arg]);
3685 }
3686 function unshift(v, arg) {
3687 var clone = __spreadArray([], __read(toArray(v)), false);
3688 clone.unshift(arg);
3689 return clone;
3690 }
3691 function pop(v) {
3692 var clone = __spreadArray([], __read(toArray(v)), false);
3693 clone.pop();
3694 return clone;
3695 }
3696 function shift(v) {
3697 var clone = __spreadArray([], __read(toArray(v)), false);
3698 clone.shift();
3699 return clone;
3700 }
3701 function slice(v, begin, length) {
3702 if (length === void 0) { length = 1; }
3703 v = toValue(v);
3704 if (isNil(v))
3705 return [];
3706 if (!isArray(v))
3707 v = stringify(v);
3708 begin = begin < 0 ? v.length + begin : begin;
3709 return v.slice(begin, begin + length);
3710 }
3711 function where(arr, property, expected) {
3712 var values, token, arr_1, arr_1_1, item, _a, _b, e_4_1;
3713 var e_4, _c;
3714 var _this = this;
3715 return __generator(this, function (_d) {
3716 switch (_d.label) {
3717 case 0:
3718 values = [];
3719 arr = toArray(arr);
3720 token = new Tokenizer(stringify(property)).readScopeValue();
3721 _d.label = 1;
3722 case 1:
3723 _d.trys.push([1, 6, 7, 8]);
3724 arr_1 = __values(arr), arr_1_1 = arr_1.next();
3725 _d.label = 2;
3726 case 2:
3727 if (!!arr_1_1.done) return [3 /*break*/, 5];
3728 item = arr_1_1.value;
3729 _b = (_a = values).push;
3730 return [4 /*yield*/, evalToken(token, new Context(item))];
3731 case 3:
3732 _b.apply(_a, [_d.sent()]);
3733 _d.label = 4;
3734 case 4:
3735 arr_1_1 = arr_1.next();
3736 return [3 /*break*/, 2];
3737 case 5: return [3 /*break*/, 8];
3738 case 6:
3739 e_4_1 = _d.sent();
3740 e_4 = { error: e_4_1 };
3741 return [3 /*break*/, 8];
3742 case 7:
3743 try {
3744 if (arr_1_1 && !arr_1_1.done && (_c = arr_1.return)) _c.call(arr_1);
3745 }
3746 finally { if (e_4) throw e_4.error; }
3747 return [7 /*endfinally*/];
3748 case 8: return [2 /*return*/, arr.filter(function (_, i) {
3749 if (expected === undefined)
3750 return isTruthy(values[i], _this.context);
3751 return equals(values[i], expected);
3752 })];
3753 }
3754 });
3755 }
3756 function where_exp(arr, itemName, exp) {
3757 var filtered, keyTemplate, _a, _b, item, value, e_5_1;
3758 var e_5, _c, _d;
3759 return __generator(this, function (_e) {
3760 switch (_e.label) {
3761 case 0:
3762 filtered = [];
3763 keyTemplate = new Value(stringify(exp), this.liquid);
3764 _e.label = 1;
3765 case 1:
3766 _e.trys.push([1, 6, 7, 8]);
3767 _a = __values(toArray(arr)), _b = _a.next();
3768 _e.label = 2;
3769 case 2:
3770 if (!!_b.done) return [3 /*break*/, 5];
3771 item = _b.value;
3772 return [4 /*yield*/, keyTemplate.value(new Context((_d = {}, _d[itemName] = item, _d)))];
3773 case 3:
3774 value = _e.sent();
3775 if (value)
3776 filtered.push(item);
3777 _e.label = 4;
3778 case 4:
3779 _b = _a.next();
3780 return [3 /*break*/, 2];
3781 case 5: return [3 /*break*/, 8];
3782 case 6:
3783 e_5_1 = _e.sent();
3784 e_5 = { error: e_5_1 };
3785 return [3 /*break*/, 8];
3786 case 7:
3787 try {
3788 if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
3789 }
3790 finally { if (e_5) throw e_5.error; }
3791 return [7 /*endfinally*/];
3792 case 8: return [2 /*return*/, filtered];
3793 }
3794 });
3795 }
3796 function group_by(arr, property) {
3797 var map, token, arr_2, arr_2_1, item, key, e_6_1;
3798 var e_6, _a;
3799 return __generator(this, function (_b) {
3800 switch (_b.label) {
3801 case 0:
3802 map = new Map();
3803 arr = toArray(arr);
3804 token = new Tokenizer(stringify(property)).readScopeValue();
3805 _b.label = 1;
3806 case 1:
3807 _b.trys.push([1, 6, 7, 8]);
3808 arr_2 = __values(arr), arr_2_1 = arr_2.next();
3809 _b.label = 2;
3810 case 2:
3811 if (!!arr_2_1.done) return [3 /*break*/, 5];
3812 item = arr_2_1.value;
3813 return [4 /*yield*/, evalToken(token, new Context(item))];
3814 case 3:
3815 key = _b.sent();
3816 if (!map.has(key))
3817 map.set(key, []);
3818 map.get(key).push(item);
3819 _b.label = 4;
3820 case 4:
3821 arr_2_1 = arr_2.next();
3822 return [3 /*break*/, 2];
3823 case 5: return [3 /*break*/, 8];
3824 case 6:
3825 e_6_1 = _b.sent();
3826 e_6 = { error: e_6_1 };
3827 return [3 /*break*/, 8];
3828 case 7:
3829 try {
3830 if (arr_2_1 && !arr_2_1.done && (_a = arr_2.return)) _a.call(arr_2);
3831 }
3832 finally { if (e_6) throw e_6.error; }
3833 return [7 /*endfinally*/];
3834 case 8: return [2 /*return*/, __spreadArray([], __read(map.entries()), false).map(function (_a) {
3835 var _b = __read(_a, 2), name = _b[0], items = _b[1];
3836 return ({ name: name, items: items });
3837 })];
3838 }
3839 });
3840 }
3841 function group_by_exp(arr, itemName, exp) {
3842 var map, keyTemplate, _a, _b, item, key, e_7_1;
3843 var e_7, _c, _d;
3844 return __generator(this, function (_e) {
3845 switch (_e.label) {
3846 case 0:
3847 map = new Map();
3848 keyTemplate = new Value(stringify(exp), this.liquid);
3849 _e.label = 1;
3850 case 1:
3851 _e.trys.push([1, 6, 7, 8]);
3852 _a = __values(toArray(arr)), _b = _a.next();
3853 _e.label = 2;
3854 case 2:
3855 if (!!_b.done) return [3 /*break*/, 5];
3856 item = _b.value;
3857 return [4 /*yield*/, keyTemplate.value(new Context((_d = {}, _d[itemName] = item, _d)))];
3858 case 3:
3859 key = _e.sent();
3860 if (!map.has(key))
3861 map.set(key, []);
3862 map.get(key).push(item);
3863 _e.label = 4;
3864 case 4:
3865 _b = _a.next();
3866 return [3 /*break*/, 2];
3867 case 5: return [3 /*break*/, 8];
3868 case 6:
3869 e_7_1 = _e.sent();
3870 e_7 = { error: e_7_1 };
3871 return [3 /*break*/, 8];
3872 case 7:
3873 try {
3874 if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
3875 }
3876 finally { if (e_7) throw e_7.error; }
3877 return [7 /*endfinally*/];
3878 case 8: return [2 /*return*/, __spreadArray([], __read(map.entries()), false).map(function (_a) {
3879 var _b = __read(_a, 2), name = _b[0], items = _b[1];
3880 return ({ name: name, items: items });
3881 })];
3882 }
3883 });
3884 }
3885 function find(arr, property, expected) {
3886 var token, _a, _b, item, value, e_8_1;
3887 var e_8, _c;
3888 return __generator(this, function (_d) {
3889 switch (_d.label) {
3890 case 0:
3891 token = new Tokenizer(stringify(property)).readScopeValue();
3892 _d.label = 1;
3893 case 1:
3894 _d.trys.push([1, 6, 7, 8]);
3895 _a = __values(toArray(arr)), _b = _a.next();
3896 _d.label = 2;
3897 case 2:
3898 if (!!_b.done) return [3 /*break*/, 5];
3899 item = _b.value;
3900 return [4 /*yield*/, evalToken(token, new Context(item))];
3901 case 3:
3902 value = _d.sent();
3903 if (equals(value, expected))
3904 return [2 /*return*/, item];
3905 _d.label = 4;
3906 case 4:
3907 _b = _a.next();
3908 return [3 /*break*/, 2];
3909 case 5: return [3 /*break*/, 8];
3910 case 6:
3911 e_8_1 = _d.sent();
3912 e_8 = { error: e_8_1 };
3913 return [3 /*break*/, 8];
3914 case 7:
3915 try {
3916 if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
3917 }
3918 finally { if (e_8) throw e_8.error; }
3919 return [7 /*endfinally*/];
3920 case 8: return [2 /*return*/, null];
3921 }
3922 });
3923 }
3924 function find_exp(arr, itemName, exp) {
3925 var predicate, _a, _b, item, value, e_9_1;
3926 var e_9, _c, _d;
3927 return __generator(this, function (_e) {
3928 switch (_e.label) {
3929 case 0:
3930 predicate = new Value(stringify(exp), this.liquid);
3931 _e.label = 1;
3932 case 1:
3933 _e.trys.push([1, 6, 7, 8]);
3934 _a = __values(toArray(arr)), _b = _a.next();
3935 _e.label = 2;
3936 case 2:
3937 if (!!_b.done) return [3 /*break*/, 5];
3938 item = _b.value;
3939 return [4 /*yield*/, predicate.value(new Context((_d = {}, _d[itemName] = item, _d)))];
3940 case 3:
3941 value = _e.sent();
3942 if (value)
3943 return [2 /*return*/, item];
3944 _e.label = 4;
3945 case 4:
3946 _b = _a.next();
3947 return [3 /*break*/, 2];
3948 case 5: return [3 /*break*/, 8];
3949 case 6:
3950 e_9_1 = _e.sent();
3951 e_9 = { error: e_9_1 };
3952 return [3 /*break*/, 8];
3953 case 7:
3954 try {
3955 if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
3956 }
3957 finally { if (e_9) throw e_9.error; }
3958 return [7 /*endfinally*/];
3959 case 8: return [2 /*return*/, null];
3960 }
3961 });
3962 }
3963 function uniq(arr) {
3964 arr = toValue(arr);
3965 var u = {};
3966 return (arr || []).filter(function (val) {
3967 if (hasOwnProperty.call(u, String(val)))
3968 return false;
3969 u[String(val)] = true;
3970 return true;
3971 });
3972 }
3973 function sample(v, count) {
3974 if (count === void 0) { count = 1; }
3975 v = toValue(v);
3976 if (isNil(v))
3977 return [];
3978 if (!isArray(v))
3979 v = stringify(v);
3980 var shuffled = __spreadArray([], __read(v), false).sort(function () { return Math.random() - 0.5; });
3981 if (count === 1)
3982 return shuffled[0];
3983 return shuffled.slice(0, count);
3984 }
3985
3986 var arrayFilters = /*#__PURE__*/Object.freeze({
3987 __proto__: null,
3988 join: join,
3989 last: last$1,
3990 first: first,
3991 reverse: reverse,
3992 sort: sort,
3993 sort_natural: sort_natural,
3994 size: size,
3995 map: map,
3996 sum: sum,
3997 compact: compact,
3998 concat: concat,
3999 push: push,
4000 unshift: unshift,
4001 pop: pop,
4002 shift: shift,
4003 slice: slice,
4004 where: where,
4005 where_exp: where_exp,
4006 group_by: group_by,
4007 group_by_exp: group_by_exp,
4008 find: find,
4009 find_exp: find_exp,
4010 uniq: uniq,
4011 sample: sample
4012 });
4013
4014 function date(v, format, timezoneOffset) {
4015 var date = parseDate(v, this.context.opts, timezoneOffset);
4016 if (!date)
4017 return v;
4018 format = toValue(format);
4019 format = isNil(format) ? this.context.opts.dateFormat : stringify(format);
4020 return strftime(date, format);
4021 }
4022 function date_to_xmlschema(v) {
4023 return date.call(this, v, '%Y-%m-%dT%H:%M:%S%:z');
4024 }
4025 function date_to_rfc822(v) {
4026 return date.call(this, v, '%a, %d %b %Y %H:%M:%S %z');
4027 }
4028 function date_to_string(v, type, style) {
4029 return stringify_date.call(this, v, '%b', type, style);
4030 }
4031 function date_to_long_string(v, type, style) {
4032 return stringify_date.call(this, v, '%B', type, style);
4033 }
4034 function stringify_date(v, month_type, type, style) {
4035 var date = parseDate(v, this.context.opts);
4036 if (!date)
4037 return v;
4038 if (type === 'ordinal') {
4039 var d = date.getDate();
4040 return style === 'US'
4041 ? strftime(date, "".concat(month_type, " ").concat(d, "%q, %Y"))
4042 : strftime(date, "".concat(d, "%q ").concat(month_type, " %Y"));
4043 }
4044 return strftime(date, "%d ".concat(month_type, " %Y"));
4045 }
4046 function parseDate(v, opts, timezoneOffset) {
4047 var date;
4048 v = toValue(v);
4049 if (v === 'now' || v === 'today') {
4050 date = new Date();
4051 }
4052 else if (isNumber(v)) {
4053 date = new Date(v * 1000);
4054 }
4055 else if (isString(v)) {
4056 if (/^\d+$/.test(v)) {
4057 date = new Date(+v * 1000);
4058 }
4059 else if (opts.preserveTimezones) {
4060 date = TimezoneDate.createDateFixedToTimezone(v);
4061 }
4062 else {
4063 date = new Date(v);
4064 }
4065 }
4066 else {
4067 date = v;
4068 }
4069 if (!isValidDate(date))
4070 return;
4071 if (timezoneOffset !== undefined) {
4072 date = new TimezoneDate(date, timezoneOffset);
4073 }
4074 else if (!(date instanceof TimezoneDate) && opts.timezoneOffset !== undefined) {
4075 date = new TimezoneDate(date, opts.timezoneOffset);
4076 }
4077 return date;
4078 }
4079 function isValidDate(date) {
4080 return (date instanceof Date || date instanceof TimezoneDate) && !isNaN(date.getTime());
4081 }
4082
4083 var dateFilters = /*#__PURE__*/Object.freeze({
4084 __proto__: null,
4085 date: date,
4086 date_to_xmlschema: date_to_xmlschema,
4087 date_to_rfc822: date_to_rfc822,
4088 date_to_string: date_to_string,
4089 date_to_long_string: date_to_long_string
4090 });
4091
4092 /**
4093 * String related filters
4094 *
4095 * * prefer stringify() to String() since `undefined`, `null` should eval ''
4096 */
4097 var rCJKWord = /[\u4E00-\u9FFF\uF900-\uFAFF\u3400-\u4DBF\u3040-\u309F\u30A0-\u30FF\uAC00-\uD7AF]/gu;
4098 // Word boundary followed by word characters (for detecting words)
4099 var rNonCJKWord = /[^\u4E00-\u9FFF\uF900-\uFAFF\u3400-\u4DBF\u3040-\u309F\u30A0-\u30FF\uAC00-\uD7AF\s]+/gu;
4100 function append(v, arg) {
4101 assert(arguments.length === 2, 'append expect 2 arguments');
4102 return stringify(v) + stringify(arg);
4103 }
4104 function prepend(v, arg) {
4105 assert(arguments.length === 2, 'prepend expect 2 arguments');
4106 return stringify(arg) + stringify(v);
4107 }
4108 function lstrip(v, chars) {
4109 if (chars) {
4110 chars = escapeRegExp(stringify(chars));
4111 return stringify(v).replace(new RegExp("^[".concat(chars, "]+"), 'g'), '');
4112 }
4113 return stringify(v).replace(/^\s+/, '');
4114 }
4115 function downcase(v) {
4116 return stringify(v).toLowerCase();
4117 }
4118 function upcase(str) {
4119 return stringify(str).toUpperCase();
4120 }
4121 function remove(v, arg) {
4122 return stringify(v).split(stringify(arg)).join('');
4123 }
4124 function remove_first(v, l) {
4125 return stringify(v).replace(stringify(l), '');
4126 }
4127 function remove_last(v, l) {
4128 var str = stringify(v);
4129 var pattern = stringify(l);
4130 var index = str.lastIndexOf(pattern);
4131 if (index === -1)
4132 return str;
4133 return str.substring(0, index) + str.substring(index + pattern.length);
4134 }
4135 function rstrip(str, chars) {
4136 if (chars) {
4137 chars = escapeRegExp(stringify(chars));
4138 return stringify(str).replace(new RegExp("[".concat(chars, "]+$"), 'g'), '');
4139 }
4140 return stringify(str).replace(/\s+$/, '');
4141 }
4142 function split(v, arg) {
4143 var arr = stringify(v).split(stringify(arg));
4144 // align to ruby split, which is the behavior of shopify/liquid
4145 // see: https://ruby-doc.org/core-2.4.0/String.html#method-i-split
4146 while (arr.length && arr[arr.length - 1] === '')
4147 arr.pop();
4148 return arr;
4149 }
4150 function strip(v, chars) {
4151 if (chars) {
4152 chars = escapeRegExp(stringify(chars));
4153 return stringify(v)
4154 .replace(new RegExp("^[".concat(chars, "]+"), 'g'), '')
4155 .replace(new RegExp("[".concat(chars, "]+$"), 'g'), '');
4156 }
4157 return stringify(v).trim();
4158 }
4159 function strip_newlines(v) {
4160 return stringify(v).replace(/\r?\n/gm, '');
4161 }
4162 function capitalize(str) {
4163 str = stringify(str);
4164 return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
4165 }
4166 function replace(v, pattern, replacement) {
4167 return stringify(v).split(stringify(pattern)).join(replacement);
4168 }
4169 function replace_first(v, arg1, arg2) {
4170 return stringify(v).replace(stringify(arg1), arg2);
4171 }
4172 function replace_last(v, arg1, arg2) {
4173 var str = stringify(v);
4174 var pattern = stringify(arg1);
4175 var index = str.lastIndexOf(pattern);
4176 if (index === -1)
4177 return str;
4178 var replacement = stringify(arg2);
4179 return str.substring(0, index) + replacement + str.substring(index + pattern.length);
4180 }
4181 function truncate(v, l, o) {
4182 if (l === void 0) { l = 50; }
4183 if (o === void 0) { o = '...'; }
4184 v = stringify(v);
4185 if (v.length <= l)
4186 return v;
4187 return v.substring(0, l - o.length) + o;
4188 }
4189 function truncatewords(v, words, o) {
4190 if (words === void 0) { words = 15; }
4191 if (o === void 0) { o = '...'; }
4192 var arr = stringify(v).split(/\s+/);
4193 if (words <= 0)
4194 words = 1;
4195 var ret = arr.slice(0, words).join(' ');
4196 if (arr.length >= words)
4197 ret += o;
4198 return ret;
4199 }
4200 function normalize_whitespace(v) {
4201 v = stringify(v);
4202 return v.replace(/\s+/g, ' ');
4203 }
4204 function number_of_words(input, mode) {
4205 input = stringify(input).trim();
4206 if (!input)
4207 return 0;
4208 switch (mode) {
4209 case 'cjk':
4210 // Count CJK characters and words
4211 return (input.match(rCJKWord) || []).length + (input.match(rNonCJKWord) || []).length;
4212 case 'auto':
4213 // Count CJK characters, if none, count words
4214 return rCJKWord.test(input)
4215 ? input.match(rCJKWord).length + (input.match(rNonCJKWord) || []).length
4216 : input.split(/\s+/).length;
4217 default:
4218 // Count words only
4219 return input.split(/\s+/).length;
4220 }
4221 }
4222 function array_to_sentence_string(array, connector) {
4223 if (connector === void 0) { connector = 'and'; }
4224 switch (array.length) {
4225 case 0:
4226 return '';
4227 case 1:
4228 return array[0];
4229 case 2:
4230 return "".concat(array[0], " ").concat(connector, " ").concat(array[1]);
4231 default:
4232 return "".concat(array.slice(0, -1).join(', '), ", ").concat(connector, " ").concat(array[array.length - 1]);
4233 }
4234 }
4235
4236 var stringFilters = /*#__PURE__*/Object.freeze({
4237 __proto__: null,
4238 append: append,
4239 prepend: prepend,
4240 lstrip: lstrip,
4241 downcase: downcase,
4242 upcase: upcase,
4243 remove: remove,
4244 remove_first: remove_first,
4245 remove_last: remove_last,
4246 rstrip: rstrip,
4247 split: split,
4248 strip: strip,
4249 strip_newlines: strip_newlines,
4250 capitalize: capitalize,
4251 replace: replace,
4252 replace_first: replace_first,
4253 replace_last: replace_last,
4254 truncate: truncate,
4255 truncatewords: truncatewords,
4256 normalize_whitespace: normalize_whitespace,
4257 number_of_words: number_of_words,
4258 array_to_sentence_string: array_to_sentence_string
4259 });
4260
4261 var filters = __assign(__assign(__assign(__assign(__assign(__assign(__assign({}, htmlFilters), mathFilters), urlFilters), arrayFilters), dateFilters), stringFilters), misc);
4262
4263 var default_1 = /** @class */ (function (_super) {
4264 __extends(default_1, _super);
4265 function default_1(token, remainTokens, liquid) {
4266 var _this = _super.call(this, token, remainTokens, liquid) || this;
4267 _this.key = _this.tokenizer.readIdentifier().content;
4268 _this.tokenizer.assert(_this.key, 'expected variable name');
4269 _this.tokenizer.skipBlank();
4270 _this.tokenizer.assert(_this.tokenizer.peek() === '=', 'expected "="');
4271 _this.tokenizer.advance();
4272 _this.value = new Value(_this.tokenizer.readFilteredValue(), _this.liquid);
4273 return _this;
4274 }
4275 default_1.prototype.render = function (ctx) {
4276 var _a, _b;
4277 return __generator(this, function (_c) {
4278 switch (_c.label) {
4279 case 0:
4280 _a = ctx.bottom();
4281 _b = this.key;
4282 return [4 /*yield*/, this.value.value(ctx, this.liquid.options.lenientIf)];
4283 case 1:
4284 _a[_b] = _c.sent();
4285 return [2 /*return*/];
4286 }
4287 });
4288 };
4289 return default_1;
4290 }(Tag));
4291
4292 var MODIFIERS = ['offset', 'limit', 'reversed'];
4293 var default_1$1 = /** @class */ (function (_super) {
4294 __extends(default_1, _super);
4295 function default_1(token, remainTokens, liquid) {
4296 var _this = _super.call(this, token, remainTokens, liquid) || this;
4297 var variable = _this.tokenizer.readIdentifier();
4298 var inStr = _this.tokenizer.readIdentifier();
4299 var collection = _this.tokenizer.readValue();
4300 if (!variable.size() || inStr.content !== 'in' || !collection) {
4301 throw new Error("illegal tag: ".concat(token.getText()));
4302 }
4303 _this.variable = variable.content;
4304 _this.collection = collection;
4305 _this.hash = new Hash(_this.tokenizer.remaining());
4306 _this.templates = [];
4307 _this.elseTemplates = [];
4308 var p;
4309 var stream = _this.liquid.parser.parseStream(remainTokens)
4310 .on('start', function () { return (p = _this.templates); })
4311 .on('tag:else', function () { return (p = _this.elseTemplates); })
4312 .on('tag:endfor', function () { return stream.stop(); })
4313 .on('template', function (tpl) { return p.push(tpl); })
4314 .on('end', function () {
4315 throw new Error("tag ".concat(token.getText(), " not closed"));
4316 });
4317 stream.start();
4318 return _this;
4319 }
4320 default_1.prototype.render = function (ctx, emitter) {
4321 var r, collection, _a, continueKey, hash, modifiers, scope, collection_1, collection_1_1, item, e_1_1;
4322 var e_1, _b;
4323 return __generator(this, function (_c) {
4324 switch (_c.label) {
4325 case 0:
4326 r = this.liquid.renderer;
4327 _a = toEnumerable;
4328 return [4 /*yield*/, evalToken(this.collection, ctx)];
4329 case 1:
4330 collection = _a.apply(void 0, [_c.sent()]);
4331 if (!!collection.length) return [3 /*break*/, 3];
4332 return [4 /*yield*/, r.renderTemplates(this.elseTemplates, ctx, emitter)];
4333 case 2:
4334 _c.sent();
4335 return [2 /*return*/];
4336 case 3:
4337 continueKey = 'continue-' + this.variable + '-' + this.collection.getText();
4338 ctx.push({ continue: ctx.getRegister(continueKey) });
4339 return [4 /*yield*/, this.hash.render(ctx)];
4340 case 4:
4341 hash = _c.sent();
4342 ctx.pop();
4343 modifiers = this.liquid.options.orderedFilterParameters
4344 ? Object.keys(hash).filter(function (x) { return MODIFIERS.includes(x); })
4345 : MODIFIERS.filter(function (x) { return hash[x] !== undefined; });
4346 collection = modifiers.reduce(function (collection, modifier) {
4347 if (modifier === 'offset')
4348 return offset(collection, hash['offset']);
4349 if (modifier === 'limit')
4350 return limit(collection, hash['limit']);
4351 return reversed(collection);
4352 }, collection);
4353 ctx.setRegister(continueKey, (hash['offset'] || 0) + collection.length);
4354 scope = { forloop: new ForloopDrop(collection.length, this.collection.getText(), this.variable) };
4355 ctx.push(scope);
4356 _c.label = 5;
4357 case 5:
4358 _c.trys.push([5, 10, 11, 12]);
4359 collection_1 = __values(collection), collection_1_1 = collection_1.next();
4360 _c.label = 6;
4361 case 6:
4362 if (!!collection_1_1.done) return [3 /*break*/, 9];
4363 item = collection_1_1.value;
4364 scope[this.variable] = item;
4365 return [4 /*yield*/, r.renderTemplates(this.templates, ctx, emitter)];
4366 case 7:
4367 _c.sent();
4368 if (emitter['break']) {
4369 emitter['break'] = false;
4370 return [3 /*break*/, 9];
4371 }
4372 emitter['continue'] = false;
4373 scope.forloop.next();
4374 _c.label = 8;
4375 case 8:
4376 collection_1_1 = collection_1.next();
4377 return [3 /*break*/, 6];
4378 case 9: return [3 /*break*/, 12];
4379 case 10:
4380 e_1_1 = _c.sent();
4381 e_1 = { error: e_1_1 };
4382 return [3 /*break*/, 12];
4383 case 11:
4384 try {
4385 if (collection_1_1 && !collection_1_1.done && (_b = collection_1.return)) _b.call(collection_1);
4386 }
4387 finally { if (e_1) throw e_1.error; }
4388 return [7 /*endfinally*/];
4389 case 12:
4390 ctx.pop();
4391 return [2 /*return*/];
4392 }
4393 });
4394 };
4395 return default_1;
4396 }(Tag));
4397 function reversed(arr) {
4398 return __spreadArray([], __read(arr), false).reverse();
4399 }
4400 function offset(arr, count) {
4401 return arr.slice(count);
4402 }
4403 function limit(arr, count) {
4404 return arr.slice(0, count);
4405 }
4406
4407 var default_1$2 = /** @class */ (function (_super) {
4408 __extends(default_1, _super);
4409 function default_1(tagToken, remainTokens, liquid) {
4410 var _this = _super.call(this, tagToken, remainTokens, liquid) || this;
4411 _this.templates = [];
4412 _this.variable = _this.readVariableName();
4413 while (remainTokens.length) {
4414 var token = remainTokens.shift();
4415 if (isTagToken(token) && token.name === 'endcapture')
4416 return _this;
4417 _this.templates.push(liquid.parser.parseToken(token, remainTokens));
4418 }
4419 throw new Error("tag ".concat(tagToken.getText(), " not closed"));
4420 }
4421 default_1.prototype.render = function (ctx) {
4422 var r, html;
4423 return __generator(this, function (_a) {
4424 switch (_a.label) {
4425 case 0:
4426 r = this.liquid.renderer;
4427 return [4 /*yield*/, r.renderTemplates(this.templates, ctx)];
4428 case 1:
4429 html = _a.sent();
4430 ctx.bottom()[this.variable] = html;
4431 return [2 /*return*/];
4432 }
4433 });
4434 };
4435 default_1.prototype.readVariableName = function () {
4436 var word = this.tokenizer.readIdentifier().content;
4437 if (word)
4438 return word;
4439 var quoted = this.tokenizer.readQuoted();
4440 if (quoted)
4441 return evalQuotedToken(quoted);
4442 throw this.tokenizer.error('invalid capture name');
4443 };
4444 return default_1;
4445 }(Tag));
4446
4447 var default_1$3 = /** @class */ (function (_super) {
4448 __extends(default_1, _super);
4449 function default_1(tagToken, remainTokens, liquid) {
4450 var _this = _super.call(this, tagToken, remainTokens, liquid) || this;
4451 _this.branches = [];
4452 _this.elseTemplates = [];
4453 _this.value = new Value(_this.tokenizer.readFilteredValue(), _this.liquid);
4454 _this.elseTemplates = [];
4455 var p = [];
4456 var elseCount = 0;
4457 var stream = _this.liquid.parser.parseStream(remainTokens)
4458 .on('tag:when', function (token) {
4459 if (elseCount > 0) {
4460 return;
4461 }
4462 p = [];
4463 var values = [];
4464 while (!token.tokenizer.end()) {
4465 values.push(token.tokenizer.readValueOrThrow());
4466 token.tokenizer.skipBlank();
4467 if (token.tokenizer.peek() === ',') {
4468 token.tokenizer.readTo(',');
4469 }
4470 else {
4471 token.tokenizer.readTo('or');
4472 }
4473 }
4474 _this.branches.push({
4475 values: values,
4476 templates: p
4477 });
4478 })
4479 .on('tag:else', function () {
4480 elseCount++;
4481 p = _this.elseTemplates;
4482 })
4483 .on('tag:endcase', function () { return stream.stop(); })
4484 .on('template', function (tpl) {
4485 if (p !== _this.elseTemplates || elseCount === 1) {
4486 p.push(tpl);
4487 }
4488 })
4489 .on('end', function () {
4490 throw new Error("tag ".concat(tagToken.getText(), " not closed"));
4491 });
4492 stream.start();
4493 return _this;
4494 }
4495 default_1.prototype.render = function (ctx, emitter) {
4496 var r, target, _a, branchHit, _b, _c, branch, _d, _e, valueToken, value, e_1_1, e_2_1;
4497 var e_2, _f, e_1, _g;
4498 return __generator(this, function (_h) {
4499 switch (_h.label) {
4500 case 0:
4501 r = this.liquid.renderer;
4502 _a = toValue;
4503 return [4 /*yield*/, this.value.value(ctx, ctx.opts.lenientIf)];
4504 case 1:
4505 target = _a.apply(void 0, [_h.sent()]);
4506 branchHit = false;
4507 _h.label = 2;
4508 case 2:
4509 _h.trys.push([2, 14, 15, 16]);
4510 _b = __values(this.branches), _c = _b.next();
4511 _h.label = 3;
4512 case 3:
4513 if (!!_c.done) return [3 /*break*/, 13];
4514 branch = _c.value;
4515 _h.label = 4;
4516 case 4:
4517 _h.trys.push([4, 10, 11, 12]);
4518 _d = (e_1 = void 0, __values(branch.values)), _e = _d.next();
4519 _h.label = 5;
4520 case 5:
4521 if (!!_e.done) return [3 /*break*/, 9];
4522 valueToken = _e.value;
4523 return [4 /*yield*/, evalToken(valueToken, ctx, ctx.opts.lenientIf)];
4524 case 6:
4525 value = _h.sent();
4526 if (!equals(target, value)) return [3 /*break*/, 8];
4527 return [4 /*yield*/, r.renderTemplates(branch.templates, ctx, emitter)];
4528 case 7:
4529 _h.sent();
4530 branchHit = true;
4531 return [3 /*break*/, 9];
4532 case 8:
4533 _e = _d.next();
4534 return [3 /*break*/, 5];
4535 case 9: return [3 /*break*/, 12];
4536 case 10:
4537 e_1_1 = _h.sent();
4538 e_1 = { error: e_1_1 };
4539 return [3 /*break*/, 12];
4540 case 11:
4541 try {
4542 if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
4543 }
4544 finally { if (e_1) throw e_1.error; }
4545 return [7 /*endfinally*/];
4546 case 12:
4547 _c = _b.next();
4548 return [3 /*break*/, 3];
4549 case 13: return [3 /*break*/, 16];
4550 case 14:
4551 e_2_1 = _h.sent();
4552 e_2 = { error: e_2_1 };
4553 return [3 /*break*/, 16];
4554 case 15:
4555 try {
4556 if (_c && !_c.done && (_f = _b.return)) _f.call(_b);
4557 }
4558 finally { if (e_2) throw e_2.error; }
4559 return [7 /*endfinally*/];
4560 case 16:
4561 if (!!branchHit) return [3 /*break*/, 18];
4562 return [4 /*yield*/, r.renderTemplates(this.elseTemplates, ctx, emitter)];
4563 case 17:
4564 _h.sent();
4565 _h.label = 18;
4566 case 18: return [2 /*return*/];
4567 }
4568 });
4569 };
4570 return default_1;
4571 }(Tag));
4572
4573 var default_1$4 = /** @class */ (function (_super) {
4574 __extends(default_1, _super);
4575 function default_1(tagToken, remainTokens, liquid) {
4576 var _this = _super.call(this, tagToken, remainTokens, liquid) || this;
4577 while (remainTokens.length) {
4578 var token = remainTokens.shift();
4579 if (isTagToken(token) && token.name === 'endcomment')
4580 return _this;
4581 }
4582 throw new Error("tag ".concat(tagToken.getText(), " not closed"));
4583 }
4584 default_1.prototype.render = function () { };
4585 return default_1;
4586 }(Tag));
4587
4588 var default_1$5 = /** @class */ (function (_super) {
4589 __extends(default_1, _super);
4590 function default_1(token, remainTokens, liquid) {
4591 var _this = _super.call(this, token, remainTokens, liquid) || this;
4592 var tokenizer = _this.tokenizer;
4593 _this.file = parseFilePath(tokenizer, _this.liquid);
4594 _this.currentFile = token.file;
4595 while (!tokenizer.end()) {
4596 tokenizer.skipBlank();
4597 var begin = tokenizer.p;
4598 var keyword = tokenizer.readIdentifier();
4599 if (keyword.content === 'with' || keyword.content === 'for') {
4600 tokenizer.skipBlank();
4601 // can be normal key/value pair, like "with: true"
4602 if (tokenizer.peek() !== ':') {
4603 var value = tokenizer.readValue();
4604 // can be normal key, like "with,"
4605 if (value) {
4606 var beforeAs = tokenizer.p;
4607 var asStr = tokenizer.readIdentifier();
4608 var alias = void 0;
4609 if (asStr.content === 'as')
4610 alias = tokenizer.readIdentifier();
4611 else
4612 tokenizer.p = beforeAs;
4613 _this[keyword.content] = { value: value, alias: alias && alias.content };
4614 tokenizer.skipBlank();
4615 if (tokenizer.peek() === ',')
4616 tokenizer.advance();
4617 continue; // matched!
4618 }
4619 }
4620 }
4621 /**
4622 * restore cursor if with/for not matched
4623 */
4624 tokenizer.p = begin;
4625 break;
4626 }
4627 _this.hash = new Hash(tokenizer.remaining());
4628 return _this;
4629 }
4630 default_1.prototype.render = function (ctx, emitter) {
4631 var _a, liquid, hash, filepath, childCtx, scope, _b, _c, _d, value, alias, _e, _f, _g, value, alias, collection, _h, collection_1, collection_1_1, item, templates, e_1_1, templates;
4632 var e_1, _j;
4633 return __generator(this, function (_k) {
4634 switch (_k.label) {
4635 case 0:
4636 _a = this, liquid = _a.liquid, hash = _a.hash;
4637 return [4 /*yield*/, renderFilePath(this['file'], ctx, liquid)];
4638 case 1:
4639 filepath = (_k.sent());
4640 assert(filepath, function () { return "illegal file path \"".concat(filepath, "\""); });
4641 childCtx = new Context({}, ctx.opts, { sync: ctx.sync, globals: ctx.globals, strictVariables: ctx.strictVariables });
4642 scope = childCtx.bottom();
4643 _b = __assign;
4644 _c = [scope];
4645 return [4 /*yield*/, hash.render(ctx)];
4646 case 2:
4647 _b.apply(void 0, _c.concat([_k.sent()]));
4648 if (!this['with']) return [3 /*break*/, 4];
4649 _d = this['with'], value = _d.value, alias = _d.alias;
4650 _e = scope;
4651 _f = alias || filepath;
4652 return [4 /*yield*/, evalToken(value, ctx)];
4653 case 3:
4654 _e[_f] = _k.sent();
4655 _k.label = 4;
4656 case 4:
4657 if (!this['for']) return [3 /*break*/, 15];
4658 _g = this['for'], value = _g.value, alias = _g.alias;
4659 _h = toEnumerable;
4660 return [4 /*yield*/, evalToken(value, ctx)];
4661 case 5:
4662 collection = _h.apply(void 0, [_k.sent()]);
4663 scope['forloop'] = new ForloopDrop(collection.length, value.getText(), alias);
4664 _k.label = 6;
4665 case 6:
4666 _k.trys.push([6, 12, 13, 14]);
4667 collection_1 = __values(collection), collection_1_1 = collection_1.next();
4668 _k.label = 7;
4669 case 7:
4670 if (!!collection_1_1.done) return [3 /*break*/, 11];
4671 item = collection_1_1.value;
4672 scope[alias] = item;
4673 return [4 /*yield*/, liquid._parsePartialFile(filepath, childCtx.sync, this['currentFile'])];
4674 case 8:
4675 templates = (_k.sent());
4676 return [4 /*yield*/, liquid.renderer.renderTemplates(templates, childCtx, emitter)];
4677 case 9:
4678 _k.sent();
4679 scope['forloop'].next();
4680 _k.label = 10;
4681 case 10:
4682 collection_1_1 = collection_1.next();
4683 return [3 /*break*/, 7];
4684 case 11: return [3 /*break*/, 14];
4685 case 12:
4686 e_1_1 = _k.sent();
4687 e_1 = { error: e_1_1 };
4688 return [3 /*break*/, 14];
4689 case 13:
4690 try {
4691 if (collection_1_1 && !collection_1_1.done && (_j = collection_1.return)) _j.call(collection_1);
4692 }
4693 finally { if (e_1) throw e_1.error; }
4694 return [7 /*endfinally*/];
4695 case 14: return [3 /*break*/, 18];
4696 case 15: return [4 /*yield*/, liquid._parsePartialFile(filepath, childCtx.sync, this['currentFile'])];
4697 case 16:
4698 templates = (_k.sent());
4699 return [4 /*yield*/, liquid.renderer.renderTemplates(templates, childCtx, emitter)];
4700 case 17:
4701 _k.sent();
4702 _k.label = 18;
4703 case 18: return [2 /*return*/];
4704 }
4705 });
4706 };
4707 return default_1;
4708 }(Tag));
4709 /**
4710 * @return null for "none",
4711 * @return Template[] for quoted with tags and/or filters
4712 * @return Token for expression (not quoted)
4713 * @throws TypeError if cannot read next token
4714 */
4715 function parseFilePath(tokenizer, liquid) {
4716 if (liquid.options.dynamicPartials) {
4717 var file = tokenizer.readValue();
4718 tokenizer.assert(file, 'illegal file path');
4719 if (file.getText() === 'none')
4720 return;
4721 if (isQuotedToken(file)) {
4722 // for filenames like "files/{{file}}", eval as liquid template
4723 var templates_1 = liquid.parse(evalQuotedToken(file));
4724 return optimize(templates_1);
4725 }
4726 return file;
4727 }
4728 var tokens = __spreadArray([], __read(tokenizer.readFileNameTemplate(liquid.options)), false);
4729 var templates = optimize(liquid.parser.parseTokens(tokens));
4730 return templates === 'none' ? undefined : templates;
4731 }
4732 function optimize(templates) {
4733 // for filenames like "files/file.liquid", extract the string directly
4734 if (templates.length === 1 && isHTMLToken(templates[0].token))
4735 return templates[0].token.getContent();
4736 return templates;
4737 }
4738 function renderFilePath(file, ctx, liquid) {
4739 return __generator(this, function (_a) {
4740 switch (_a.label) {
4741 case 0:
4742 if (typeof file === 'string')
4743 return [2 /*return*/, file];
4744 if (Array.isArray(file))
4745 return [2 /*return*/, liquid.renderer.renderTemplates(file, ctx)];
4746 return [4 /*yield*/, evalToken(file, ctx)];
4747 case 1: return [2 /*return*/, _a.sent()];
4748 }
4749 });
4750 }
4751
4752 var default_1$6 = /** @class */ (function (_super) {
4753 __extends(default_1, _super);
4754 function default_1(token, remainTokens, liquid) {
4755 var _this = _super.call(this, token, remainTokens, liquid) || this;
4756 var tokenizer = token.tokenizer;
4757 _this['file'] = parseFilePath(tokenizer, _this.liquid);
4758 _this['currentFile'] = token.file;
4759 var begin = tokenizer.p;
4760 var withStr = tokenizer.readIdentifier();
4761 if (withStr.content === 'with') {
4762 tokenizer.skipBlank();
4763 if (tokenizer.peek() !== ':') {
4764 _this.withVar = tokenizer.readValue();
4765 }
4766 else
4767 tokenizer.p = begin;
4768 }
4769 else
4770 tokenizer.p = begin;
4771 _this.hash = new Hash(tokenizer.remaining(), _this.liquid.options.jekyllInclude);
4772 return _this;
4773 }
4774 default_1.prototype.render = function (ctx, emitter) {
4775 var _a, liquid, hash, withVar, renderer, filepath, saved, scope, _b, _c, templates;
4776 return __generator(this, function (_d) {
4777 switch (_d.label) {
4778 case 0:
4779 _a = this, liquid = _a.liquid, hash = _a.hash, withVar = _a.withVar;
4780 renderer = liquid.renderer;
4781 return [4 /*yield*/, renderFilePath(this['file'], ctx, liquid)];
4782 case 1:
4783 filepath = (_d.sent());
4784 assert(filepath, function () { return "illegal file path \"".concat(filepath, "\""); });
4785 saved = ctx.saveRegister('blocks', 'blockMode');
4786 ctx.setRegister('blocks', {});
4787 ctx.setRegister('blockMode', BlockMode.OUTPUT);
4788 return [4 /*yield*/, hash.render(ctx)];
4789 case 2:
4790 scope = (_d.sent());
4791 if (!withVar) return [3 /*break*/, 4];
4792 _b = scope;
4793 _c = filepath;
4794 return [4 /*yield*/, evalToken(withVar, ctx)];
4795 case 3:
4796 _b[_c] = _d.sent();
4797 _d.label = 4;
4798 case 4: return [4 /*yield*/, liquid._parsePartialFile(filepath, ctx.sync, this['currentFile'])];
4799 case 5:
4800 templates = (_d.sent());
4801 ctx.push(ctx.opts.jekyllInclude ? { include: scope } : scope);
4802 return [4 /*yield*/, renderer.renderTemplates(templates, ctx, emitter)];
4803 case 6:
4804 _d.sent();
4805 ctx.pop();
4806 ctx.restoreRegister(saved);
4807 return [2 /*return*/];
4808 }
4809 });
4810 };
4811 return default_1;
4812 }(Tag));
4813
4814 var default_1$7 = /** @class */ (function (_super) {
4815 __extends(default_1, _super);
4816 function default_1(token, remainTokens, liquid) {
4817 var _this = _super.call(this, token, remainTokens, liquid) || this;
4818 _this.variable = _this.tokenizer.readIdentifier().content;
4819 return _this;
4820 }
4821 default_1.prototype.render = function (context, emitter) {
4822 var scope = context.environments;
4823 if (!isNumber(scope[this.variable])) {
4824 scope[this.variable] = 0;
4825 }
4826 emitter.write(stringify(--scope[this.variable]));
4827 };
4828 return default_1;
4829 }(Tag));
4830
4831 var default_1$8 = /** @class */ (function (_super) {
4832 __extends(default_1, _super);
4833 function default_1(token, remainTokens, liquid) {
4834 var _this = _super.call(this, token, remainTokens, liquid) || this;
4835 _this.candidates = [];
4836 var group = _this.tokenizer.readValue();
4837 _this.tokenizer.skipBlank();
4838 if (group) {
4839 if (_this.tokenizer.peek() === ':') {
4840 _this.group = group;
4841 _this.tokenizer.advance();
4842 }
4843 else
4844 _this.candidates.push(group);
4845 }
4846 while (!_this.tokenizer.end()) {
4847 var value = _this.tokenizer.readValue();
4848 if (value)
4849 _this.candidates.push(value);
4850 _this.tokenizer.readTo(',');
4851 }
4852 _this.tokenizer.assert(_this.candidates.length, function () { return "empty candidates: \"".concat(token.getText(), "\""); });
4853 return _this;
4854 }
4855 default_1.prototype.render = function (ctx, emitter) {
4856 var group, fingerprint, groups, idx, candidate;
4857 return __generator(this, function (_a) {
4858 switch (_a.label) {
4859 case 0: return [4 /*yield*/, evalToken(this.group, ctx)];
4860 case 1:
4861 group = (_a.sent());
4862 fingerprint = "cycle:".concat(group, ":") + this.candidates.join(',');
4863 groups = ctx.getRegister('cycle');
4864 idx = groups[fingerprint];
4865 if (idx === undefined) {
4866 idx = groups[fingerprint] = 0;
4867 }
4868 candidate = this.candidates[idx];
4869 idx = (idx + 1) % this.candidates.length;
4870 groups[fingerprint] = idx;
4871 return [4 /*yield*/, evalToken(candidate, ctx)];
4872 case 2: return [2 /*return*/, _a.sent()];
4873 }
4874 });
4875 };
4876 return default_1;
4877 }(Tag));
4878
4879 var default_1$9 = /** @class */ (function (_super) {
4880 __extends(default_1, _super);
4881 function default_1(tagToken, remainTokens, liquid) {
4882 var _this = _super.call(this, tagToken, remainTokens, liquid) || this;
4883 _this.branches = [];
4884 _this.elseTemplates = [];
4885 var p = [];
4886 var elseCount = 0;
4887 liquid.parser.parseStream(remainTokens)
4888 .on('start', function () { return _this.branches.push({
4889 value: new Value(tagToken.args, _this.liquid),
4890 templates: (p = [])
4891 }); })
4892 .on('tag:elsif', function (token) {
4893 if (elseCount > 0) {
4894 p = [];
4895 return;
4896 }
4897 _this.branches.push({
4898 value: new Value(token.args, _this.liquid),
4899 templates: (p = [])
4900 });
4901 })
4902 .on('tag:else', function () {
4903 elseCount++;
4904 p = _this.elseTemplates;
4905 })
4906 .on('tag:endif', function () { this.stop(); })
4907 .on('template', function (tpl) {
4908 if (p !== _this.elseTemplates || elseCount === 1) {
4909 p.push(tpl);
4910 }
4911 })
4912 .on('end', function () { throw new Error("tag ".concat(tagToken.getText(), " not closed")); })
4913 .start();
4914 return _this;
4915 }
4916 default_1.prototype.render = function (ctx, emitter) {
4917 var r, _a, _b, _c, value, templates, v, e_1_1;
4918 var e_1, _d;
4919 return __generator(this, function (_e) {
4920 switch (_e.label) {
4921 case 0:
4922 r = this.liquid.renderer;
4923 _e.label = 1;
4924 case 1:
4925 _e.trys.push([1, 7, 8, 9]);
4926 _a = __values(this.branches), _b = _a.next();
4927 _e.label = 2;
4928 case 2:
4929 if (!!_b.done) return [3 /*break*/, 6];
4930 _c = _b.value, value = _c.value, templates = _c.templates;
4931 return [4 /*yield*/, value.value(ctx, ctx.opts.lenientIf)];
4932 case 3:
4933 v = _e.sent();
4934 if (!isTruthy(v, ctx)) return [3 /*break*/, 5];
4935 return [4 /*yield*/, r.renderTemplates(templates, ctx, emitter)];
4936 case 4:
4937 _e.sent();
4938 return [2 /*return*/];
4939 case 5:
4940 _b = _a.next();
4941 return [3 /*break*/, 2];
4942 case 6: return [3 /*break*/, 9];
4943 case 7:
4944 e_1_1 = _e.sent();
4945 e_1 = { error: e_1_1 };
4946 return [3 /*break*/, 9];
4947 case 8:
4948 try {
4949 if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
4950 }
4951 finally { if (e_1) throw e_1.error; }
4952 return [7 /*endfinally*/];
4953 case 9: return [4 /*yield*/, r.renderTemplates(this.elseTemplates, ctx, emitter)];
4954 case 10:
4955 _e.sent();
4956 return [2 /*return*/];
4957 }
4958 });
4959 };
4960 return default_1;
4961 }(Tag));
4962
4963 var default_1$a = /** @class */ (function (_super) {
4964 __extends(default_1, _super);
4965 function default_1(token, remainTokens, liquid) {
4966 var _this = _super.call(this, token, remainTokens, liquid) || this;
4967 _this.variable = _this.tokenizer.readIdentifier().content;
4968 return _this;
4969 }
4970 default_1.prototype.render = function (context, emitter) {
4971 var scope = context.environments;
4972 if (!isNumber(scope[this.variable])) {
4973 scope[this.variable] = 0;
4974 }
4975 var val = scope[this.variable];
4976 scope[this.variable]++;
4977 emitter.write(stringify(val));
4978 };
4979 return default_1;
4980 }(Tag));
4981
4982 var default_1$b = /** @class */ (function (_super) {
4983 __extends(default_1, _super);
4984 function default_1(token, remainTokens, liquid) {
4985 var _this = _super.call(this, token, remainTokens, liquid) || this;
4986 _this.file = parseFilePath(_this.tokenizer, _this.liquid);
4987 _this['currentFile'] = token.file;
4988 _this.args = new Hash(_this.tokenizer.remaining());
4989 _this.templates = _this.liquid.parser.parseTokens(remainTokens);
4990 return _this;
4991 }
4992 default_1.prototype.render = function (ctx, emitter) {
4993 var _a, liquid, args, file, renderer, filepath, templates, html, blocks, _b, _c;
4994 return __generator(this, function (_d) {
4995 switch (_d.label) {
4996 case 0:
4997 _a = this, liquid = _a.liquid, args = _a.args, file = _a.file;
4998 renderer = liquid.renderer;
4999 if (!(file === undefined)) return [3 /*break*/, 2];
5000 ctx.setRegister('blockMode', BlockMode.OUTPUT);
5001 return [4 /*yield*/, renderer.renderTemplates(this.templates, ctx, emitter)];
5002 case 1:
5003 _d.sent();
5004 return [2 /*return*/];
5005 case 2: return [4 /*yield*/, renderFilePath(this.file, ctx, liquid)];
5006 case 3:
5007 filepath = (_d.sent());
5008 assert(filepath, function () { return "illegal file path \"".concat(filepath, "\""); });
5009 return [4 /*yield*/, liquid._parseLayoutFile(filepath, ctx.sync, this['currentFile'])];
5010 case 4:
5011 templates = (_d.sent());
5012 // render remaining contents and store rendered results
5013 ctx.setRegister('blockMode', BlockMode.STORE);
5014 return [4 /*yield*/, renderer.renderTemplates(this.templates, ctx)];
5015 case 5:
5016 html = _d.sent();
5017 blocks = ctx.getRegister('blocks');
5018 // set whole content to anonymous block if anonymous doesn't specified
5019 if (blocks[''] === undefined)
5020 blocks[''] = function (parent, emitter) { return emitter.write(html); };
5021 ctx.setRegister('blockMode', BlockMode.OUTPUT);
5022 // render the layout file use stored blocks
5023 _c = (_b = ctx).push;
5024 return [4 /*yield*/, args.render(ctx)];
5025 case 6:
5026 // render the layout file use stored blocks
5027 _c.apply(_b, [(_d.sent())]);
5028 return [4 /*yield*/, renderer.renderTemplates(templates, ctx, emitter)];
5029 case 7:
5030 _d.sent();
5031 ctx.pop();
5032 return [2 /*return*/];
5033 }
5034 });
5035 };
5036 return default_1;
5037 }(Tag));
5038
5039 var default_1$c = /** @class */ (function (_super) {
5040 __extends(default_1, _super);
5041 function default_1(token, remainTokens, liquid) {
5042 var _this = _super.call(this, token, remainTokens, liquid) || this;
5043 _this.templates = [];
5044 var match = /\w+/.exec(token.args);
5045 _this.block = match ? match[0] : '';
5046 while (remainTokens.length) {
5047 var token_1 = remainTokens.shift();
5048 if (isTagToken(token_1) && token_1.name === 'endblock')
5049 return _this;
5050 var template = liquid.parser.parseToken(token_1, remainTokens);
5051 _this.templates.push(template);
5052 }
5053 throw new Error("tag ".concat(token.getText(), " not closed"));
5054 }
5055 default_1.prototype.render = function (ctx, emitter) {
5056 var blockRender;
5057 return __generator(this, function (_a) {
5058 switch (_a.label) {
5059 case 0:
5060 blockRender = this.getBlockRender(ctx);
5061 if (!(ctx.getRegister('blockMode') === BlockMode.STORE)) return [3 /*break*/, 1];
5062 ctx.getRegister('blocks')[this.block] = blockRender;
5063 return [3 /*break*/, 3];
5064 case 1: return [4 /*yield*/, blockRender(new BlockDrop(), emitter)];
5065 case 2:
5066 _a.sent();
5067 _a.label = 3;
5068 case 3: return [2 /*return*/];
5069 }
5070 });
5071 };
5072 default_1.prototype.getBlockRender = function (ctx) {
5073 var _a = this, liquid = _a.liquid, templates = _a.templates;
5074 var renderChild = ctx.getRegister('blocks')[this.block];
5075 var renderCurrent = function (superBlock, emitter) {
5076 return __generator(this, function (_a) {
5077 switch (_a.label) {
5078 case 0:
5079 // add {{ block.super }} support when rendering
5080 ctx.push({ block: superBlock });
5081 return [4 /*yield*/, liquid.renderer.renderTemplates(templates, ctx, emitter)];
5082 case 1:
5083 _a.sent();
5084 ctx.pop();
5085 return [2 /*return*/];
5086 }
5087 });
5088 };
5089 return renderChild
5090 ? function (superBlock, emitter) { return renderChild(new BlockDrop(function () { return renderCurrent(superBlock, emitter); }), emitter); }
5091 : renderCurrent;
5092 };
5093 return default_1;
5094 }(Tag));
5095
5096 var default_1$d = /** @class */ (function (_super) {
5097 __extends(default_1, _super);
5098 function default_1(tagToken, remainTokens, liquid) {
5099 var _this = _super.call(this, tagToken, remainTokens, liquid) || this;
5100 _this.tokens = [];
5101 while (remainTokens.length) {
5102 var token = remainTokens.shift();
5103 if (isTagToken(token) && token.name === 'endraw')
5104 return _this;
5105 _this.tokens.push(token);
5106 }
5107 throw new Error("tag ".concat(tagToken.getText(), " not closed"));
5108 }
5109 default_1.prototype.render = function () {
5110 return this.tokens.map(function (token) { return token.getText(); }).join('');
5111 };
5112 return default_1;
5113 }(Tag));
5114
5115 var TablerowloopDrop = /** @class */ (function (_super) {
5116 __extends(TablerowloopDrop, _super);
5117 function TablerowloopDrop(length, cols, collection, variable) {
5118 var _this = _super.call(this, length, collection, variable) || this;
5119 _this.length = length;
5120 _this.cols = cols;
5121 return _this;
5122 }
5123 TablerowloopDrop.prototype.row = function () {
5124 return Math.floor(this.i / this.cols) + 1;
5125 };
5126 TablerowloopDrop.prototype.col0 = function () {
5127 return (this.i % this.cols);
5128 };
5129 TablerowloopDrop.prototype.col = function () {
5130 return this.col0() + 1;
5131 };
5132 TablerowloopDrop.prototype.col_first = function () {
5133 return this.col0() === 0;
5134 };
5135 TablerowloopDrop.prototype.col_last = function () {
5136 return this.col() === this.cols;
5137 };
5138 return TablerowloopDrop;
5139 }(ForloopDrop));
5140
5141 var default_1$e = /** @class */ (function (_super) {
5142 __extends(default_1, _super);
5143 function default_1(tagToken, remainTokens, liquid) {
5144 var _this = _super.call(this, tagToken, remainTokens, liquid) || this;
5145 var variable = _this.tokenizer.readIdentifier();
5146 _this.tokenizer.skipBlank();
5147 var predicate = _this.tokenizer.readIdentifier();
5148 var collectionToken = _this.tokenizer.readValue();
5149 if (predicate.content !== 'in' || !collectionToken) {
5150 throw new Error("illegal tag: ".concat(tagToken.getText()));
5151 }
5152 _this.variable = variable.content;
5153 _this.collection = collectionToken;
5154 _this.args = new Hash(_this.tokenizer.remaining());
5155 _this.templates = [];
5156 var p;
5157 var stream = _this.liquid.parser.parseStream(remainTokens)
5158 .on('start', function () { return (p = _this.templates); })
5159 .on('tag:endtablerow', function () { return stream.stop(); })
5160 .on('template', function (tpl) { return p.push(tpl); })
5161 .on('end', function () {
5162 throw new Error("tag ".concat(tagToken.getText(), " not closed"));
5163 });
5164 stream.start();
5165 return _this;
5166 }
5167 default_1.prototype.render = function (ctx, emitter) {
5168 var collection, _a, args, offset, limit, cols, r, tablerowloop, scope, idx;
5169 return __generator(this, function (_b) {
5170 switch (_b.label) {
5171 case 0:
5172 _a = toEnumerable;
5173 return [4 /*yield*/, evalToken(this.collection, ctx)];
5174 case 1:
5175 collection = _a.apply(void 0, [_b.sent()]);
5176 return [4 /*yield*/, this.args.render(ctx)];
5177 case 2:
5178 args = (_b.sent());
5179 offset = args.offset || 0;
5180 limit = (args.limit === undefined) ? collection.length : args.limit;
5181 collection = collection.slice(offset, offset + limit);
5182 cols = args.cols || collection.length;
5183 r = this.liquid.renderer;
5184 tablerowloop = new TablerowloopDrop(collection.length, cols, this.collection.getText(), this.variable);
5185 scope = { tablerowloop: tablerowloop };
5186 ctx.push(scope);
5187 idx = 0;
5188 _b.label = 3;
5189 case 3:
5190 if (!(idx < collection.length)) return [3 /*break*/, 6];
5191 scope[this.variable] = collection[idx];
5192 if (tablerowloop.col0() === 0) {
5193 if (tablerowloop.row() !== 1)
5194 emitter.write('</tr>');
5195 emitter.write("<tr class=\"row".concat(tablerowloop.row(), "\">"));
5196 }
5197 emitter.write("<td class=\"col".concat(tablerowloop.col(), "\">"));
5198 return [4 /*yield*/, r.renderTemplates(this.templates, ctx, emitter)];
5199 case 4:
5200 _b.sent();
5201 emitter.write('</td>');
5202 _b.label = 5;
5203 case 5:
5204 idx++, tablerowloop.next();
5205 return [3 /*break*/, 3];
5206 case 6:
5207 if (collection.length)
5208 emitter.write('</tr>');
5209 ctx.pop();
5210 return [2 /*return*/];
5211 }
5212 });
5213 };
5214 return default_1;
5215 }(Tag));
5216
5217 var default_1$f = /** @class */ (function (_super) {
5218 __extends(default_1, _super);
5219 function default_1(tagToken, remainTokens, liquid) {
5220 var _this = _super.call(this, tagToken, remainTokens, liquid) || this;
5221 _this.branches = [];
5222 _this.elseTemplates = [];
5223 var p = [];
5224 var elseCount = 0;
5225 _this.liquid.parser.parseStream(remainTokens)
5226 .on('start', function () { return _this.branches.push({
5227 value: new Value(tagToken.args, _this.liquid),
5228 test: isFalsy,
5229 templates: (p = [])
5230 }); })
5231 .on('tag:elsif', function (token) {
5232 if (elseCount > 0) {
5233 p = [];
5234 return;
5235 }
5236 _this.branches.push({
5237 value: new Value(token.args, _this.liquid),
5238 test: isTruthy,
5239 templates: (p = [])
5240 });
5241 })
5242 .on('tag:else', function () {
5243 elseCount++;
5244 p = _this.elseTemplates;
5245 })
5246 .on('tag:endunless', function () { this.stop(); })
5247 .on('template', function (tpl) {
5248 if (p !== _this.elseTemplates || elseCount === 1) {
5249 p.push(tpl);
5250 }
5251 })
5252 .on('end', function () { throw new Error("tag ".concat(tagToken.getText(), " not closed")); })
5253 .start();
5254 return _this;
5255 }
5256 default_1.prototype.render = function (ctx, emitter) {
5257 var r, _a, _b, _c, value, test_1, templates, v, e_1_1;
5258 var e_1, _d;
5259 return __generator(this, function (_e) {
5260 switch (_e.label) {
5261 case 0:
5262 r = this.liquid.renderer;
5263 _e.label = 1;
5264 case 1:
5265 _e.trys.push([1, 7, 8, 9]);
5266 _a = __values(this.branches), _b = _a.next();
5267 _e.label = 2;
5268 case 2:
5269 if (!!_b.done) return [3 /*break*/, 6];
5270 _c = _b.value, value = _c.value, test_1 = _c.test, templates = _c.templates;
5271 return [4 /*yield*/, value.value(ctx, ctx.opts.lenientIf)];
5272 case 3:
5273 v = _e.sent();
5274 if (!test_1(v, ctx)) return [3 /*break*/, 5];
5275 return [4 /*yield*/, r.renderTemplates(templates, ctx, emitter)];
5276 case 4:
5277 _e.sent();
5278 return [2 /*return*/];
5279 case 5:
5280 _b = _a.next();
5281 return [3 /*break*/, 2];
5282 case 6: return [3 /*break*/, 9];
5283 case 7:
5284 e_1_1 = _e.sent();
5285 e_1 = { error: e_1_1 };
5286 return [3 /*break*/, 9];
5287 case 8:
5288 try {
5289 if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
5290 }
5291 finally { if (e_1) throw e_1.error; }
5292 return [7 /*endfinally*/];
5293 case 9: return [4 /*yield*/, r.renderTemplates(this.elseTemplates, ctx, emitter)];
5294 case 10:
5295 _e.sent();
5296 return [2 /*return*/];
5297 }
5298 });
5299 };
5300 return default_1;
5301 }(Tag));
5302
5303 var default_1$g = /** @class */ (function (_super) {
5304 __extends(default_1, _super);
5305 function default_1() {
5306 return _super !== null && _super.apply(this, arguments) || this;
5307 }
5308 default_1.prototype.render = function (ctx, emitter) {
5309 emitter['break'] = true;
5310 };
5311 return default_1;
5312 }(Tag));
5313
5314 var default_1$h = /** @class */ (function (_super) {
5315 __extends(default_1, _super);
5316 function default_1() {
5317 return _super !== null && _super.apply(this, arguments) || this;
5318 }
5319 default_1.prototype.render = function (ctx, emitter) {
5320 emitter['continue'] = true;
5321 };
5322 return default_1;
5323 }(Tag));
5324
5325 var default_1$i = /** @class */ (function (_super) {
5326 __extends(default_1, _super);
5327 function default_1(token, remainTokens, liquid) {
5328 var _this = _super.call(this, token, remainTokens, liquid) || this;
5329 _this.tokenizer.skipBlank();
5330 if (!_this.tokenizer.end()) {
5331 _this.value = new Value(_this.tokenizer.readFilteredValue(), _this.liquid);
5332 }
5333 return _this;
5334 }
5335 default_1.prototype.render = function (ctx, emitter) {
5336 var val;
5337 return __generator(this, function (_a) {
5338 switch (_a.label) {
5339 case 0:
5340 if (!this.value)
5341 return [2 /*return*/];
5342 return [4 /*yield*/, this.value.value(ctx, false)];
5343 case 1:
5344 val = _a.sent();
5345 emitter.write(val);
5346 return [2 /*return*/];
5347 }
5348 });
5349 };
5350 return default_1;
5351 }(Tag));
5352
5353 var default_1$j = /** @class */ (function (_super) {
5354 __extends(default_1, _super);
5355 function default_1(token, remainTokens, liquid) {
5356 var _this = _super.call(this, token, remainTokens, liquid) || this;
5357 var tokens = _this.tokenizer.readLiquidTagTokens(_this.liquid.options);
5358 _this.templates = _this.liquid.parser.parseTokens(tokens);
5359 return _this;
5360 }
5361 default_1.prototype.render = function (ctx, emitter) {
5362 return __generator(this, function (_a) {
5363 switch (_a.label) {
5364 case 0: return [4 /*yield*/, this.liquid.renderer.renderTemplates(this.templates, ctx, emitter)];
5365 case 1:
5366 _a.sent();
5367 return [2 /*return*/];
5368 }
5369 });
5370 };
5371 return default_1;
5372 }(Tag));
5373
5374 var default_1$k = /** @class */ (function (_super) {
5375 __extends(default_1, _super);
5376 function default_1(tagToken, remainTokens, liquid) {
5377 var _this = _super.call(this, tagToken, remainTokens, liquid) || this;
5378 if (tagToken.args.search(/\n\s*[^#\s]/g) !== -1) {
5379 throw new Error('every line of an inline comment must start with a \'#\' character');
5380 }
5381 return _this;
5382 }
5383 default_1.prototype.render = function () { };
5384 return default_1;
5385 }(Tag));
5386
5387 var tags = {
5388 assign: default_1,
5389 'for': default_1$1,
5390 capture: default_1$2,
5391 'case': default_1$3,
5392 comment: default_1$4,
5393 include: default_1$6,
5394 render: default_1$5,
5395 decrement: default_1$7,
5396 increment: default_1$a,
5397 cycle: default_1$8,
5398 'if': default_1$9,
5399 layout: default_1$b,
5400 block: default_1$c,
5401 raw: default_1$d,
5402 tablerow: default_1$e,
5403 unless: default_1$f,
5404 'break': default_1$g,
5405 'continue': default_1$h,
5406 echo: default_1$i,
5407 liquid: default_1$j,
5408 '#': default_1$k
5409 };
5410
5411 var Liquid = /** @class */ (function () {
5412 function Liquid(opts) {
5413 if (opts === void 0) { opts = {}; }
5414 var _this = this;
5415 this.renderer = new Render();
5416 this.filters = {};
5417 this.tags = {};
5418 this.options = normalize(opts);
5419 this.parser = new Parser(this);
5420 forOwn(tags, function (conf, name) { return _this.registerTag(name, conf); });
5421 forOwn(filters, function (handler, name) { return _this.registerFilter(name, handler); });
5422 }
5423 Liquid.prototype.parse = function (html, filepath) {
5424 return this.parser.parse(html, filepath);
5425 };
5426 Liquid.prototype._render = function (tpl, scope, renderOptions) {
5427 var ctx = scope instanceof Context ? scope : new Context(scope, this.options, renderOptions);
5428 return this.renderer.renderTemplates(tpl, ctx);
5429 };
5430 Liquid.prototype.render = function (tpl, scope, renderOptions) {
5431 return __awaiter(this, void 0, void 0, function () {
5432 return __generator(this, function (_a) {
5433 return [2 /*return*/, toPromise(this._render(tpl, scope, __assign(__assign({}, renderOptions), { sync: false })))];
5434 });
5435 });
5436 };
5437 Liquid.prototype.renderSync = function (tpl, scope, renderOptions) {
5438 return toValueSync(this._render(tpl, scope, __assign(__assign({}, renderOptions), { sync: true })));
5439 };
5440 Liquid.prototype.renderToNodeStream = function (tpl, scope, renderOptions) {
5441 if (renderOptions === void 0) { renderOptions = {}; }
5442 var ctx = new Context(scope, this.options, renderOptions);
5443 return this.renderer.renderTemplatesToNodeStream(tpl, ctx);
5444 };
5445 Liquid.prototype._parseAndRender = function (html, scope, renderOptions) {
5446 var tpl = this.parse(html);
5447 return this._render(tpl, scope, renderOptions);
5448 };
5449 Liquid.prototype.parseAndRender = function (html, scope, renderOptions) {
5450 return __awaiter(this, void 0, void 0, function () {
5451 return __generator(this, function (_a) {
5452 return [2 /*return*/, toPromise(this._parseAndRender(html, scope, __assign(__assign({}, renderOptions), { sync: false })))];
5453 });
5454 });
5455 };
5456 Liquid.prototype.parseAndRenderSync = function (html, scope, renderOptions) {
5457 return toValueSync(this._parseAndRender(html, scope, __assign(__assign({}, renderOptions), { sync: true })));
5458 };
5459 Liquid.prototype._parsePartialFile = function (file, sync, currentFile) {
5460 return this.parser.parseFile(file, sync, LookupType.Partials, currentFile);
5461 };
5462 Liquid.prototype._parseLayoutFile = function (file, sync, currentFile) {
5463 return this.parser.parseFile(file, sync, LookupType.Layouts, currentFile);
5464 };
5465 Liquid.prototype._parseFile = function (file, sync, lookupType, currentFile) {
5466 return this.parser.parseFile(file, sync, lookupType, currentFile);
5467 };
5468 Liquid.prototype.parseFile = function (file, lookupType) {
5469 return __awaiter(this, void 0, void 0, function () {
5470 return __generator(this, function (_a) {
5471 return [2 /*return*/, toPromise(this.parser.parseFile(file, false, lookupType))];
5472 });
5473 });
5474 };
5475 Liquid.prototype.parseFileSync = function (file, lookupType) {
5476 return toValueSync(this.parser.parseFile(file, true, lookupType));
5477 };
5478 Liquid.prototype._renderFile = function (file, ctx, renderFileOptions) {
5479 var templates;
5480 return __generator(this, function (_a) {
5481 switch (_a.label) {
5482 case 0: return [4 /*yield*/, this._parseFile(file, renderFileOptions.sync, renderFileOptions.lookupType)];
5483 case 1:
5484 templates = (_a.sent());
5485 return [4 /*yield*/, this._render(templates, ctx, renderFileOptions)];
5486 case 2: return [2 /*return*/, _a.sent()];
5487 }
5488 });
5489 };
5490 Liquid.prototype.renderFile = function (file, ctx, renderFileOptions) {
5491 return __awaiter(this, void 0, void 0, function () {
5492 return __generator(this, function (_a) {
5493 return [2 /*return*/, toPromise(this._renderFile(file, ctx, __assign(__assign({}, renderFileOptions), { sync: false })))];
5494 });
5495 });
5496 };
5497 Liquid.prototype.renderFileSync = function (file, ctx, renderFileOptions) {
5498 return toValueSync(this._renderFile(file, ctx, __assign(__assign({}, renderFileOptions), { sync: true })));
5499 };
5500 Liquid.prototype.renderFileToNodeStream = function (file, scope, renderOptions) {
5501 return __awaiter(this, void 0, void 0, function () {
5502 var templates;
5503 return __generator(this, function (_a) {
5504 switch (_a.label) {
5505 case 0: return [4 /*yield*/, this.parseFile(file)];
5506 case 1:
5507 templates = _a.sent();
5508 return [2 /*return*/, this.renderToNodeStream(templates, scope, renderOptions)];
5509 }
5510 });
5511 });
5512 };
5513 Liquid.prototype._evalValue = function (str, scope) {
5514 var value = new Value(str, this);
5515 var ctx = scope instanceof Context ? scope : new Context(scope, this.options);
5516 return value.value(ctx);
5517 };
5518 Liquid.prototype.evalValue = function (str, scope) {
5519 return __awaiter(this, void 0, void 0, function () {
5520 return __generator(this, function (_a) {
5521 return [2 /*return*/, toPromise(this._evalValue(str, scope))];
5522 });
5523 });
5524 };
5525 Liquid.prototype.evalValueSync = function (str, scope) {
5526 return toValueSync(this._evalValue(str, scope));
5527 };
5528 Liquid.prototype.registerFilter = function (name, filter) {
5529 this.filters[name] = filter;
5530 };
5531 Liquid.prototype.registerTag = function (name, tag) {
5532 this.tags[name] = isFunction(tag) ? tag : createTagClass(tag);
5533 };
5534 Liquid.prototype.plugin = function (plugin) {
5535 return plugin.call(this, Liquid);
5536 };
5537 Liquid.prototype.express = function () {
5538 var self = this; // eslint-disable-line
5539 var firstCall = true;
5540 return function (filePath, ctx, callback) {
5541 var _a, _b, _c;
5542 if (firstCall) {
5543 firstCall = false;
5544 var dirs = normalizeDirectoryList(this.root);
5545 (_a = self.options.root).unshift.apply(_a, __spreadArray([], __read(dirs), false));
5546 (_b = self.options.layouts).unshift.apply(_b, __spreadArray([], __read(dirs), false));
5547 (_c = self.options.partials).unshift.apply(_c, __spreadArray([], __read(dirs), false));
5548 }
5549 self.renderFile(filePath, ctx).then(function (html) { return callback(null, html); }, callback);
5550 };
5551 };
5552 return Liquid;
5553 }());
5554
5555 /* istanbul ignore file */
5556 var version = '10.14.0';
5557
5558 exports.AssertionError = AssertionError;
5559 exports.AssignTag = default_1;
5560 exports.BlockTag = default_1$c;
5561 exports.BreakTag = default_1$g;
5562 exports.CaptureTag = default_1$2;
5563 exports.CaseTag = default_1$3;
5564 exports.CommentTag = default_1$4;
5565 exports.Context = Context;
5566 exports.ContinueTag = default_1$h;
5567 exports.CycleTag = default_1$8;
5568 exports.DecrementTag = default_1$7;
5569 exports.Drop = Drop;
5570 exports.EchoTag = default_1$i;
5571 exports.Expression = Expression;
5572 exports.Filter = Filter;
5573 exports.ForTag = default_1$1;
5574 exports.Hash = Hash;
5575 exports.IfTag = default_1$9;
5576 exports.IncludeTag = default_1$6;
5577 exports.IncrementTag = default_1$a;
5578 exports.InlineCommentTag = default_1$k;
5579 exports.LayoutTag = default_1$b;
5580 exports.Liquid = Liquid;
5581 exports.LiquidError = LiquidError;
5582 exports.LiquidTag = default_1$j;
5583 exports.Output = Output;
5584 exports.ParseError = ParseError;
5585 exports.ParseStream = ParseStream;
5586 exports.RawTag = default_1$d;
5587 exports.RenderError = RenderError;
5588 exports.RenderTag = default_1$5;
5589 exports.TablerowTag = default_1$e;
5590 exports.Tag = Tag;
5591 exports.TagToken = TagToken;
5592 exports.TimezoneDate = TimezoneDate;
5593 exports.Token = Token;
5594 exports.TokenizationError = TokenizationError;
5595 exports.Tokenizer = Tokenizer;
5596 exports.TypeGuards = typeGuards;
5597 exports.UndefinedVariableError = UndefinedVariableError;
5598 exports.UnlessTag = default_1$f;
5599 exports.Value = Value;
5600 exports.assert = assert;
5601 exports.createTrie = createTrie;
5602 exports.defaultOperators = defaultOperators;
5603 exports.defaultOptions = defaultOptions;
5604 exports.evalQuotedToken = evalQuotedToken;
5605 exports.evalToken = evalToken;
5606 exports.filters = filters;
5607 exports.isFalsy = isFalsy;
5608 exports.isTruthy = isTruthy;
5609 exports.tags = tags;
5610 exports.toPromise = toPromise;
5611 exports.toValue = toValue;
5612 exports.toValueSync = toValueSync;
5613 exports.version = version;
5614
5615 Object.defineProperty(exports, '__esModule', { value: true });
5616
5617})));
5618//# sourceMappingURL=liquid.browser.umd.js.map