@diplodoc/liquid 0.0.0-rc-fix-new-line-202509031344
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/conditions.d.ts +3 -0
- package/lib/conditions.js +223 -0
- package/lib/conditions.js.map +1 -0
- package/lib/cycles.d.ts +3 -0
- package/lib/cycles.js +128 -0
- package/lib/cycles.js.map +1 -0
- package/lib/errors.d.ts +3 -0
- package/lib/errors.js +16 -0
- package/lib/errors.js.map +1 -0
- package/lib/frontmatter.d.ts +5 -0
- package/lib/frontmatter.js +63 -0
- package/lib/frontmatter.js.map +1 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +68 -0
- package/lib/index.js.map +1 -0
- package/lib/sourcemap.d.ts +20 -0
- package/lib/sourcemap.js +130 -0
- package/lib/sourcemap.js.map +1 -0
- package/lib/substitutions.d.ts +2 -0
- package/lib/substitutions.js +51 -0
- package/lib/substitutions.js.map +1 -0
- package/lib/syntax/evaluate.d.ts +3 -0
- package/lib/syntax/evaluate.js +149 -0
- package/lib/syntax/evaluate.js.map +1 -0
- package/lib/syntax/filters.d.ts +3 -0
- package/lib/syntax/filters.js +15 -0
- package/lib/syntax/filters.js.map +1 -0
- package/lib/syntax/lexical.d.ts +16 -0
- package/lib/syntax/lexical.js +83 -0
- package/lib/syntax/lexical.js.map +1 -0
- package/lib/types.d.ts +18 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts +19 -0
- package/lib/utils.js +89 -0
- package/lib/utils.js.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 YANDEX LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
[](https://www.npmjs.org/package/@diplodoc/liquid)
|
|
2
|
+
|
|
3
|
+
[@diplodoc/liquid](https://www.npmjs.com/package/@diplodoc/liquid) is a small and fast implementation of basic liquid syntax.
|
|
4
|
+
|
|
5
|
+
## Installation {#install}
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm i @diplodoc/liquid
|
|
9
|
+
```
|
|
@@ -0,0 +1,223 @@
|
|
|
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.applyConditions = applyConditions;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const lexical_1 = require("./syntax/lexical");
|
|
9
|
+
const evaluate_1 = require("./syntax/evaluate");
|
|
10
|
+
function resourcemap(source, ifTag, ifCon, sourcemap) {
|
|
11
|
+
const lines = sourcemap.lines(source);
|
|
12
|
+
const sourcel = sourcemap.location(ifTag.start + 1, ifTag.end - 1, lines);
|
|
13
|
+
const isInlineTag = sourcel.start === sourcel.end;
|
|
14
|
+
if (isInlineTag || ifTag === ifCon) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (ifCon) {
|
|
18
|
+
const resultl = sourcemap.location(ifCon.start, ifCon.end, lines);
|
|
19
|
+
sourcemap.patch({
|
|
20
|
+
delete: [
|
|
21
|
+
{ start: resultl.end + 1, end: sourcel.end },
|
|
22
|
+
{ start: sourcel.start, end: resultl.start - 1 },
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
sourcemap.patch({ delete: [sourcel] });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function headLinebreak(raw) {
|
|
31
|
+
const match = raw.match(/^([^{]+){.*/);
|
|
32
|
+
return match ? match[1] : '';
|
|
33
|
+
}
|
|
34
|
+
function tailLinebreak(raw) {
|
|
35
|
+
const match = raw.match(/.*}(\s*\r?\n)$/);
|
|
36
|
+
return match ? match[1].replace(/\r\n/g, '\n') : '';
|
|
37
|
+
}
|
|
38
|
+
function trimResult(content, ifTag, ifCon) {
|
|
39
|
+
if (!ifCon) {
|
|
40
|
+
const head = headLinebreak(ifTag.rawStart);
|
|
41
|
+
const tail = tailLinebreak(ifTag.rawEnd);
|
|
42
|
+
let rest = head + tail;
|
|
43
|
+
if (rest !== head && rest !== tail) {
|
|
44
|
+
// We have extra line break, if condition was placed on individual line
|
|
45
|
+
rest = rest.replace('\n', '');
|
|
46
|
+
}
|
|
47
|
+
return ifTag.isBlock ? '\n' : rest;
|
|
48
|
+
}
|
|
49
|
+
content = content.substring(ifCon.start, ifCon.end);
|
|
50
|
+
if (ifTag.isBlock) {
|
|
51
|
+
return trimBlockResult(content, ifCon);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return trimInlineResult(content, ifTag);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function trimBlockResult(content, ifCon) {
|
|
58
|
+
const head = headLinebreak(ifCon.rawStart);
|
|
59
|
+
if (head) {
|
|
60
|
+
content = '\n' + content;
|
|
61
|
+
}
|
|
62
|
+
const tail = tailLinebreak(ifCon.rawEnd);
|
|
63
|
+
if (tail) {
|
|
64
|
+
content = content + '\n';
|
|
65
|
+
}
|
|
66
|
+
return content;
|
|
67
|
+
}
|
|
68
|
+
function trimInlineResult(content, ifTag) {
|
|
69
|
+
const head = headLinebreak(ifTag.rawStart);
|
|
70
|
+
if (head) {
|
|
71
|
+
content = head + content;
|
|
72
|
+
}
|
|
73
|
+
const tail = tailLinebreak(ifTag.rawEnd);
|
|
74
|
+
if (tail) {
|
|
75
|
+
content = content + tail;
|
|
76
|
+
}
|
|
77
|
+
return content;
|
|
78
|
+
}
|
|
79
|
+
class IfTag {
|
|
80
|
+
constructor() {
|
|
81
|
+
this.conditions = [];
|
|
82
|
+
}
|
|
83
|
+
get start() {
|
|
84
|
+
if (!this.conditions.length) {
|
|
85
|
+
return -1;
|
|
86
|
+
}
|
|
87
|
+
const first = this.conditions[0];
|
|
88
|
+
return first.start - first.rawStart.length;
|
|
89
|
+
}
|
|
90
|
+
get end() {
|
|
91
|
+
if (!this.conditions.length) {
|
|
92
|
+
return -1;
|
|
93
|
+
}
|
|
94
|
+
const last = this.conditions[this.conditions.length - 1];
|
|
95
|
+
return last.end + last.rawEnd.length;
|
|
96
|
+
}
|
|
97
|
+
get rawStart() {
|
|
98
|
+
if (!this.conditions.length) {
|
|
99
|
+
return '';
|
|
100
|
+
}
|
|
101
|
+
const first = this.conditions[0];
|
|
102
|
+
return first.rawStart;
|
|
103
|
+
}
|
|
104
|
+
get rawEnd() {
|
|
105
|
+
if (!this.conditions.length) {
|
|
106
|
+
return '';
|
|
107
|
+
}
|
|
108
|
+
const last = this.conditions[this.conditions.length - 1];
|
|
109
|
+
return last.rawEnd;
|
|
110
|
+
}
|
|
111
|
+
get isBlock() {
|
|
112
|
+
const first = this.conditions[0];
|
|
113
|
+
const last = this.conditions[this.conditions.length - 1];
|
|
114
|
+
return tailLinebreak(first.rawStart) && headLinebreak(last.rawEnd);
|
|
115
|
+
}
|
|
116
|
+
*[Symbol.iterator]() {
|
|
117
|
+
for (const condition of this.conditions) {
|
|
118
|
+
yield condition;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
openCondition(raw, expr, start) {
|
|
122
|
+
this.closeCondition(raw, start);
|
|
123
|
+
this.conditions.push({
|
|
124
|
+
rawStart: raw,
|
|
125
|
+
start: start + raw.length,
|
|
126
|
+
expr,
|
|
127
|
+
});
|
|
128
|
+
return start + raw.length - tailLinebreak(raw).length;
|
|
129
|
+
}
|
|
130
|
+
closeCondition(raw, end) {
|
|
131
|
+
const condition = this.conditions[this.conditions.length - 1];
|
|
132
|
+
if (condition) {
|
|
133
|
+
condition.rawEnd = raw;
|
|
134
|
+
condition.end = end;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function inlineConditions(content, vars, ifTag) {
|
|
139
|
+
const { conditions = true, keepConditionSyntaxOnTrue = false } = this.settings;
|
|
140
|
+
let ifCon = null;
|
|
141
|
+
for (const condition of ifTag) {
|
|
142
|
+
const value = evaluate_1.evaluate.call(this, condition.expr, vars, conditions === 'strict');
|
|
143
|
+
if (condition.expr &&
|
|
144
|
+
(value === evaluate_1.NoValue || (keepConditionSyntaxOnTrue && value === true))) {
|
|
145
|
+
return {
|
|
146
|
+
result: content,
|
|
147
|
+
// Fix offset for next matches.
|
|
148
|
+
// There can be some significant linebreak and spaces.
|
|
149
|
+
lastIndex: ifTag.end - tailLinebreak(ifTag.rawEnd).length,
|
|
150
|
+
ifCon: ifTag,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
if (!condition.expr || value) {
|
|
154
|
+
ifCon = condition;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const start = content.slice(0, ifTag.start);
|
|
159
|
+
const end = content.slice(ifTag.end);
|
|
160
|
+
const result = trimResult(content, ifTag, ifCon);
|
|
161
|
+
return {
|
|
162
|
+
result: start + result + end,
|
|
163
|
+
lastIndex: start.length + result.length - tailLinebreak(ifTag.rawEnd).length,
|
|
164
|
+
ifCon,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function applyConditions(input, vars, sourcemap) {
|
|
168
|
+
const { path } = this;
|
|
169
|
+
const tagStack = [];
|
|
170
|
+
// Consumes all between curly braces
|
|
171
|
+
// and all closest upon to first linebreak before and after braces.
|
|
172
|
+
const R_LIQUID = /((?:\r?\n[\t ]*)?{%-?([\s\S]*?)-?%}(?:[\t ]*\r?\n)?)/g;
|
|
173
|
+
let match;
|
|
174
|
+
while ((match = R_LIQUID.exec(input)) !== null) {
|
|
175
|
+
if (!match[1]) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const tagMatch = match[2].trim().match(lexical_1.tagLine);
|
|
179
|
+
if (!tagMatch) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const [type, args] = tagMatch.slice(1);
|
|
183
|
+
switch (type) {
|
|
184
|
+
case 'if': {
|
|
185
|
+
const tag = new IfTag();
|
|
186
|
+
R_LIQUID.lastIndex = tag.openCondition(match[1], args, match.index);
|
|
187
|
+
tagStack.push(tag);
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case 'elsif':
|
|
191
|
+
case 'else': {
|
|
192
|
+
const tag = tagStack[tagStack.length - 1];
|
|
193
|
+
R_LIQUID.lastIndex = tag.openCondition(match[1], args, match.index);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case 'endif': {
|
|
197
|
+
const ifTag = tagStack.pop();
|
|
198
|
+
if (!ifTag) {
|
|
199
|
+
// TODO(3y3): make lint rule
|
|
200
|
+
this.logger.error(`If block must be opened before close${path ? ` in ${chalk_1.default.bold(path)}` : ''}`);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
ifTag.closeCondition(match[1], match.index);
|
|
204
|
+
const { result, lastIndex, ifCon } = inlineConditions.call(this, input, vars, ifTag);
|
|
205
|
+
if (sourcemap) {
|
|
206
|
+
resourcemap(input, ifTag, ifCon, sourcemap);
|
|
207
|
+
}
|
|
208
|
+
R_LIQUID.lastIndex = lastIndex;
|
|
209
|
+
input = result;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
default:
|
|
213
|
+
// This is not condition.
|
|
214
|
+
// Step back last linebreaks to match them on next condition
|
|
215
|
+
R_LIQUID.lastIndex -= tailLinebreak(match[1]).length;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (tagStack.length !== 0) {
|
|
219
|
+
this.logger.error(`Condition block must be closed${path ? ` in ${chalk_1.default.bold(path)}` : ''}`);
|
|
220
|
+
}
|
|
221
|
+
return input;
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=conditions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditions.js","sourceRoot":"","sources":["../src/conditions.ts"],"names":[],"mappings":";;;;;AAqOA,0CA+EC;AAjTD,kDAA0B;AAE1B,8CAAyC;AACzC,gDAAoD;AASpD,SAAS,WAAW,CAChB,MAAc,EACd,KAAkB,EAClB,KAAyB,EACzB,SAAoB;IAEpB,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IAC1E,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,KAA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IAChG,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
package/lib/cycles.d.ts
ADDED
package/lib/cycles.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
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.applyCycles = applyCycles;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const lexical_1 = require("./syntax/lexical");
|
|
9
|
+
const evaluate_1 = require("./syntax/evaluate");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
const index_1 = require("./index");
|
|
12
|
+
function resourcemap(source, template, result, forTag, sourcemap) {
|
|
13
|
+
const lines = sourcemap.lines(source);
|
|
14
|
+
if (!forTag.multiline) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
sourcemap.patch({
|
|
18
|
+
delete: [
|
|
19
|
+
sourcemap.location(forTag.startPos, forTag.contentStart - 1, lines),
|
|
20
|
+
sourcemap.location(forTag.contentEnd + 1, forTag.endPos, lines),
|
|
21
|
+
],
|
|
22
|
+
replace: [
|
|
23
|
+
[
|
|
24
|
+
sourcemap.location(forTag.contentStart, forTag.contentStart, lines).start,
|
|
25
|
+
template,
|
|
26
|
+
result,
|
|
27
|
+
],
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function inlineConditions(content, vars, forTag, sourcemap) {
|
|
32
|
+
const forTemplate = content.substring(forTag.contentStart, forTag.contentEnd);
|
|
33
|
+
let collection = evaluate_1.evaluate.call(this, forTag.collectionName, vars);
|
|
34
|
+
if (!collection || !Array.isArray(collection)) {
|
|
35
|
+
collection = [];
|
|
36
|
+
this.logger.error(`${chalk_1.default.bold(forTag.collectionName)} is undefined or not iterable`);
|
|
37
|
+
}
|
|
38
|
+
const results = collection.map((item) => {
|
|
39
|
+
const newVars = { ...vars, [forTag.variableName]: item };
|
|
40
|
+
return index_1.liquidSnippet.call(this, forTemplate, newVars).replace(/ +$/, '');
|
|
41
|
+
});
|
|
42
|
+
let res = results.join(forTag.multiline ? '\n' : '');
|
|
43
|
+
if (sourcemap) {
|
|
44
|
+
resourcemap(content, forTemplate, res, forTag, sourcemap);
|
|
45
|
+
}
|
|
46
|
+
const preparedLeftContent = (0, utils_1.getPreparedLeftContent)({
|
|
47
|
+
content,
|
|
48
|
+
tagStartPos: forTag.startPos,
|
|
49
|
+
tagContent: res,
|
|
50
|
+
});
|
|
51
|
+
let shift = 0;
|
|
52
|
+
if (res === '' &&
|
|
53
|
+
preparedLeftContent[preparedLeftContent.length - 1] === '\n' &&
|
|
54
|
+
content[forTag.endPos] === '\n') {
|
|
55
|
+
shift = 1;
|
|
56
|
+
}
|
|
57
|
+
if (res[0] === ' ') {
|
|
58
|
+
res = res.substring(1);
|
|
59
|
+
}
|
|
60
|
+
const leftPart = preparedLeftContent + res;
|
|
61
|
+
return {
|
|
62
|
+
result: leftPart + content.substring(forTag.endPos + shift),
|
|
63
|
+
idx: leftPart.length,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function applyCycles(input, vars, sourcemap) {
|
|
67
|
+
var _a, _b, _c;
|
|
68
|
+
const { path } = this;
|
|
69
|
+
const R_LIQUID = /{%-?(?<for>\s*for[^}]+?)-?%}\n?|\n?{%-?(?<endfor>\s*endfor[^}]+?)-?%}/g;
|
|
70
|
+
const FOR_SYNTAX = new RegExp(`(\\w+)\\s+in\\s+(${lexical_1.variable.source})`);
|
|
71
|
+
let match;
|
|
72
|
+
const tagStack = [];
|
|
73
|
+
let countSkippedInnerTags = 0;
|
|
74
|
+
while ((match = R_LIQUID.exec(input))) {
|
|
75
|
+
switch (true) {
|
|
76
|
+
case Boolean((_a = match.groups) === null || _a === void 0 ? void 0 : _a.for): {
|
|
77
|
+
const tagMatch = (_b = match.groups) === null || _b === void 0 ? void 0 : _b.for.match(lexical_1.tagLine);
|
|
78
|
+
if (!tagMatch) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const [args] = tagMatch.slice(2);
|
|
82
|
+
if (tagStack.length) {
|
|
83
|
+
countSkippedInnerTags += 1;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
const matches = args.match(FOR_SYNTAX);
|
|
87
|
+
if (!matches) {
|
|
88
|
+
this.logger.error(`Incorrect syntax in if condition${path ? ` in ${chalk_1.default.bold(path)}` : ''}`);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
const [variableName, collectionName] = matches.slice(1);
|
|
92
|
+
tagStack.push({
|
|
93
|
+
item: args,
|
|
94
|
+
variableName,
|
|
95
|
+
collectionName,
|
|
96
|
+
startPos: match.index,
|
|
97
|
+
endPos: -1,
|
|
98
|
+
contentStart: R_LIQUID.lastIndex,
|
|
99
|
+
contentEnd: -1,
|
|
100
|
+
multiline: match[0].endsWith('\n'),
|
|
101
|
+
});
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
case Boolean((_c = match.groups) === null || _c === void 0 ? void 0 : _c.endfor): {
|
|
105
|
+
if (countSkippedInnerTags > 0) {
|
|
106
|
+
countSkippedInnerTags -= 1;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
const forTag = tagStack.pop();
|
|
110
|
+
if (!forTag) {
|
|
111
|
+
this.logger.error(`For block must be opened before close${path ? ` in ${chalk_1.default.bold(path)}` : ''}`);
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
forTag.endPos = R_LIQUID.lastIndex;
|
|
115
|
+
forTag.contentEnd = match.index;
|
|
116
|
+
const { idx, result } = inlineConditions.call(this, input, vars, forTag, sourcemap);
|
|
117
|
+
R_LIQUID.lastIndex = idx;
|
|
118
|
+
input = result;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (tagStack.length !== 0) {
|
|
124
|
+
this.logger.error(`For block must be closed${path ? ` in ${chalk_1.default.bold(path)}` : ''}`);
|
|
125
|
+
}
|
|
126
|
+
return input;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=cycles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cycles.js","sourceRoot":"","sources":["../src/cycles.ts"],"names":[],"mappings":";;;;;AAuGA,kCAkFC;AAtLD,kDAA0B;AAE1B,8CAAmD;AACnD,gDAA2C;AAC3C,mCAA+C;AAE/C,mCAAsC;AAEtC,SAAS,WAAW,CAChB,MAAc,EACd,QAAgB,EAChB,MAAc,EACd,MAAW,EACX,SAAoB;IAEpB,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAEtC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACpB,OAAO;IACX,CAAC;IAED,SAAS,CAAC,KAAK,CAAC;QACZ,MAAM,EAAE;YACJ,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,YAAY,GAAG,CAAC,EAAE,KAAK,CAAC;YACnE,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;SAClE;QACD,OAAO,EAAE;YACL;gBACI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,KAAK;gBACzE,QAAQ;gBACR,MAAM;aACT;SACJ;KACJ,CAAC,CAAC;AACP,CAAC;AAED,SAAS,gBAAgB,CAErB,OAAe,EACf,IAA6B,EAC7B,MAAW,EACX,SAAqB;IAErB,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAE9E,IAAI,UAAU,GAAG,mBAAQ,CAAC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;gBAED,MAAM,CAAC,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC;gBACnC,MAAM,CAAC,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC;gBAEhC,MAAM,EAAC,GAAG,EAAE,MAAM,EAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;gBAClF,QAAQ,CAAC,SAAS,GAAG,GAAG,CAAC;gBACzB,KAAK,GAAG,MAAM,CAAC;gBAEf,MAAM;YACV,CAAC;QACL,CAAC;IACL,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,IAAI,CAAC,CAAC,CAAC,OAAO,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1F,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
package/lib/errors.d.ts
ADDED
package/lib/errors.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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.SkippedEvalError = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
class SkippedEvalError extends Error {
|
|
9
|
+
constructor(message, exp) {
|
|
10
|
+
super();
|
|
11
|
+
this.name = 'SkippedEvalError';
|
|
12
|
+
this.message = `${message}: ${chalk_1.default.bold(exp)}`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.SkippedEvalError = SkippedEvalError;
|
|
16
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,MAAa,gBAAiB,SAAQ,KAAK;IACvC,YAAY,OAAe,EAAE,GAAW;QACpC,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,GAAG,OAAO,KAAK,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACpD,CAAC;CACJ;AAPD,4CAOC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type FrontMatter = {
|
|
2
|
+
[key: string]: unknown;
|
|
3
|
+
};
|
|
4
|
+
export declare const extractFrontMatter: (content: string, options?: {}) => [FrontMatter, string, string];
|
|
5
|
+
export declare const composeFrontMatter: (frontMatter: FrontMatter, strippedContent?: string) => string;
|
|
@@ -0,0 +1,63 @@
|
|
|
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.composeFrontMatter = exports.extractFrontMatter = void 0;
|
|
7
|
+
const js_yaml_1 = require("js-yaml");
|
|
8
|
+
const cloneDeepWith_1 = __importDefault(require("lodash/cloneDeepWith"));
|
|
9
|
+
const SEP = '---';
|
|
10
|
+
/**
|
|
11
|
+
* Temporary workaround to enable parsing YAML metadata from potentially
|
|
12
|
+
* Liquid-aware source files
|
|
13
|
+
* @param content Input string which could contain Liquid-style substitution syntax (which clashes with YAML
|
|
14
|
+
* object syntax)
|
|
15
|
+
* @returns String with `{}` escaped, ready to be parsed with `js-yaml`
|
|
16
|
+
*/
|
|
17
|
+
const escapeLiquid = (content) => content.replace(/{{/g, '(({{').replace(/}}/g, '}}))');
|
|
18
|
+
/**
|
|
19
|
+
* Inverse of a workaround defined above.
|
|
20
|
+
* @see `escapeLiquidSubstitutionSyntax`
|
|
21
|
+
* @param escapedContent Input string with `{}` escaped with backslashes
|
|
22
|
+
* @returns Unescaped string
|
|
23
|
+
*/
|
|
24
|
+
const unescapeLiquid = (escapedContent) => escapedContent.replace(/\(\({{/g, '{{').replace(/}}\)\)/g, '}}');
|
|
25
|
+
const matchMetadata = (content) => {
|
|
26
|
+
const rx = /^(?<open>[-]{3,} *\r?\n)(?<meta>[\s\S]+?)(?<close>\r?\n[-]{3,}(?: *\r?\n|$))/;
|
|
27
|
+
const match = rx.exec(content);
|
|
28
|
+
if (!match) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return match.groups;
|
|
32
|
+
};
|
|
33
|
+
const extractFrontMatter = (content, options = {}) => {
|
|
34
|
+
const matches = matchMetadata(content);
|
|
35
|
+
if (matches) {
|
|
36
|
+
const { open, close, meta } = matches;
|
|
37
|
+
const rawMeta = open + meta + close;
|
|
38
|
+
const strippedContent = content.slice(rawMeta.length);
|
|
39
|
+
const loadedData = (0, js_yaml_1.load)(escapeLiquid(meta), options);
|
|
40
|
+
if (!loadedData) {
|
|
41
|
+
return [{}, strippedContent, rawMeta];
|
|
42
|
+
}
|
|
43
|
+
return [
|
|
44
|
+
(0, cloneDeepWith_1.default)(loadedData, (v) => typeof v === 'string' ? unescapeLiquid(v) : undefined),
|
|
45
|
+
strippedContent,
|
|
46
|
+
rawMeta,
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
return [{}, content, ''];
|
|
50
|
+
};
|
|
51
|
+
exports.extractFrontMatter = extractFrontMatter;
|
|
52
|
+
const composeFrontMatter = (frontMatter, strippedContent = '') => {
|
|
53
|
+
const dumped = (0, js_yaml_1.dump)(frontMatter, { lineWidth: -1 }).trim();
|
|
54
|
+
// This empty object check is a bit naive
|
|
55
|
+
// The other option would be to check if all own fields are `undefined`,
|
|
56
|
+
// since we exploit passing in `undefined` to remove a field quite a bit
|
|
57
|
+
if (dumped === '{}') {
|
|
58
|
+
return strippedContent;
|
|
59
|
+
}
|
|
60
|
+
return `${SEP}\n${dumped}\n${SEP}\n${strippedContent}`;
|
|
61
|
+
};
|
|
62
|
+
exports.composeFrontMatter = composeFrontMatter;
|
|
63
|
+
//# sourceMappingURL=frontmatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../src/frontmatter.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAmC;AACnC,yEAAiD;AAMjD,MAAM,GAAG,GAAG,KAAK,CAAC;AAElB;;;;;;GAMG;AACH,MAAM,YAAY,GAAG,CAAC,OAAe,EAAU,EAAE,CAC7C,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,cAAc,GAAG,CAAC,cAAsB,EAAU,EAAE,CACtD,cAAc,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAErE,MAAM,aAAa,GAAG,CAAC,OAAe,EAAE,EAAE;IACtC,MAAM,EAAE,GAAG,8EAA8E,CAAC;IAC1F,MAAM,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAE/B,IAAI,CAAC,KAAK,EAAE,CAAC;QACT,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC,MAAqD,CAAC;AACvE,CAAC,CAAC;AAEK,MAAM,kBAAkB,GAAG,CAC9B,OAAe,EACf,OAAO,GAAG,EAAE,EACiB,EAAE;IAC/B,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IAEvC,IAAI,OAAO,EAAE,CAAC;QACV,MAAM,EAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAC,GAAG,OAAO,CAAC;QACpC,MAAM,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;QACpC,MAAM,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEtD,MAAM,UAAU,GAAG,IAAA,cAAI,EAAC,YAAY,CAAC,IAAI,CAAC,EAAE,OAAO,CAAgB,CAAC;QAEpE,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,OAAO,CAAC,EAAE,EAAE,eAAe,EAAE,OAAO,CAAC,CAAC;QAC1C,CAAC;QAED,OAAO;YACH,IAAA,uBAAa,EAAC,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CAC5B,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CACxD;YACD,eAAe;YACf,OAAO;SACV,CAAC;IACN,CAAC;IAED,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;AAC7B,CAAC,CAAC;AA3BW,QAAA,kBAAkB,sBA2B7B;AAEK,MAAM,kBAAkB,GAAG,CAAC,WAAwB,EAAE,eAAe,GAAG,EAAE,EAAE,EAAE;IACjF,MAAM,MAAM,GAAG,IAAA,cAAI,EAAC,WAAW,EAAE,EAAC,SAAS,EAAE,CAAC,CAAC,EAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAEzD,yCAAyC;IACzC,wEAAwE;IACxE,wEAAwE;IACxE,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAClB,OAAO,eAAe,CAAC;IAC3B,CAAC;IAED,OAAO,GAAG,GAAG,KAAK,MAAM,KAAK,GAAG,KAAK,eAAe,EAAE,CAAC;AAC3D,CAAC,CAAC;AAXW,QAAA,kBAAkB,sBAW7B"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LiquidContext, LiquidSettings, Logger } from './types';
|
|
2
|
+
import type { SourceMap } from './sourcemap';
|
|
3
|
+
export type { LiquidContext } from './types';
|
|
4
|
+
export { evaluate, NoValue } from './syntax/evaluate';
|
|
5
|
+
export { SourceMap } from './sourcemap';
|
|
6
|
+
export { composeFrontMatter, extractFrontMatter } from './frontmatter';
|
|
7
|
+
export declare function liquidSnippet(this: LiquidContext, input: string, vars: Record<string, unknown>, sourcemap?: SourceMap): string;
|
|
8
|
+
export declare function liquidJson(this: LiquidContext, json: object, vars: Record<string, unknown>): any;
|
|
9
|
+
export declare function liquidDocument(this: LiquidContext, input: string, vars: Record<string, unknown>, sourcemap?: SourceMap): string;
|
|
10
|
+
export declare function createContext(logger: Logger, settings?: Partial<LiquidSettings>): LiquidContext;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
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.extractFrontMatter = exports.composeFrontMatter = exports.SourceMap = exports.NoValue = exports.evaluate = void 0;
|
|
7
|
+
exports.liquidSnippet = liquidSnippet;
|
|
8
|
+
exports.liquidJson = liquidJson;
|
|
9
|
+
exports.liquidDocument = liquidDocument;
|
|
10
|
+
exports.createContext = createContext;
|
|
11
|
+
const cloneDeepWith_1 = __importDefault(require("lodash/cloneDeepWith"));
|
|
12
|
+
const frontmatter_1 = require("./frontmatter");
|
|
13
|
+
const substitutions_1 = require("./substitutions");
|
|
14
|
+
const cycles_1 = require("./cycles");
|
|
15
|
+
const conditions_1 = require("./conditions");
|
|
16
|
+
const utils_1 = require("./utils");
|
|
17
|
+
var evaluate_1 = require("./syntax/evaluate");
|
|
18
|
+
Object.defineProperty(exports, "evaluate", { enumerable: true, get: function () { return evaluate_1.evaluate; } });
|
|
19
|
+
Object.defineProperty(exports, "NoValue", { enumerable: true, get: function () { return evaluate_1.NoValue; } });
|
|
20
|
+
var sourcemap_1 = require("./sourcemap");
|
|
21
|
+
Object.defineProperty(exports, "SourceMap", { enumerable: true, get: function () { return sourcemap_1.SourceMap; } });
|
|
22
|
+
var frontmatter_2 = require("./frontmatter");
|
|
23
|
+
Object.defineProperty(exports, "composeFrontMatter", { enumerable: true, get: function () { return frontmatter_2.composeFrontMatter; } });
|
|
24
|
+
Object.defineProperty(exports, "extractFrontMatter", { enumerable: true, get: function () { return frontmatter_2.extractFrontMatter; } });
|
|
25
|
+
function liquidSnippet(input, vars, sourcemap) {
|
|
26
|
+
const { cycles = true, conditions = true, substitutions = true, conditionsInCode = false, } = this.settings;
|
|
27
|
+
const { saveCode, repairCode } = utils_1.codeUtils.call(this);
|
|
28
|
+
let output = input;
|
|
29
|
+
if (!conditionsInCode) {
|
|
30
|
+
output = saveCode(output, vars);
|
|
31
|
+
}
|
|
32
|
+
if (cycles) {
|
|
33
|
+
output = cycles_1.applyCycles.call(this, output, vars, sourcemap);
|
|
34
|
+
}
|
|
35
|
+
if (conditions) {
|
|
36
|
+
output = conditions_1.applyConditions.call(this, output, vars, sourcemap);
|
|
37
|
+
}
|
|
38
|
+
if (substitutions) {
|
|
39
|
+
output = substitutions_1.applySubstitutions.call(this, output, vars);
|
|
40
|
+
}
|
|
41
|
+
if (!conditionsInCode && typeof output === 'string') {
|
|
42
|
+
output = repairCode(output);
|
|
43
|
+
}
|
|
44
|
+
return output;
|
|
45
|
+
}
|
|
46
|
+
function liquidJson(json, vars) {
|
|
47
|
+
return (0, cloneDeepWith_1.default)(json, (value) => typeof value === 'string' ? liquidSnippet.call(this, value, vars) : undefined);
|
|
48
|
+
}
|
|
49
|
+
function liquidDocument(input, vars, sourcemap) {
|
|
50
|
+
const normalizedInput = input.replace(/\r\n/g, '\n');
|
|
51
|
+
const [frontMatter, strippedContent, rawFrontmatter] = (0, frontmatter_1.extractFrontMatter)(normalizedInput);
|
|
52
|
+
const liquidedFrontMatter = liquidJson.call(this, frontMatter, vars);
|
|
53
|
+
const composedFrontmatter = (0, frontmatter_1.composeFrontMatter)(liquidedFrontMatter);
|
|
54
|
+
if (sourcemap && rawFrontmatter.length) {
|
|
55
|
+
sourcemap.patch({
|
|
56
|
+
replace: [[1, rawFrontmatter, composedFrontmatter]],
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const liquidedResult = liquidSnippet.call(this, strippedContent, vars);
|
|
60
|
+
return composedFrontmatter + liquidedResult;
|
|
61
|
+
}
|
|
62
|
+
function createContext(logger, settings = {}) {
|
|
63
|
+
return {
|
|
64
|
+
logger,
|
|
65
|
+
settings,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAiBA,sCAsCC;AAED,gCAIC;AAED,wCAsBC;AAED,sCAQC;AA5FD,yEAAiD;AAEjD,+CAAqE;AACrE,mDAAmD;AACnD,qCAAqC;AACrC,6CAA6C;AAC7C,mCAAkC;AAIlC,8CAAoD;AAA5C,oGAAA,QAAQ,OAAA;AAAE,mGAAA,OAAO,OAAA;AACzB,yCAAsC;AAA9B,sGAAA,SAAS,OAAA;AACjB,6CAAqE;AAA7D,iHAAA,kBAAkB,OAAA;AAAE,iHAAA,kBAAkB,OAAA;AAE9C,SAAgB,aAAa,CAEzB,KAAa,EACb,IAA6B,EAC7B,SAAqB;IAErB,MAAM,EACF,MAAM,GAAG,IAAI,EACb,UAAU,GAAG,IAAI,EACjB,aAAa,GAAG,IAAI,EACpB,gBAAgB,GAAG,KAAK,GAC3B,GAAG,IAAI,CAAC,QAAQ,CAAC;IAElB,MAAM,EAAC,QAAQ,EAAE,UAAU,EAAC,GAAG,iBAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEpD,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACpB,MAAM,GAAG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mBAAmB,GAAG,IAAA,gCAAkB,EAAC,mBAAmB,CAAC,CAAC;IAEpE,IAAI,SAAS,IAAI,cAAc,CAAC,MAAM,EAAE,CAAC;QACrC,SAAS,CAAC,KAAK,CAAC;YACZ,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,mBAAmB,CAAC,CAAC;SACtD,CAAC,CAAC;IACP,CAAC;IAED,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,eAAe,EAAE,IAAI,CAAC,CAAC;IAEvE,OAAO,mBAAmB,GAAG,cAAc,CAAC;AAChD,CAAC;AAED,SAAgB,aAAa,CACzB,MAAc,EACd,WAAoC,EAAE;IAEtC,OAAO;QACH,MAAM;QACN,QAAQ;KACX,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type Point = {
|
|
2
|
+
start: number;
|
|
3
|
+
end: number;
|
|
4
|
+
};
|
|
5
|
+
type SourceMapTx = {
|
|
6
|
+
delete: Point[];
|
|
7
|
+
offset: [number, number][];
|
|
8
|
+
replace: [number, string, string][];
|
|
9
|
+
};
|
|
10
|
+
export declare class SourceMap {
|
|
11
|
+
private patches;
|
|
12
|
+
private size;
|
|
13
|
+
constructor(content: string);
|
|
14
|
+
dump(): {};
|
|
15
|
+
delete(start: number, content: string): void;
|
|
16
|
+
patch(tx: Partial<SourceMapTx>): void;
|
|
17
|
+
lines(content: string): number[];
|
|
18
|
+
location(from: number, to: number, lines: number[], offset?: number): Point;
|
|
19
|
+
}
|
|
20
|
+
export {};
|