@platformos/prettier-plugin-liquid 0.0.2
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/README.md +158 -0
- package/ThirdPartyNotices.txt +17 -0
- package/dist/constants.evaluate.d.ts +7 -0
- package/dist/constants.evaluate.js +78 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/parser.d.ts +19 -0
- package/dist/parser.js +21 -0
- package/dist/plugin.d.ts +7 -0
- package/dist/plugin.js +88 -0
- package/dist/printer/embed.d.ts +9 -0
- package/dist/printer/embed.js +82 -0
- package/dist/printer/index.d.ts +14 -0
- package/dist/printer/index.js +12 -0
- package/dist/printer/preprocess/augment-with-css-properties.d.ts +2 -0
- package/dist/printer/preprocess/augment-with-css-properties.js +240 -0
- package/dist/printer/preprocess/augment-with-family.d.ts +2 -0
- package/dist/printer/preprocess/augment-with-family.js +13 -0
- package/dist/printer/preprocess/augment-with-parent.d.ts +2 -0
- package/dist/printer/preprocess/augment-with-parent.js +18 -0
- package/dist/printer/preprocess/augment-with-siblings.d.ts +1902 -0
- package/dist/printer/preprocess/augment-with-siblings.js +45 -0
- package/dist/printer/preprocess/augment-with-whitespace-helpers.d.ts +23 -0
- package/dist/printer/preprocess/augment-with-whitespace-helpers.js +460 -0
- package/dist/printer/preprocess/index.d.ts +1 -0
- package/dist/printer/preprocess/index.js +16 -0
- package/dist/printer/print/children.d.ts +6 -0
- package/dist/printer/print/children.js +283 -0
- package/dist/printer/print/element.d.ts +4 -0
- package/dist/printer/print/element.js +114 -0
- package/dist/printer/print/liquid.d.ts +14 -0
- package/dist/printer/print/liquid.js +637 -0
- package/dist/printer/print/tag.d.ts +23 -0
- package/dist/printer/print/tag.js +358 -0
- package/dist/printer/print-preprocess.d.ts +3 -0
- package/dist/printer/print-preprocess.js +48 -0
- package/dist/printer/printer-liquid-html.d.ts +13 -0
- package/dist/printer/printer-liquid-html.js +545 -0
- package/dist/printer/utils/array.d.ts +4 -0
- package/dist/printer/utils/array.js +19 -0
- package/dist/printer/utils/index.d.ts +14 -0
- package/dist/printer/utils/index.js +59 -0
- package/dist/printer/utils/node.d.ts +44 -0
- package/dist/printer/utils/node.js +270 -0
- package/dist/printer/utils/string.d.ts +15 -0
- package/dist/printer/utils/string.js +55 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.js +53 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +35 -0
- package/package.json +65 -0
- package/standalone.js +19503 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printChildren = printChildren;
|
|
4
|
+
const liquid_html_parser_1 = require("@platformos/liquid-html-parser");
|
|
5
|
+
const prettier_1 = require("prettier");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const utils_2 = require("../utils");
|
|
8
|
+
const tag_1 = require("./tag");
|
|
9
|
+
const { builders: { breakParent, group, ifBreak, line, softline, hardline }, } = prettier_1.doc;
|
|
10
|
+
const { replaceEndOfLine } = prettier_1.doc.utils;
|
|
11
|
+
function printChild(childPath, options, print, args) {
|
|
12
|
+
const child = childPath.getValue();
|
|
13
|
+
if ((0, utils_2.hasPrettierIgnore)(child)) {
|
|
14
|
+
const isPrevBorrowingOpeningMarker = child.prev && (0, tag_1.needsToBorrowNextOpeningTagStartMarker)(child.prev);
|
|
15
|
+
const bodyStartOffset = isPrevBorrowingOpeningMarker
|
|
16
|
+
? (0, tag_1.printOpeningTagStartMarker)(child).length
|
|
17
|
+
: 0;
|
|
18
|
+
const bodyStart = (0, utils_1.locStart)(child) + bodyStartOffset;
|
|
19
|
+
const isNextBorrowingClosingMarker = child.next && (0, tag_1.needsToBorrowPrevClosingTagEndMarker)(child.next);
|
|
20
|
+
// This could be "minus the `>` because the next tag borrows it"
|
|
21
|
+
const bodyEndOffset = isNextBorrowingClosingMarker
|
|
22
|
+
? (0, tag_1.printClosingTagEndMarker)(child, options).length
|
|
23
|
+
: 0;
|
|
24
|
+
const bodyEnd = (0, utils_1.locEnd)(child) - bodyEndOffset;
|
|
25
|
+
let rawContent = options.originalText.slice(bodyStart, bodyEnd);
|
|
26
|
+
// This is an idempotence edge case that I don't know how to solve
|
|
27
|
+
// "cleanly." I feel like there's a more elegant solution, but I can't
|
|
28
|
+
// find one right now.
|
|
29
|
+
//
|
|
30
|
+
// The gist: We might pretty-print something like this:
|
|
31
|
+
// <!-- prettier-ignore -->
|
|
32
|
+
// <b>{%cycle a,b,c%}</b
|
|
33
|
+
// >hi
|
|
34
|
+
// Which would mean the closing tag is '</b\n >'
|
|
35
|
+
//
|
|
36
|
+
// For idempotence to be maintained, we need to strip the '\n '
|
|
37
|
+
// from the raw source.
|
|
38
|
+
if (child.type === liquid_html_parser_1.NodeTypes.HtmlElement && isNextBorrowingClosingMarker) {
|
|
39
|
+
rawContent = rawContent.trimEnd();
|
|
40
|
+
}
|
|
41
|
+
return [
|
|
42
|
+
(0, tag_1.printOpeningTagPrefix)(child, options),
|
|
43
|
+
...replaceEndOfLine(rawContent),
|
|
44
|
+
(0, tag_1.printClosingTagSuffix)(child, options),
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
return print(childPath, args);
|
|
48
|
+
}
|
|
49
|
+
function printBetweenLine(prevNode, nextNode) {
|
|
50
|
+
if (!prevNode || !nextNode)
|
|
51
|
+
return '';
|
|
52
|
+
const spaceBetweenLinesIsHandledSomewhereElse = ((0, tag_1.needsToBorrowNextOpeningTagStartMarker)(prevNode) &&
|
|
53
|
+
((0, utils_2.hasPrettierIgnore)(nextNode) ||
|
|
54
|
+
/**
|
|
55
|
+
* 123<a
|
|
56
|
+
* ~
|
|
57
|
+
* ><b>
|
|
58
|
+
*/
|
|
59
|
+
nextNode.firstChild ||
|
|
60
|
+
/**
|
|
61
|
+
* 123<!--
|
|
62
|
+
* ~
|
|
63
|
+
* -->
|
|
64
|
+
*/
|
|
65
|
+
(0, utils_2.hasNoChildren)(nextNode) ||
|
|
66
|
+
/**
|
|
67
|
+
* 123<span
|
|
68
|
+
* ~
|
|
69
|
+
* attr
|
|
70
|
+
*/
|
|
71
|
+
(nextNode.type === liquid_html_parser_1.NodeTypes.HtmlElement && nextNode.attributes.length > 0))) ||
|
|
72
|
+
/**
|
|
73
|
+
* <img
|
|
74
|
+
* src="long"
|
|
75
|
+
* ~
|
|
76
|
+
* />123
|
|
77
|
+
*/
|
|
78
|
+
(prevNode.type === liquid_html_parser_1.NodeTypes.HtmlElement &&
|
|
79
|
+
(0, utils_2.hasNoCloseMarker)(prevNode) &&
|
|
80
|
+
(0, tag_1.needsToBorrowPrevClosingTagEndMarker)(nextNode));
|
|
81
|
+
if (spaceBetweenLinesIsHandledSomewhereElse) {
|
|
82
|
+
return '';
|
|
83
|
+
}
|
|
84
|
+
const shouldUseHardline = !nextNode.isLeadingWhitespaceSensitive ||
|
|
85
|
+
(0, utils_2.preferHardlineAsLeadingSpaces)(nextNode) ||
|
|
86
|
+
/**
|
|
87
|
+
* Want to write us a letter? Use our<a
|
|
88
|
+
* ><b><a>mailing address</a></b></a
|
|
89
|
+
* ~
|
|
90
|
+
* >.
|
|
91
|
+
*/
|
|
92
|
+
((0, tag_1.needsToBorrowPrevClosingTagEndMarker)(nextNode) &&
|
|
93
|
+
prevNode.lastChild &&
|
|
94
|
+
(0, tag_1.needsToBorrowParentClosingTagStartMarker)(prevNode.lastChild) &&
|
|
95
|
+
prevNode.lastChild.lastChild &&
|
|
96
|
+
(0, tag_1.needsToBorrowParentClosingTagStartMarker)(prevNode.lastChild.lastChild));
|
|
97
|
+
if (shouldUseHardline) {
|
|
98
|
+
return hardline;
|
|
99
|
+
}
|
|
100
|
+
return nextNode.hasLeadingWhitespace ? line : softline;
|
|
101
|
+
}
|
|
102
|
+
// This code is adapted from prettier's language-html plugin.
|
|
103
|
+
function printChildren(path, options, print, args) {
|
|
104
|
+
const node = path.getValue();
|
|
105
|
+
if (!node.children) {
|
|
106
|
+
throw new Error('attempting to use printChildren on something without children');
|
|
107
|
+
}
|
|
108
|
+
if ((0, utils_2.forceBreakChildren)(node)) {
|
|
109
|
+
return [
|
|
110
|
+
breakParent,
|
|
111
|
+
...path.map((childPath) => {
|
|
112
|
+
const childNode = childPath.getValue();
|
|
113
|
+
const prevBetweenLine = printBetweenLine(childNode.prev, childNode);
|
|
114
|
+
return [
|
|
115
|
+
!prevBetweenLine
|
|
116
|
+
? ''
|
|
117
|
+
: [prevBetweenLine, (0, utils_2.forceNextEmptyLine)(childNode.prev) ? hardline : ''],
|
|
118
|
+
printChild(childPath, options, print, {
|
|
119
|
+
...args,
|
|
120
|
+
leadingSpaceGroupId: utils_2.FORCE_BREAK_GROUP_ID,
|
|
121
|
+
trailingSpaceGroupId: utils_2.FORCE_BREAK_GROUP_ID,
|
|
122
|
+
}),
|
|
123
|
+
];
|
|
124
|
+
}, 'children'),
|
|
125
|
+
];
|
|
126
|
+
}
|
|
127
|
+
const leadingSpaceGroupIds = node.children.map((_, i) => Symbol(`leading-${i}`));
|
|
128
|
+
const trailingSpaceGroupIds = node.children.map((_, i) => Symbol(`trailing-${i}`));
|
|
129
|
+
/**
|
|
130
|
+
* Whitespace handling. My favourite topic.
|
|
131
|
+
*
|
|
132
|
+
* TL;DR we sort the output of printBetweenLine into buckets.
|
|
133
|
+
*
|
|
134
|
+
* What we want:
|
|
135
|
+
* - Hardlines should go in as is and not break unrelated content
|
|
136
|
+
* - When we want the content to flow as a paragraph, we'll immitate
|
|
137
|
+
* prettier's `fill` builder with this:
|
|
138
|
+
* group([whitespace, group(content, whitespace)])
|
|
139
|
+
* - When we want the content to break surrounding whitespace in pairs,
|
|
140
|
+
* we'll do this:
|
|
141
|
+
* group([whitespace, content, whitespace])
|
|
142
|
+
* - We want to know the whitespace beforehand because conditional whitespace
|
|
143
|
+
* stripping depends on the groupId of the already printed group that
|
|
144
|
+
* breaks.
|
|
145
|
+
*/
|
|
146
|
+
const whitespaceBetweenNode = path.map((childPath, childIndex) => {
|
|
147
|
+
const childNode = childPath.getValue();
|
|
148
|
+
const leadingHardlines = [];
|
|
149
|
+
const leadingWhitespace = [];
|
|
150
|
+
const leadingDependentWhitespace = [];
|
|
151
|
+
const trailingWhitespace = [];
|
|
152
|
+
const trailingHardlines = [];
|
|
153
|
+
const prevBetweenLine = printBetweenLine(childNode.prev, childNode);
|
|
154
|
+
const nextBetweenLine = printBetweenLine(childNode, childNode.next);
|
|
155
|
+
if ((0, utils_2.isTextLikeNode)(childNode)) {
|
|
156
|
+
return {
|
|
157
|
+
leadingHardlines,
|
|
158
|
+
leadingWhitespace,
|
|
159
|
+
leadingDependentWhitespace,
|
|
160
|
+
trailingWhitespace,
|
|
161
|
+
trailingHardlines,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
if (prevBetweenLine) {
|
|
165
|
+
if ((0, utils_2.forceNextEmptyLine)(childNode.prev)) {
|
|
166
|
+
leadingHardlines.push(hardline, hardline);
|
|
167
|
+
}
|
|
168
|
+
else if (prevBetweenLine === hardline) {
|
|
169
|
+
leadingHardlines.push(hardline);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
if ((0, utils_2.isTextLikeNode)(childNode.prev)) {
|
|
173
|
+
if ((0, utils_2.isLiquidNode)(childNode) && prevBetweenLine === softline) {
|
|
174
|
+
leadingDependentWhitespace.push(prevBetweenLine);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
leadingWhitespace.push(prevBetweenLine);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
// We're collapsing nextBetweenLine and prevBetweenLine of
|
|
182
|
+
// adjacent nodes here. When the previous node breaks content,
|
|
183
|
+
// then we want to print nothing here. If it doesn't, then add
|
|
184
|
+
// a softline and give a chance to _this_ node to break.
|
|
185
|
+
leadingWhitespace.push(ifBreak('', softline, {
|
|
186
|
+
groupId: trailingSpaceGroupIds[childIndex - 1],
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (nextBetweenLine) {
|
|
192
|
+
if ((0, utils_2.forceNextEmptyLine)(childNode)) {
|
|
193
|
+
if ((0, utils_2.isTextLikeNode)(childNode.next)) {
|
|
194
|
+
trailingHardlines.push(hardline, hardline);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else if (nextBetweenLine === hardline) {
|
|
198
|
+
if ((0, utils_2.isTextLikeNode)(childNode.next)) {
|
|
199
|
+
trailingHardlines.push(hardline);
|
|
200
|
+
}
|
|
201
|
+
// there's a hole here, it's intentional!
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
// We know it's not a typeof hardline here because we do the
|
|
205
|
+
// check on the previous condition.
|
|
206
|
+
trailingWhitespace.push(nextBetweenLine);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
leadingHardlines,
|
|
211
|
+
leadingWhitespace,
|
|
212
|
+
leadingDependentWhitespace,
|
|
213
|
+
trailingWhitespace,
|
|
214
|
+
trailingHardlines,
|
|
215
|
+
};
|
|
216
|
+
}, 'children');
|
|
217
|
+
return path.map((childPath, childIndex) => {
|
|
218
|
+
const { leadingHardlines, leadingWhitespace, leadingDependentWhitespace, trailingWhitespace, trailingHardlines, } = whitespaceBetweenNode[childIndex];
|
|
219
|
+
return [
|
|
220
|
+
...leadingHardlines, // independent
|
|
221
|
+
group([
|
|
222
|
+
...leadingWhitespace, // breaks first
|
|
223
|
+
group([
|
|
224
|
+
...leadingDependentWhitespace, // breaks with trailing
|
|
225
|
+
printChild(childPath, options, print, {
|
|
226
|
+
...args,
|
|
227
|
+
leadingSpaceGroupId: leadingSpaceGroupId(whitespaceBetweenNode, childIndex),
|
|
228
|
+
trailingSpaceGroupId: trailingSpaceGroupId(whitespaceBetweenNode, childIndex),
|
|
229
|
+
}),
|
|
230
|
+
...trailingWhitespace, // breaks second, if content breaks
|
|
231
|
+
], {
|
|
232
|
+
id: trailingSpaceGroupIds[childIndex],
|
|
233
|
+
}),
|
|
234
|
+
], {
|
|
235
|
+
id: leadingSpaceGroupIds[childIndex],
|
|
236
|
+
}),
|
|
237
|
+
...trailingHardlines, // independent
|
|
238
|
+
];
|
|
239
|
+
}, 'children');
|
|
240
|
+
function leadingSpaceGroupId(whitespaceBetweenNode, index) {
|
|
241
|
+
if (index === 0) {
|
|
242
|
+
return args.leadingSpaceGroupId;
|
|
243
|
+
}
|
|
244
|
+
const prev = whitespaceBetweenNode[index - 1];
|
|
245
|
+
const curr = whitespaceBetweenNode[index];
|
|
246
|
+
const groupIds = [];
|
|
247
|
+
if (!(0, utils_2.isEmpty)(prev.trailingHardlines) || !(0, utils_2.isEmpty)(curr.leadingHardlines)) {
|
|
248
|
+
return utils_2.FORCE_BREAK_GROUP_ID;
|
|
249
|
+
}
|
|
250
|
+
if (!(0, utils_2.isEmpty)(prev.trailingWhitespace)) {
|
|
251
|
+
groupIds.push(trailingSpaceGroupIds[index - 1]);
|
|
252
|
+
}
|
|
253
|
+
if (!(0, utils_2.isEmpty)(curr.leadingWhitespace)) {
|
|
254
|
+
groupIds.push(leadingSpaceGroupIds[index]);
|
|
255
|
+
}
|
|
256
|
+
if (!(0, utils_2.isEmpty)(curr.leadingDependentWhitespace)) {
|
|
257
|
+
groupIds.push(trailingSpaceGroupIds[index]);
|
|
258
|
+
}
|
|
259
|
+
if ((0, utils_2.isEmpty)(groupIds)) {
|
|
260
|
+
groupIds.push(utils_2.FORCE_FLAT_GROUP_ID);
|
|
261
|
+
}
|
|
262
|
+
return groupIds;
|
|
263
|
+
}
|
|
264
|
+
function trailingSpaceGroupId(whitespaceBetweenNode, index) {
|
|
265
|
+
if (index === whitespaceBetweenNode.length - 1) {
|
|
266
|
+
return args.trailingSpaceGroupId;
|
|
267
|
+
}
|
|
268
|
+
const curr = whitespaceBetweenNode[index];
|
|
269
|
+
const next = whitespaceBetweenNode[index + 1];
|
|
270
|
+
const groupIds = [];
|
|
271
|
+
if (!(0, utils_2.isEmpty)(curr.trailingHardlines) || !(0, utils_2.isEmpty)(next.leadingHardlines)) {
|
|
272
|
+
return utils_2.FORCE_BREAK_GROUP_ID;
|
|
273
|
+
}
|
|
274
|
+
if (!(0, utils_2.isEmpty)(curr.trailingWhitespace)) {
|
|
275
|
+
groupIds.push(trailingSpaceGroupIds[index]);
|
|
276
|
+
}
|
|
277
|
+
if ((0, utils_2.isEmpty)(groupIds)) {
|
|
278
|
+
groupIds.push(utils_2.FORCE_FLAT_GROUP_ID);
|
|
279
|
+
}
|
|
280
|
+
return groupIds;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
//# sourceMappingURL=children.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { AstPath, LiquidParserOptions, LiquidPrinter, HtmlNode, LiquidPrinterArgs, HtmlRawNode } from '../../types';
|
|
3
|
+
export declare function printRawElement(path: AstPath<HtmlRawNode>, options: LiquidParserOptions, print: LiquidPrinter, _args: LiquidPrinterArgs): doc.builders.Group;
|
|
4
|
+
export declare function printElement(path: AstPath<HtmlNode>, options: LiquidParserOptions, print: LiquidPrinter, args: LiquidPrinterArgs): any[] | doc.builders.Group;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printRawElement = printRawElement;
|
|
4
|
+
exports.printElement = printElement;
|
|
5
|
+
const prettier_1 = require("prettier");
|
|
6
|
+
const liquid_html_parser_1 = require("@platformos/liquid-html-parser");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const tag_1 = require("./tag");
|
|
9
|
+
const children_1 = require("./children");
|
|
10
|
+
const { builders: { breakParent, dedentToRoot, group, indent, hardline, line, softline }, } = prettier_1.doc;
|
|
11
|
+
const { replaceEndOfLine } = prettier_1.doc.utils;
|
|
12
|
+
function printRawElement(path, options, print, _args) {
|
|
13
|
+
const node = path.getValue();
|
|
14
|
+
const attrGroupId = Symbol('element-attr-group-id');
|
|
15
|
+
let body = [];
|
|
16
|
+
const hasEmptyBody = node.body.value.trim() === '';
|
|
17
|
+
if (!hasEmptyBody) {
|
|
18
|
+
body = [path.call((p) => print(p), 'body')];
|
|
19
|
+
}
|
|
20
|
+
return group([
|
|
21
|
+
(0, tag_1.printOpeningTagPrefix)(node, options),
|
|
22
|
+
group((0, tag_1.printOpeningTag)(path, options, print, attrGroupId), {
|
|
23
|
+
id: attrGroupId,
|
|
24
|
+
}),
|
|
25
|
+
...body,
|
|
26
|
+
...(0, tag_1.printClosingTag)(node, options),
|
|
27
|
+
(0, tag_1.printClosingTagSuffix)(node, options),
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
function printElement(path, options, print, args) {
|
|
31
|
+
const node = path.getValue();
|
|
32
|
+
const attrGroupId = Symbol('element-attr-group-id');
|
|
33
|
+
const elementGroupId = Symbol('element-group-id');
|
|
34
|
+
if (node.type === liquid_html_parser_1.NodeTypes.HtmlRawNode) {
|
|
35
|
+
return printRawElement(path, options, print, args);
|
|
36
|
+
}
|
|
37
|
+
if ((0, utils_1.hasNoChildren)(node)) {
|
|
38
|
+
// TODO, broken for HtmlComment but this code path is not used (so far).
|
|
39
|
+
return [
|
|
40
|
+
group((0, tag_1.printOpeningTag)(path, options, print, attrGroupId), {
|
|
41
|
+
id: attrGroupId,
|
|
42
|
+
}),
|
|
43
|
+
...(0, tag_1.printClosingTag)(node, options),
|
|
44
|
+
(0, tag_1.printClosingTagSuffix)(node, options),
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
if ((0, utils_1.shouldPreserveContent)(node)) {
|
|
48
|
+
return [
|
|
49
|
+
(0, tag_1.printOpeningTagPrefix)(node, options),
|
|
50
|
+
group((0, tag_1.printOpeningTag)(path, options, print, attrGroupId), {
|
|
51
|
+
id: attrGroupId,
|
|
52
|
+
}),
|
|
53
|
+
...replaceEndOfLine((0, tag_1.getNodeContent)(node, options)),
|
|
54
|
+
...(0, tag_1.printClosingTag)(node, options),
|
|
55
|
+
(0, tag_1.printClosingTagSuffix)(node, options),
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
const printTag = (doc) => group([
|
|
59
|
+
group((0, tag_1.printOpeningTag)(path, options, print, attrGroupId), {
|
|
60
|
+
id: attrGroupId,
|
|
61
|
+
}),
|
|
62
|
+
doc,
|
|
63
|
+
(0, tag_1.printClosingTag)(node, options),
|
|
64
|
+
], { id: elementGroupId });
|
|
65
|
+
const printLineBeforeChildren = () => {
|
|
66
|
+
if (node.firstChild.hasLeadingWhitespace && node.firstChild.isLeadingWhitespaceSensitive) {
|
|
67
|
+
return line;
|
|
68
|
+
}
|
|
69
|
+
if (node.firstChild.type === liquid_html_parser_1.NodeTypes.TextNode &&
|
|
70
|
+
node.isWhitespaceSensitive &&
|
|
71
|
+
node.isIndentationSensitive) {
|
|
72
|
+
return dedentToRoot(softline);
|
|
73
|
+
}
|
|
74
|
+
return softline;
|
|
75
|
+
};
|
|
76
|
+
const printLineAfterChildren = () => {
|
|
77
|
+
// does not have the closing tag
|
|
78
|
+
if (node.blockEndPosition.start === node.blockEndPosition.end) {
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
81
|
+
const needsToBorrow = node.next
|
|
82
|
+
? (0, tag_1.needsToBorrowPrevClosingTagEndMarker)(node.next)
|
|
83
|
+
: (0, tag_1.needsToBorrowLastChildClosingTagEndMarker)(node.parentNode);
|
|
84
|
+
if (needsToBorrow) {
|
|
85
|
+
if (node.lastChild.hasTrailingWhitespace && node.lastChild.isTrailingWhitespaceSensitive) {
|
|
86
|
+
return ' ';
|
|
87
|
+
}
|
|
88
|
+
return '';
|
|
89
|
+
}
|
|
90
|
+
if (node.lastChild.hasTrailingWhitespace && node.lastChild.isTrailingWhitespaceSensitive) {
|
|
91
|
+
return line;
|
|
92
|
+
}
|
|
93
|
+
return softline;
|
|
94
|
+
};
|
|
95
|
+
if (node.children.length === 0) {
|
|
96
|
+
return printTag(node.hasDanglingWhitespace &&
|
|
97
|
+
node.isDanglingWhitespaceSensitive &&
|
|
98
|
+
node.blockEndPosition.end !== node.blockEndPosition.start
|
|
99
|
+
? line
|
|
100
|
+
: '');
|
|
101
|
+
}
|
|
102
|
+
return printTag([
|
|
103
|
+
(0, utils_1.forceBreakContent)(node) ? breakParent : '',
|
|
104
|
+
indent([
|
|
105
|
+
printLineBeforeChildren(),
|
|
106
|
+
(0, children_1.printChildren)(path, options, print, {
|
|
107
|
+
leadingSpaceGroupId: elementGroupId,
|
|
108
|
+
trailingSpaceGroupId: elementGroupId,
|
|
109
|
+
}),
|
|
110
|
+
]),
|
|
111
|
+
printLineAfterChildren(),
|
|
112
|
+
]);
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RawMarkup, LiquidDocParamNode, LiquidDocExampleNode, LiquidDocDescriptionNode, LiquidDocPromptNode } from '@platformos/liquid-html-parser';
|
|
2
|
+
import { Doc, doc } from 'prettier';
|
|
3
|
+
import { AstPath, LiquidAstPath, LiquidBranch, LiquidParserOptions, LiquidPrinter, LiquidPrinterArgs, LiquidRawTag, LiquidTag } from '../../types';
|
|
4
|
+
export declare function printLiquidVariableOutput(path: LiquidAstPath, _options: LiquidParserOptions, print: LiquidPrinter, { leadingSpaceGroupId, trailingSpaceGroupId }: LiquidPrinterArgs): doc.builders.Group;
|
|
5
|
+
export declare function printLiquidBlockStart(path: AstPath<LiquidTag | LiquidBranch>, options: LiquidParserOptions, print: LiquidPrinter, args?: LiquidPrinterArgs): Doc;
|
|
6
|
+
export declare function printLiquidBlockEnd(path: AstPath<LiquidTag>, _options: LiquidParserOptions, _print: LiquidPrinter, args?: LiquidPrinterArgs): Doc;
|
|
7
|
+
export declare function printLiquidTag(path: AstPath<LiquidTag>, options: LiquidParserOptions, print: LiquidPrinter, args: LiquidPrinterArgs): Doc;
|
|
8
|
+
export declare function printLiquidRawTag(path: AstPath<LiquidRawTag>, options: LiquidParserOptions, print: LiquidPrinter, { isLiquidStatement }: LiquidPrinterArgs): Doc;
|
|
9
|
+
export declare function printLiquidDoc(path: AstPath<RawMarkup>, _options: LiquidParserOptions, print: LiquidPrinter, _args: LiquidPrinterArgs): (doc.builders.Concat | doc.builders.Indent)[];
|
|
10
|
+
export declare function printLiquidDocParam(path: AstPath<LiquidDocParamNode>, options: LiquidParserOptions, _print: LiquidPrinter, _args: LiquidPrinterArgs): Doc;
|
|
11
|
+
export declare function printLiquidDocExample(path: AstPath<LiquidDocExampleNode>, options: LiquidParserOptions, _print: LiquidPrinter, _args: LiquidPrinterArgs): Doc;
|
|
12
|
+
export declare function printLiquidDocDescription(path: AstPath<LiquidDocDescriptionNode>, options: LiquidParserOptions, _print: LiquidPrinter, _args: LiquidPrinterArgs): Doc;
|
|
13
|
+
export declare function printLiquidDocPrompt(path: AstPath<LiquidDocPromptNode>, options: LiquidParserOptions, _print: LiquidPrinter, _args: LiquidPrinterArgs): Doc;
|
|
14
|
+
export declare function printLiquidBranch(path: AstPath<LiquidBranch>, options: LiquidParserOptions, print: LiquidPrinter, args: LiquidPrinterArgs): Doc;
|