@diplodoc/liquid 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/lib/frontmatter.d.ts +6 -0
- package/lib/frontmatter.js +80 -0
- package/lib/frontmatter.js.map +1 -0
- package/lib/getObject.d.ts +2 -0
- package/lib/getObject.js +14 -0
- package/lib/getObject.js.map +1 -0
- package/lib/liquid/conditions.d.ts +6 -0
- package/lib/liquid/conditions.js +243 -0
- package/lib/liquid/conditions.js.map +1 -0
- package/lib/liquid/cycles.d.ts +4 -0
- package/lib/liquid/cycles.js +154 -0
- package/lib/liquid/cycles.js.map +1 -0
- package/lib/liquid/errors.d.ts +3 -0
- package/lib/liquid/errors.js +13 -0
- package/lib/liquid/errors.js.map +1 -0
- package/lib/liquid/evaluation.d.ts +4 -0
- package/lib/liquid/evaluation.js +143 -0
- package/lib/liquid/evaluation.js.map +1 -0
- package/lib/liquid/filters.d.ts +9 -0
- package/lib/liquid/filters.js +22 -0
- package/lib/liquid/filters.js.map +1 -0
- package/lib/liquid/index.d.ts +15 -0
- package/lib/liquid/index.js +132 -0
- package/lib/liquid/index.js.map +1 -0
- package/lib/liquid/legacyConditions.d.ts +4 -0
- package/lib/liquid/legacyConditions.js +174 -0
- package/lib/liquid/legacyConditions.js.map +1 -0
- package/lib/liquid/lexical.d.ts +16 -0
- package/lib/liquid/lexical.js +83 -0
- package/lib/liquid/lexical.js.map +1 -0
- package/lib/liquid/services/argv.d.ts +16 -0
- package/lib/liquid/services/argv.js +17 -0
- package/lib/liquid/services/argv.js.map +1 -0
- package/lib/liquid/sourceMap.d.ts +19 -0
- package/lib/liquid/sourceMap.js +51 -0
- package/lib/liquid/sourceMap.js.map +1 -0
- package/lib/liquid/substitutions.d.ts +2 -0
- package/lib/liquid/substitutions.js +56 -0
- package/lib/liquid/substitutions.js.map +1 -0
- package/lib/liquid/utils.d.ts +8 -0
- package/lib/liquid/utils.js +24 -0
- package/lib/liquid/utils.js.map +1 -0
- package/lib/log.d.ts +18 -0
- package/lib/log.js +54 -0
- package/lib/log.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.evalExp = exports.NoValue = void 0;
|
|
30
|
+
const getObject_1 = __importDefault(require("../getObject"));
|
|
31
|
+
const log_1 = require("../log");
|
|
32
|
+
const lexical = __importStar(require("./lexical"));
|
|
33
|
+
const filters_1 = __importDefault(require("./filters"));
|
|
34
|
+
const errors_1 = require("./errors");
|
|
35
|
+
const operators = {
|
|
36
|
+
'==': ((l, r) => l === r),
|
|
37
|
+
'!=': ((l, r) => l !== r),
|
|
38
|
+
'>': ((l, r) => l !== null && r !== null && l > r),
|
|
39
|
+
'<': ((l, r) => l !== null && r !== null && l < r),
|
|
40
|
+
'>=': ((l, r) => l !== null && r !== null && l >= r),
|
|
41
|
+
'<=': ((l, r) => l !== null && r !== null && l <= r),
|
|
42
|
+
contains: ((l, r) => l !== null && r !== null && l.includes(r)),
|
|
43
|
+
and: ((l, r) => isTruthy(l) && isTruthy(r)),
|
|
44
|
+
or: ((l, r) => isTruthy(l) || isTruthy(r)),
|
|
45
|
+
'|': ((l, filter, exp) => {
|
|
46
|
+
try {
|
|
47
|
+
return filter(l);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
if (!filter) {
|
|
51
|
+
throw new errors_1.SkippedEvalError('Cannot apply an unsupported filter', exp);
|
|
52
|
+
}
|
|
53
|
+
throw new errors_1.SkippedEvalError('There are some problems with the filter', exp);
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
56
|
+
'.': ((l, r, exp) => {
|
|
57
|
+
const parsed = lexical.getParsedMethod(r);
|
|
58
|
+
try {
|
|
59
|
+
if (!parsed) {
|
|
60
|
+
throw new Error();
|
|
61
|
+
}
|
|
62
|
+
const { name, args } = parsed;
|
|
63
|
+
return l[name](...args);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
if (!l) {
|
|
67
|
+
throw new errors_1.SkippedEvalError(`Cannot apply the function '${name}' on an undefined variable`, exp);
|
|
68
|
+
}
|
|
69
|
+
throw new errors_1.SkippedEvalError('There are some problems with the function', exp);
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
};
|
|
73
|
+
exports.NoValue = Symbol('NoValue');
|
|
74
|
+
function evalValue(originStr, scope, strict) {
|
|
75
|
+
const str = originStr && originStr.trim();
|
|
76
|
+
if (!str) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
if (lexical.isLiteral(str)) {
|
|
80
|
+
return lexical.parseLiteral(str);
|
|
81
|
+
}
|
|
82
|
+
if (lexical.isVariable(str)) {
|
|
83
|
+
return (0, getObject_1.default)(str, scope, strict ? exports.NoValue : undefined);
|
|
84
|
+
}
|
|
85
|
+
throw new TypeError(`cannot eval '${str}' as value`);
|
|
86
|
+
}
|
|
87
|
+
function isTruthy(val) {
|
|
88
|
+
return !isFalsy(val);
|
|
89
|
+
}
|
|
90
|
+
function isFalsy(val) {
|
|
91
|
+
return val === false || undefined === val || val === null;
|
|
92
|
+
}
|
|
93
|
+
const operatorREs = lexical.operators.map((op) => new RegExp(`^(${lexical.quoteBalanced.source})(${op.source})(${lexical.quoteBalanced.source})$`));
|
|
94
|
+
function evalExp(exp, scope, strict = false) {
|
|
95
|
+
if (Object.getOwnPropertyNames(filters_1.default).includes(exp.trim())) {
|
|
96
|
+
return filters_1.default[exp.trim()];
|
|
97
|
+
}
|
|
98
|
+
if (lexical.isSupportedMethod(exp)) {
|
|
99
|
+
return exp;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
for (let i = 0; i < operatorREs.length; i++) {
|
|
103
|
+
const operatorRE = operatorREs[i];
|
|
104
|
+
const match = exp.match(operatorRE);
|
|
105
|
+
if (match) {
|
|
106
|
+
const operator = match[2].trim();
|
|
107
|
+
if (operator === '.' && !lexical.isSupportedMethod(match[3].trim())) {
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
const op = operators[operator];
|
|
111
|
+
const l = evalExp(match[1], scope, strict);
|
|
112
|
+
const r = evalExp(match[3], scope, strict);
|
|
113
|
+
if (l === exports.NoValue || r === exports.NoValue) {
|
|
114
|
+
return exports.NoValue;
|
|
115
|
+
}
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
117
|
+
return op(l, r, exp);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const match = exp.match(lexical.rangeLine);
|
|
121
|
+
if (match) {
|
|
122
|
+
const low = Number(evalValue(match[1], scope, strict));
|
|
123
|
+
const high = Number(evalValue(match[2], scope, strict));
|
|
124
|
+
const range = [];
|
|
125
|
+
for (let j = low; j <= high; j++) {
|
|
126
|
+
range.push(j);
|
|
127
|
+
}
|
|
128
|
+
return range;
|
|
129
|
+
}
|
|
130
|
+
return evalValue(exp, scope, strict);
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
if (e instanceof errors_1.SkippedEvalError) {
|
|
134
|
+
log_1.log.warn(`Skip error: ${e}`);
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
log_1.log.error(`Error: ${e}`);
|
|
138
|
+
}
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
exports.evalExp = evalExp;
|
|
142
|
+
exports.default = (exp, scope, strict = false) => Boolean(evalExp(exp, scope, strict));
|
|
143
|
+
//# sourceMappingURL=evaluation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluation.js","sourceRoot":"","sources":["../../src/transform/liquid/evaluation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAAqC;AACrC,gCAA2B;AAE3B,mDAAqC;AACrC,wDAAgC;AAChC,qCAA0C;AAY1C,MAAM,SAAS,GAAwD;IACnE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAa;IACrC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAa;IACrC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,CAAa;IAC9D,GAA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AAED,kBAAe,CAAC,GAAW,EAAE,KAA8B,EAAE,MAAM,GAAG,KAAK,EAAE,EAAE,CAC3E,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function length(input: string): number;
|
|
2
|
+
export declare function capitalize(input: string): string;
|
|
3
|
+
export declare function escapeMarkdown(input: string): string;
|
|
4
|
+
declare const index: {
|
|
5
|
+
length: typeof length;
|
|
6
|
+
capitalize: typeof capitalize;
|
|
7
|
+
escapeMarkdown: typeof escapeMarkdown;
|
|
8
|
+
};
|
|
9
|
+
export default index;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.escapeMarkdown = exports.capitalize = exports.length = void 0;
|
|
4
|
+
function length(input) {
|
|
5
|
+
return input.length;
|
|
6
|
+
}
|
|
7
|
+
exports.length = length;
|
|
8
|
+
function capitalize(input) {
|
|
9
|
+
return String(input).replace(/^([a-z])/, (_m, chr) => chr.toUpperCase());
|
|
10
|
+
}
|
|
11
|
+
exports.capitalize = capitalize;
|
|
12
|
+
function escapeMarkdown(input) {
|
|
13
|
+
return String(input).replace(/([\\`*_{}[\]()#+\-.!|])/g, '\\$1');
|
|
14
|
+
}
|
|
15
|
+
exports.escapeMarkdown = escapeMarkdown;
|
|
16
|
+
const index = {
|
|
17
|
+
length,
|
|
18
|
+
capitalize,
|
|
19
|
+
escapeMarkdown,
|
|
20
|
+
};
|
|
21
|
+
exports.default = index;
|
|
22
|
+
//# sourceMappingURL=filters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filters.js","sourceRoot":"","sources":["../../src/transform/liquid/filters.ts"],"names":[],"mappings":";;;AAAA,SAAgB,MAAM,CAAC,KAAa;IAChC,OAAO,KAAK,CAAC,MAAM,CAAC;AACxB,CAAC;AAFD,wBAEC;AAED,SAAgB,UAAU,CAAC,KAAa;IACpC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;AAC7E,CAAC;AAFD,gCAEC;AAED,SAAgB,cAAc,CAAC,KAAa;IACxC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAAC;AACrE,CAAC;AAFD,wCAEC;AAED,MAAM,KAAK,GAAG;IACV,MAAM;IACN,UAAU;IACV,cAAc;CACjB,CAAC;AAEF,kBAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Dictionary } from 'lodash';
|
|
2
|
+
import { ArgvSettings } from './services/argv';
|
|
3
|
+
declare function liquidSnippet<B extends boolean = false, C = B extends false ? string : {
|
|
4
|
+
output: string;
|
|
5
|
+
sourceMap: Dictionary<string>;
|
|
6
|
+
}>(originInput: string, vars: Record<string, unknown>, path?: string, settings?: ArgvSettings & {
|
|
7
|
+
withSourceMap?: B;
|
|
8
|
+
}): C;
|
|
9
|
+
declare function liquidDocument<B extends boolean = false, C = B extends false ? string : {
|
|
10
|
+
output: string;
|
|
11
|
+
sourceMap: Dictionary<string>;
|
|
12
|
+
}>(input: string, vars: Record<string, unknown>, path?: string, settings?: ArgvSettings & {
|
|
13
|
+
withSourceMap?: B;
|
|
14
|
+
}): C;
|
|
15
|
+
export { liquidDocument, liquidSnippet };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.liquidSnippet = exports.liquidDocument = void 0;
|
|
7
|
+
const cloneDeepWith_1 = __importDefault(require("lodash/cloneDeepWith"));
|
|
8
|
+
const frontmatter_1 = require("../frontmatter");
|
|
9
|
+
const substitutions_1 = __importDefault(require("./substitutions"));
|
|
10
|
+
const sourceMap_1 = require("./sourceMap");
|
|
11
|
+
const cycles_1 = __importDefault(require("./cycles"));
|
|
12
|
+
const conditions_1 = __importDefault(require("./conditions"));
|
|
13
|
+
const argv_1 = __importDefault(require("./services/argv"));
|
|
14
|
+
const fence = '```';
|
|
15
|
+
const find = (open, close, string, index) => {
|
|
16
|
+
const start = string.indexOf(open, index);
|
|
17
|
+
const end = start > -1 ? string.indexOf(close, start + open.length) : -1;
|
|
18
|
+
return [start, end];
|
|
19
|
+
};
|
|
20
|
+
const replace = (open, close, value, string) => {
|
|
21
|
+
let result = '';
|
|
22
|
+
let carriage = 0;
|
|
23
|
+
let [start, end] = find(open, close, string, carriage);
|
|
24
|
+
while (start > -1 && end > -1) {
|
|
25
|
+
const fragment = string.slice(start + open.length, end);
|
|
26
|
+
result += string.slice(carriage, start) + open + value(fragment) + close;
|
|
27
|
+
carriage = end + close.length;
|
|
28
|
+
[start, end] = find(open, close, string, carriage);
|
|
29
|
+
}
|
|
30
|
+
result += string.slice(carriage);
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
function saveCode(str, vars, codes, path, substitutions) {
|
|
34
|
+
return replace(fence, fence, (code) => {
|
|
35
|
+
const codeWithVars = substitutions ? (0, substitutions_1.default)(code, vars, path) : code;
|
|
36
|
+
const index = codes.push(codeWithVars) - 1;
|
|
37
|
+
/* Keep the same count of lines to avoid transformation of the source map */
|
|
38
|
+
const codeLines = codeWithVars.split('\n');
|
|
39
|
+
const emptyLines = codeLines.length > 1 ? '\n'.repeat(codeLines.length) : '';
|
|
40
|
+
return `${index}${emptyLines}`;
|
|
41
|
+
}, str);
|
|
42
|
+
}
|
|
43
|
+
function repairCode(str, codes) {
|
|
44
|
+
return replace(fence, fence, (code) => codes[Number(code)], str);
|
|
45
|
+
}
|
|
46
|
+
function liquidSnippet(originInput, vars, path, settings) {
|
|
47
|
+
const { cycles = true, conditions = true, substitutions = true, conditionsInCode = false, useLegacyConditions = false, keepNotVar = false, withSourceMap, } = settings || {};
|
|
48
|
+
argv_1.default.init({
|
|
49
|
+
cycles,
|
|
50
|
+
conditions,
|
|
51
|
+
substitutions,
|
|
52
|
+
conditionsInCode,
|
|
53
|
+
useLegacyConditions,
|
|
54
|
+
keepNotVar,
|
|
55
|
+
withSourceMap,
|
|
56
|
+
});
|
|
57
|
+
const codes = [];
|
|
58
|
+
let output = conditionsInCode
|
|
59
|
+
? originInput
|
|
60
|
+
: saveCode(originInput, vars, codes, path, substitutions);
|
|
61
|
+
let sourceMap = {};
|
|
62
|
+
if (withSourceMap) {
|
|
63
|
+
const lines = output.split('\n');
|
|
64
|
+
sourceMap = lines.reduce((acc, _cur, index) => {
|
|
65
|
+
acc[index + 1] = index + 1;
|
|
66
|
+
return acc;
|
|
67
|
+
}, {});
|
|
68
|
+
}
|
|
69
|
+
if (cycles) {
|
|
70
|
+
output = (0, cycles_1.default)(output, vars, path, { sourceMap });
|
|
71
|
+
}
|
|
72
|
+
if (conditions) {
|
|
73
|
+
const strict = conditions === 'strict';
|
|
74
|
+
output = (0, conditions_1.default)(output, vars, path, { sourceMap, strict, useLegacyConditions });
|
|
75
|
+
}
|
|
76
|
+
if (substitutions) {
|
|
77
|
+
output = (0, substitutions_1.default)(output, vars, path);
|
|
78
|
+
}
|
|
79
|
+
if (!conditionsInCode && typeof output === 'string') {
|
|
80
|
+
output = repairCode(output, codes);
|
|
81
|
+
}
|
|
82
|
+
codes.length = 0;
|
|
83
|
+
if (withSourceMap) {
|
|
84
|
+
return {
|
|
85
|
+
output,
|
|
86
|
+
sourceMap: (0, sourceMap_1.prepareSourceMap)(sourceMap),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return output;
|
|
90
|
+
}
|
|
91
|
+
exports.liquidSnippet = liquidSnippet;
|
|
92
|
+
function linesCount(content) {
|
|
93
|
+
let count = 1, index = -1;
|
|
94
|
+
while ((index = content.indexOf('\n', index + 1)) > -1) {
|
|
95
|
+
count++;
|
|
96
|
+
}
|
|
97
|
+
return count;
|
|
98
|
+
}
|
|
99
|
+
function liquidDocument(input, vars, path, settings) {
|
|
100
|
+
const [frontMatter, strippedContent] = (0, frontmatter_1.extractFrontMatter)(input, path);
|
|
101
|
+
const liquidedFrontMatter = (0, cloneDeepWith_1.default)(frontMatter, (value) => typeof value === 'string'
|
|
102
|
+
? liquidSnippet(value, vars, path, Object.assign(Object.assign({}, settings), { withSourceMap: false }))
|
|
103
|
+
: undefined);
|
|
104
|
+
const liquidedResult = liquidSnippet(strippedContent, vars, path, settings);
|
|
105
|
+
const liquidedContent = typeof liquidedResult === 'object' ? liquidedResult.output : liquidedResult;
|
|
106
|
+
const output = (0, frontmatter_1.composeFrontMatter)(liquidedFrontMatter, liquidedContent);
|
|
107
|
+
if (typeof liquidedResult === 'object') {
|
|
108
|
+
const inputLinesCount = linesCount(input);
|
|
109
|
+
const outputLinesCount = linesCount(output);
|
|
110
|
+
const contentLinesCount = linesCount(strippedContent);
|
|
111
|
+
const contentLinesDiff = linesCount(liquidedContent) - contentLinesCount;
|
|
112
|
+
const fullLinesDiff = outputLinesCount - inputLinesCount;
|
|
113
|
+
// Always >= 0
|
|
114
|
+
const sourceOffset = inputLinesCount - contentLinesCount;
|
|
115
|
+
// Content lines diff already counted in source map
|
|
116
|
+
const resultOffset = fullLinesDiff - contentLinesDiff;
|
|
117
|
+
liquidedResult.sourceMap = Object.fromEntries(Object.entries(liquidedResult.sourceMap).map(([lineInResult, lineInSource]) => [
|
|
118
|
+
(Number(lineInResult) + resultOffset).toString(),
|
|
119
|
+
(Number(lineInSource) + sourceOffset).toString(),
|
|
120
|
+
]));
|
|
121
|
+
}
|
|
122
|
+
// typeof check for better inference; the catch is that return of liquidSnippet can be an
|
|
123
|
+
// object even with source maps off, see `substitutions.test.ts`
|
|
124
|
+
return ((settings === null || settings === void 0 ? void 0 : settings.withSourceMap) && typeof liquidedResult === 'object'
|
|
125
|
+
? {
|
|
126
|
+
output,
|
|
127
|
+
sourceMap: liquidedResult.sourceMap,
|
|
128
|
+
}
|
|
129
|
+
: output);
|
|
130
|
+
}
|
|
131
|
+
exports.liquidDocument = liquidDocument;
|
|
132
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transform/liquid/index.ts"],"names":[],"mappings":";;;;;;AAEA,yEAAiD;AAEjD,gDAAsE;AAEtE,oEAAiD;AACjD,2CAA6C;AAC7C,sDAAmC;AACnC,8DAA2C;AAC3C,2DAA0D;AAE1D,MAAM,KAAK,GAAG,KAAK,CAAC;AAEpB,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,MAAc,EAAE,KAAa,EAAE,EAAE;IACxE,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1C,MAAM,GAAG,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEzE,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,CACZ,IAAY,EACZ,KAAa,EACb,KAAiC,EACjC,MAAc,EAChB,EAAE;IACA,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAEvD,OAAO,KAAK,GAAG,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,EAAE;QAC3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AAC;KACL;IAED,yFAAyF;IACzF,gEAAgE;IAChE,OAAO,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,aAAa,KAAI,OAAO,cAAc,KAAK,QAAQ;QACjE,CAAC,CAAC;YACI,MAAM;YACN,SAAS,EAAE,cAAc,CAAC,SAAS;SACtC;QACH,CAAC,CAAC,MAAM,CAAiB,CAAC;AAClC,CAAC;AAGO,wCAAc"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const chalk_1 = require("chalk");
|
|
6
|
+
const log_1 = require("../log");
|
|
7
|
+
const evaluation_1 = __importDefault(require("./evaluation"));
|
|
8
|
+
const lexical_1 = require("./lexical");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const sourceMap_1 = require("./sourceMap");
|
|
11
|
+
function changeSourceMap({ firstLineNumber, lastLineNumber, resFirstLineNumber, resLastLineNumber, linesTotal, sourceMap, }) {
|
|
12
|
+
if (!sourceMap) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const { getSourceMapValue, moveLines, removeLines } = (0, sourceMap_1.createSourceMapApi)(sourceMap);
|
|
16
|
+
let offsetRestLines;
|
|
17
|
+
if (resFirstLineNumber) {
|
|
18
|
+
// Move condition's content to the top
|
|
19
|
+
const offsetContentLines = firstLineNumber - resFirstLineNumber;
|
|
20
|
+
moveLines({
|
|
21
|
+
start: resFirstLineNumber,
|
|
22
|
+
end: resLastLineNumber - 1,
|
|
23
|
+
offset: offsetContentLines,
|
|
24
|
+
withReplace: true,
|
|
25
|
+
});
|
|
26
|
+
// Remove the rest lines of the condition block
|
|
27
|
+
removeLines({ start: firstLineNumber, end: resFirstLineNumber - 1 });
|
|
28
|
+
removeLines({ start: resLastLineNumber, end: lastLineNumber });
|
|
29
|
+
// Calculate an offset of the rest lines
|
|
30
|
+
offsetRestLines = getSourceMapValue(resLastLineNumber - 1) - lastLineNumber;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// Remove the whole condition block
|
|
34
|
+
removeLines({ start: firstLineNumber, end: lastLineNumber });
|
|
35
|
+
// Calculate offset of the rest lines
|
|
36
|
+
offsetRestLines = firstLineNumber - lastLineNumber - 1;
|
|
37
|
+
}
|
|
38
|
+
// Offset the rest lines
|
|
39
|
+
moveLines({ start: lastLineNumber + 1, end: linesTotal, offset: offsetRestLines });
|
|
40
|
+
}
|
|
41
|
+
function getElseProp({ elses }, propName, index = 0) {
|
|
42
|
+
if (!elses.length || index >= elses.length) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return elses[index][propName];
|
|
46
|
+
}
|
|
47
|
+
function inlineConditions({ ifTag, vars, content, match, lastIndex, sourceMap, linesTotal }) {
|
|
48
|
+
let res = '';
|
|
49
|
+
const firstLineNumber = (0, sourceMap_1.getLineNumber)(content, ifTag.startPos);
|
|
50
|
+
const lastLineNumber = (0, sourceMap_1.getLineNumber)(content, lastIndex);
|
|
51
|
+
let resFirstLineNumber = 0;
|
|
52
|
+
let resLastLineNumber = 0;
|
|
53
|
+
if ((0, evaluation_1.default)(ifTag.condition, vars)) {
|
|
54
|
+
const ifRawLastIndex = ifTag.startPos + ifTag.ifRaw.length;
|
|
55
|
+
const contentLastIndex = getElseProp(ifTag, 'startPos') || match.index;
|
|
56
|
+
res = content.substring(ifRawLastIndex, contentLastIndex);
|
|
57
|
+
resFirstLineNumber = (0, sourceMap_1.getLineNumber)(content, ifRawLastIndex + 1);
|
|
58
|
+
resLastLineNumber = (0, sourceMap_1.getLineNumber)(content, contentLastIndex + 1);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
ifTag.elses.some(({ condition, startPos, raw }, index) => {
|
|
62
|
+
const isTruthy = !condition || (0, evaluation_1.default)(condition, vars);
|
|
63
|
+
if (isTruthy) {
|
|
64
|
+
const elseRawLastIndex = startPos + raw.length;
|
|
65
|
+
const contentLastIndex = getElseProp(ifTag, 'startPos', index + 1) || match.index;
|
|
66
|
+
res = content.substring(elseRawLastIndex, contentLastIndex);
|
|
67
|
+
resFirstLineNumber = (0, sourceMap_1.getLineNumber)(content, elseRawLastIndex + 1);
|
|
68
|
+
resLastLineNumber = (0, sourceMap_1.getLineNumber)(content, contentLastIndex + 1);
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
changeSourceMap({
|
|
75
|
+
firstLineNumber,
|
|
76
|
+
lastLineNumber,
|
|
77
|
+
resFirstLineNumber,
|
|
78
|
+
resLastLineNumber,
|
|
79
|
+
linesTotal,
|
|
80
|
+
sourceMap,
|
|
81
|
+
});
|
|
82
|
+
const preparedLeftContent = (0, utils_1.getPreparedLeftContent)({
|
|
83
|
+
content,
|
|
84
|
+
tagStartPos: ifTag.startPos,
|
|
85
|
+
tagContent: res,
|
|
86
|
+
});
|
|
87
|
+
let shift = 0;
|
|
88
|
+
if (res === '' &&
|
|
89
|
+
preparedLeftContent[preparedLeftContent.length - 1] === '\n' &&
|
|
90
|
+
content[lastIndex] === '\n') {
|
|
91
|
+
shift = 1;
|
|
92
|
+
}
|
|
93
|
+
if (res !== '') {
|
|
94
|
+
if (res[0] === '\n') {
|
|
95
|
+
res = res.substring(1);
|
|
96
|
+
}
|
|
97
|
+
res = (0, utils_1.removeIndentBlock)(res);
|
|
98
|
+
if (res[res.length - 1] === '\n') {
|
|
99
|
+
res = res.slice(0, -1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const leftPart = preparedLeftContent + res;
|
|
103
|
+
return {
|
|
104
|
+
result: leftPart + content.substring(lastIndex + shift),
|
|
105
|
+
idx: leftPart.length,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
module.exports = function legacyConditions(originInput, vars, path, settings) {
|
|
109
|
+
const sourceMap = (settings === null || settings === void 0 ? void 0 : settings.sourceMap) || {};
|
|
110
|
+
const R_LIQUID = /({%-?([\s\S]*?)-?%})/g;
|
|
111
|
+
let match;
|
|
112
|
+
const tagStack = [];
|
|
113
|
+
let input = originInput;
|
|
114
|
+
let linesTotal = originInput.split('\n').length;
|
|
115
|
+
while ((match = R_LIQUID.exec(input)) !== null) {
|
|
116
|
+
if (!match[1]) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const tagMatch = match[2].trim().match(lexical_1.tagLine);
|
|
120
|
+
if (!tagMatch) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const [type, args] = tagMatch.slice(1);
|
|
124
|
+
switch (type) {
|
|
125
|
+
case 'if':
|
|
126
|
+
tagStack.push({
|
|
127
|
+
isOpen: true,
|
|
128
|
+
condition: args,
|
|
129
|
+
startPos: match.index,
|
|
130
|
+
ifRaw: match[1],
|
|
131
|
+
elses: [],
|
|
132
|
+
});
|
|
133
|
+
break;
|
|
134
|
+
case 'else':
|
|
135
|
+
tagStack[tagStack.length - 1].elses.push({
|
|
136
|
+
startPos: match.index,
|
|
137
|
+
raw: match[1],
|
|
138
|
+
});
|
|
139
|
+
break;
|
|
140
|
+
case 'elsif':
|
|
141
|
+
tagStack[tagStack.length - 1].elses.push({
|
|
142
|
+
condition: args,
|
|
143
|
+
startPos: match.index,
|
|
144
|
+
raw: match[1],
|
|
145
|
+
});
|
|
146
|
+
break;
|
|
147
|
+
case 'endif': {
|
|
148
|
+
const ifTag = tagStack.pop();
|
|
149
|
+
if (!ifTag) {
|
|
150
|
+
log_1.log.error(`If block must be opened before close${path ? ` in ${(0, chalk_1.bold)(path)}` : ''}`);
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
const { idx, result } = inlineConditions({
|
|
154
|
+
ifTag,
|
|
155
|
+
vars,
|
|
156
|
+
content: input,
|
|
157
|
+
match,
|
|
158
|
+
lastIndex: R_LIQUID.lastIndex,
|
|
159
|
+
sourceMap,
|
|
160
|
+
linesTotal,
|
|
161
|
+
});
|
|
162
|
+
R_LIQUID.lastIndex = idx;
|
|
163
|
+
input = result;
|
|
164
|
+
linesTotal = result.split('\n').length;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (tagStack.length !== 0) {
|
|
170
|
+
log_1.log.error(`Condition block must be closed${path ? ` in ${(0, chalk_1.bold)(path)}` : ''}`);
|
|
171
|
+
}
|
|
172
|
+
return input;
|
|
173
|
+
};
|
|
174
|
+
//# sourceMappingURL=legacyConditions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacyConditions.js","sourceRoot":"","sources":["../../src/transform/liquid/legacyConditions.ts"],"names":[],"mappings":";;;;AAAA,iCAA2B;AAE3B,gCAA2B;AAE3B,8DAAmC;AACnC,uCAAkC;AAClC,mCAAkE;AAClE,2CAA8D;AAW9D,SAAS,eAAe,CAAC,EACrB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,SAAS,GACH;IACN,IAAI,CAAC,SAAS,EAAE;QACZ,OAAO;KACV;IAED,MAAM,EAAC,iBAAiB,EAAE,SAAS,EAAE,WAAW,EAAC,GAAG,IAAA,8BAAkB,EAAC,SAAS,CAAC,CAAC;IAElF,IAAI,eAAe,CAAC;IACpB,IAAI,kBAAkB,EAAE;QACpB,sCAAsC;QACtC,MAAM,kBAAkB,GAAG,eAAe,GAAG,kBAAkB,CAAC;QAChE,SAAS,CAAC;YACN,KAAK,EAAE,kBAAkB;YACzB,GAAG,EAAE,iBAAiB,GAAG,CAAC;YAC1B,MAAM,EAAE,kBAAkB;YAC1B,WAAW,EAAE,IAAI;SACpB,CAAC,CAAC;QAEH,+CAA+C;QAC/C,WAAW,CAAC,EAAC,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,kBAAkB,GAAG,CAAC,EAAC,CAAC,CAAC;QACnE,WAAW,C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AC,CAAC;iBAChB,CAAC,CAAC;gBACH,MAAM;YACV,KAAK,OAAO,CAAC,CAAC;gBACV,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC;gBAE7B,IAAI,CAAC,KAAK,EAAE;oBACR,SAAG,CAAC,KAAK,CACL,uCAAuC,IAAI,CAAC,CAAC,CAAC,OAAO,IAAA,YAAI,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAC3E,CAAC;oBACF,MAAM;iBACT;gBAED,MAAM,EAAC,GAAG,EAAE,MAAM,EAAC,GAAG,gBAAgB,CAAC;oBACnC,KAAK;oBACL,IAAI;oBACJ,OAAO,EAAE,KAAK;oBACd,KAAK;oBACL,SAAS,EAAE,QAAQ,CAAC,SAAS;oBAC7B,SAAS;oBACT,UAAU;iBACb,CAAC,CAAC;gBACH,QAAQ,CAAC,SAAS,GAAG,GAAG,CAAC;gBACzB,KAAK,GAAG,MAAM,CAAC;gBACf,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;gBAEvC,MAAM;aACT;SACJ;KACJ;IAED,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,SAAG,CAAC,KAAK,CAAC,iCAAiC,IAAI,CAAC,CAAC,CAAC,OAAO,IAAA,YAAI,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;KACjF;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const quoteBalanced: RegExp;
|
|
2
|
+
export declare const vars: RegExp;
|
|
3
|
+
export declare const singleVariable: RegExp;
|
|
4
|
+
export declare const variable: RegExp;
|
|
5
|
+
export declare const tagLine: RegExp;
|
|
6
|
+
export declare const rangeLine: RegExp;
|
|
7
|
+
export declare const operators: RegExp[];
|
|
8
|
+
export declare const isSupportedMethod: (exp: string) => boolean;
|
|
9
|
+
export declare const getParsedMethod: (exp: String) => {
|
|
10
|
+
name: string;
|
|
11
|
+
args: string[];
|
|
12
|
+
} | null;
|
|
13
|
+
export declare const isLiteral: (str: string) => boolean;
|
|
14
|
+
export declare const isVariable: (str: string) => boolean;
|
|
15
|
+
export declare const isSingleVariable: (str: string) => boolean;
|
|
16
|
+
export declare function parseLiteral(str: string): string | number | boolean;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseLiteral = exports.isSingleVariable = exports.isVariable = exports.isLiteral = exports.getParsedMethod = exports.isSupportedMethod = exports.operators = exports.rangeLine = exports.tagLine = exports.variable = exports.singleVariable = exports.vars = exports.quoteBalanced = void 0;
|
|
4
|
+
// quote related
|
|
5
|
+
const singleQuoted = /'[^']*'/;
|
|
6
|
+
const doubleQuoted = /"[^"]*"/;
|
|
7
|
+
const quoted = new RegExp(`${singleQuoted.source}|${doubleQuoted.source}`);
|
|
8
|
+
exports.quoteBalanced = new RegExp(`(?:${quoted.source}|[^'"])*`);
|
|
9
|
+
exports.vars = /((not_var)?({{2}([. \w-|(),]+)}{2}))/gm;
|
|
10
|
+
exports.singleVariable = /^{{2}([. \w-|(),]+)}{2}$/;
|
|
11
|
+
// basic types
|
|
12
|
+
const number = /-?\d+\.?\d*|\.?\d+/;
|
|
13
|
+
const bool = /true|false/;
|
|
14
|
+
// property access
|
|
15
|
+
const identifier = /[\w-|]+[?]?/;
|
|
16
|
+
const subscript = new RegExp(`\\[(?:${quoted.source}|[\\w-\\.]+)\\]`);
|
|
17
|
+
const literal = new RegExp(`(?:${quoted.source}|${bool.source}|${number.source})`);
|
|
18
|
+
exports.variable = new RegExp(`${identifier.source}(?:\\.${identifier.source}|${subscript.source})*`);
|
|
19
|
+
// range related
|
|
20
|
+
const rangeLimit = new RegExp(`(?:${exports.variable.source}|${number.source})`);
|
|
21
|
+
const rangeCapture = new RegExp(`\\((${rangeLimit.source})\\.\\.(${rangeLimit.source})\\)`);
|
|
22
|
+
// full match
|
|
23
|
+
exports.tagLine = new RegExp(`^\\s*(${identifier.source})\\s*([\\s\\S]*)\\s*$`);
|
|
24
|
+
const literalLine = new RegExp(`^${literal.source}$`, 'i');
|
|
25
|
+
const variableLine = new RegExp(`^${exports.variable.source}$`);
|
|
26
|
+
const numberLine = new RegExp(`^${number.source}$`);
|
|
27
|
+
const boolLine = new RegExp(`^${bool.source}$`, 'i');
|
|
28
|
+
const quotedLine = new RegExp(`^${quoted.source}$`);
|
|
29
|
+
exports.rangeLine = new RegExp(`^${rangeCapture.source}$`);
|
|
30
|
+
exports.operators = [
|
|
31
|
+
/\s+or\s+/,
|
|
32
|
+
/\s+and\s+/,
|
|
33
|
+
/[=]=|!=|<=|>=|<|>|\s+contains\s+/,
|
|
34
|
+
/\s+\|\s+/,
|
|
35
|
+
/\s+\|/,
|
|
36
|
+
/\|\s+/,
|
|
37
|
+
/\./,
|
|
38
|
+
];
|
|
39
|
+
const prepareArgsForMethods = {
|
|
40
|
+
slice: (args) => args.map((arg) => Number(arg)),
|
|
41
|
+
};
|
|
42
|
+
const supportedMethods = Object.keys(prepareArgsForMethods);
|
|
43
|
+
const supportedMethodsRE = new RegExp(`^(${supportedMethods.join('\\|')})\\(([^)]*)\\)$`);
|
|
44
|
+
const isSupportedMethod = (exp) => {
|
|
45
|
+
return supportedMethodsRE.test(exp);
|
|
46
|
+
};
|
|
47
|
+
exports.isSupportedMethod = isSupportedMethod;
|
|
48
|
+
const getParsedMethod = (exp) => {
|
|
49
|
+
const match = exp.match(supportedMethodsRE);
|
|
50
|
+
if (!match) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const name = match[1];
|
|
54
|
+
const args = match[2].split(/[\s,]+/);
|
|
55
|
+
return {
|
|
56
|
+
name,
|
|
57
|
+
args,
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
exports.getParsedMethod = getParsedMethod;
|
|
61
|
+
const isLiteral = (str) => literalLine.test(str);
|
|
62
|
+
exports.isLiteral = isLiteral;
|
|
63
|
+
const isVariable = (str) => variableLine.test(str);
|
|
64
|
+
exports.isVariable = isVariable;
|
|
65
|
+
const isSingleVariable = (str) => exports.singleVariable.test(str);
|
|
66
|
+
exports.isSingleVariable = isSingleVariable;
|
|
67
|
+
function parseLiteral(str) {
|
|
68
|
+
let res = str.match(numberLine);
|
|
69
|
+
if (res) {
|
|
70
|
+
return Number(str);
|
|
71
|
+
}
|
|
72
|
+
res = str.match(boolLine);
|
|
73
|
+
if (res) {
|
|
74
|
+
return str.toLowerCase() === 'true';
|
|
75
|
+
}
|
|
76
|
+
res = str.match(quotedLine);
|
|
77
|
+
if (res) {
|
|
78
|
+
return str.slice(1, -1);
|
|
79
|
+
}
|
|
80
|
+
throw new TypeError(`cannot parse '${str}' as literal`);
|
|
81
|
+
}
|
|
82
|
+
exports.parseLiteral = parseLiteral;
|
|
83
|
+
//# sourceMappingURL=lexical.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lexical.js","sourceRoot":"","sources":["../../src/transform/liquid/lexical.ts"],"names":[],"mappings":";;;AAAA,gBAAgB;AAChB,MAAM,YAAY,GAAG,SAAS,CAAC;AAC/B,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,MAAM,IAAI,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;AAC9D,QAAA,aAAa,GAAG,IAAI,MAAM,CAAC,MAAM,MAAM,CAAC,MAAM,UAAU,CAAC,CAAC;AAE1D,QAAA,IAAI,GAAG,wCAAwC,CAAC;AAChD,QAAA,cAAc,GAAG,0BAA0B,CAAC;AAEzD,cAAc;AACd,MAAM,MAAM,GAAG,oBAAoB,CAAC;AACpC,MAAM,IAAI,GAAG,YAAY,CAAC;AAE1B,kBAAkB;AAClB,MAAM,UAAU,GAAG,aAAa,CAAC;A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