@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.
Files changed (52) hide show
  1. package/README.md +158 -0
  2. package/ThirdPartyNotices.txt +17 -0
  3. package/dist/constants.evaluate.d.ts +7 -0
  4. package/dist/constants.evaluate.js +78 -0
  5. package/dist/index.d.ts +2 -0
  6. package/dist/index.js +7 -0
  7. package/dist/parser.d.ts +19 -0
  8. package/dist/parser.js +21 -0
  9. package/dist/plugin.d.ts +7 -0
  10. package/dist/plugin.js +88 -0
  11. package/dist/printer/embed.d.ts +9 -0
  12. package/dist/printer/embed.js +82 -0
  13. package/dist/printer/index.d.ts +14 -0
  14. package/dist/printer/index.js +12 -0
  15. package/dist/printer/preprocess/augment-with-css-properties.d.ts +2 -0
  16. package/dist/printer/preprocess/augment-with-css-properties.js +240 -0
  17. package/dist/printer/preprocess/augment-with-family.d.ts +2 -0
  18. package/dist/printer/preprocess/augment-with-family.js +13 -0
  19. package/dist/printer/preprocess/augment-with-parent.d.ts +2 -0
  20. package/dist/printer/preprocess/augment-with-parent.js +18 -0
  21. package/dist/printer/preprocess/augment-with-siblings.d.ts +1902 -0
  22. package/dist/printer/preprocess/augment-with-siblings.js +45 -0
  23. package/dist/printer/preprocess/augment-with-whitespace-helpers.d.ts +23 -0
  24. package/dist/printer/preprocess/augment-with-whitespace-helpers.js +460 -0
  25. package/dist/printer/preprocess/index.d.ts +1 -0
  26. package/dist/printer/preprocess/index.js +16 -0
  27. package/dist/printer/print/children.d.ts +6 -0
  28. package/dist/printer/print/children.js +283 -0
  29. package/dist/printer/print/element.d.ts +4 -0
  30. package/dist/printer/print/element.js +114 -0
  31. package/dist/printer/print/liquid.d.ts +14 -0
  32. package/dist/printer/print/liquid.js +637 -0
  33. package/dist/printer/print/tag.d.ts +23 -0
  34. package/dist/printer/print/tag.js +358 -0
  35. package/dist/printer/print-preprocess.d.ts +3 -0
  36. package/dist/printer/print-preprocess.js +48 -0
  37. package/dist/printer/printer-liquid-html.d.ts +13 -0
  38. package/dist/printer/printer-liquid-html.js +545 -0
  39. package/dist/printer/utils/array.d.ts +4 -0
  40. package/dist/printer/utils/array.js +19 -0
  41. package/dist/printer/utils/index.d.ts +14 -0
  42. package/dist/printer/utils/index.js +59 -0
  43. package/dist/printer/utils/node.d.ts +44 -0
  44. package/dist/printer/utils/node.js +270 -0
  45. package/dist/printer/utils/string.d.ts +15 -0
  46. package/dist/printer/utils/string.js +55 -0
  47. package/dist/types.d.ts +85 -0
  48. package/dist/types.js +53 -0
  49. package/dist/utils.d.ts +6 -0
  50. package/dist/utils.js +35 -0
  51. package/package.json +65 -0
  52. package/standalone.js +19503 -0
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.augmentWithSiblings = void 0;
4
+ exports.prev = prev;
5
+ exports.next = next;
6
+ const types_1 = require("../../types");
7
+ function prev(node) {
8
+ if (!node.parentNode)
9
+ return;
10
+ const collection = parentCollection(node);
11
+ return collection[collection.indexOf(node) - 1];
12
+ }
13
+ function next(node) {
14
+ if (!node.parentNode)
15
+ return;
16
+ const collection = parentCollection(node);
17
+ return collection[collection.indexOf(node) + 1];
18
+ }
19
+ function parentCollection(node) {
20
+ if (!node.parentNode) {
21
+ return [];
22
+ }
23
+ for (const key of Object.keys(node.parentNode)) {
24
+ // can't figure out the typing for this and I am done wasting my time.
25
+ const parentValue = node.parentNode[key];
26
+ if (Array.isArray(parentValue)) {
27
+ if (parentValue.indexOf(node) !== -1) {
28
+ return parentValue;
29
+ }
30
+ }
31
+ if ((0, types_1.isLiquidHtmlNode)(parentValue) && parentValue === node) {
32
+ return [];
33
+ }
34
+ }
35
+ throw new Error('Could not find parent collection of node');
36
+ }
37
+ const augmentWithSiblings = (_options, node) => {
38
+ const augmentations = {
39
+ next: next(node),
40
+ prev: prev(node),
41
+ };
42
+ Object.assign(node, augmentations);
43
+ };
44
+ exports.augmentWithSiblings = augmentWithSiblings;
45
+ //# sourceMappingURL=augment-with-siblings.js.map
@@ -0,0 +1,23 @@
1
+ import { HtmlNodeTypes, LiquidNodeTypes } from '@platformos/liquid-html-parser';
2
+ import { WithFamily } from '../../types';
3
+ import { Augment, AugmentedNode, WithCssProperties, WithParent, WithSiblings } from '../../types';
4
+ type RequiredAugmentations = WithParent & WithSiblings & WithFamily & WithCssProperties;
5
+ type AugmentedAstNode = AugmentedNode<RequiredAugmentations>;
6
+ export declare const augmentWithWhitespaceHelpers: Augment<RequiredAugmentations>;
7
+ type ParentNode = Extract<AugmentedAstNode, {
8
+ children?: AugmentedAstNode[];
9
+ }>;
10
+ type HtmlNode = Extract<AugmentedAstNode, {
11
+ type: (typeof HtmlNodeTypes)[number];
12
+ }>;
13
+ export declare function isHtmlNode(node: AugmentedAstNode): node is HtmlNode;
14
+ type LiquidNode = Extract<AugmentedAstNode, {
15
+ type: (typeof LiquidNodeTypes)[number];
16
+ }>;
17
+ export declare function isLiquidNode(node: AugmentedAstNode | undefined): node is LiquidNode;
18
+ export declare function isParentNode(node: AugmentedAstNode): node is ParentNode;
19
+ export declare function isTrimmingOuterRight(node: AugmentedAstNode | undefined): boolean;
20
+ export declare function isTrimmingOuterLeft(node: AugmentedAstNode | undefined): boolean;
21
+ export declare function isTrimmingInnerLeft(node: AugmentedAstNode | undefined): boolean;
22
+ export declare function isTrimmingInnerRight(node: AugmentedAstNode | undefined): boolean;
23
+ export {};
@@ -0,0 +1,460 @@
1
+ "use strict";
2
+ // A lot in here is adapted from prettier/prettier.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.augmentWithWhitespaceHelpers = void 0;
5
+ exports.isHtmlNode = isHtmlNode;
6
+ exports.isLiquidNode = isLiquidNode;
7
+ exports.isParentNode = isParentNode;
8
+ exports.isTrimmingOuterRight = isTrimmingOuterRight;
9
+ exports.isTrimmingOuterLeft = isTrimmingOuterLeft;
10
+ exports.isTrimmingInnerLeft = isTrimmingInnerLeft;
11
+ exports.isTrimmingInnerRight = isTrimmingInnerRight;
12
+ const liquid_html_parser_1 = require("@platformos/liquid-html-parser");
13
+ const constants_evaluate_1 = require("../../constants.evaluate");
14
+ const utils_1 = require("../utils");
15
+ const augmentWithWhitespaceHelpers = (_options, node) => {
16
+ if (node.cssDisplay === 'should not be relevant') {
17
+ return;
18
+ }
19
+ const augmentations = {
20
+ isDanglingWhitespaceSensitive: isDanglingWhitespaceSensitiveNode(node),
21
+ isIndentationSensitive: isIndentationSensitiveNode(node),
22
+ isWhitespaceSensitive: isWhitespaceSensitiveNode(node),
23
+ // If either isn't sensitive, then this one isn't
24
+ isLeadingWhitespaceSensitive: isLeadingWhitespaceSensitiveNode(node) &&
25
+ (!node.prev || isTrailingWhitespaceSensitiveNode(node.prev)),
26
+ // If either isn't sensitive, then this one isn't
27
+ isTrailingWhitespaceSensitive: isTrailingWhitespaceSensitiveNode(node) &&
28
+ (!node.next || isLeadingWhitespaceSensitiveNode(node.next)),
29
+ hasLeadingWhitespace: hasLeadingWhitespace(node),
30
+ hasTrailingWhitespace: hasTrailingWhitespace(node),
31
+ hasDanglingWhitespace: hasDanglingWhitespace(node),
32
+ };
33
+ Object.assign(node, augmentations);
34
+ };
35
+ exports.augmentWithWhitespaceHelpers = augmentWithWhitespaceHelpers;
36
+ /**
37
+ * A node is dangling whitespace sensitive when whitespace in an empty node
38
+ * (no children) has meaning in the rendered output.
39
+ *
40
+ * examples:
41
+ * - <span> </span> is dangling whitespace sensitive (cssDisplay === inline)
42
+ * - <div> </div> is not dangling whitespace sensitive (cssDisplay === block)
43
+ * - {% if %} {% endif %} is dangling whitespace sensitive
44
+ * - {% if -%} {% endif %} is not dangling whitespace sensitive
45
+ */
46
+ function isDanglingWhitespaceSensitiveNode(node) {
47
+ return (isDanglingSpaceSensitiveCssDisplay(node.cssDisplay) &&
48
+ !(0, utils_1.isScriptLikeTag)(node) &&
49
+ !isTrimmingInnerLeft(node) &&
50
+ !isTrimmingInnerRight(node));
51
+ }
52
+ /**
53
+ * A node is whitespace sensitive when its contents is sensitive to
54
+ * whitespace. That is, whitespace between nodes must be maintained
55
+ * otherwise the rendered output would be different.
56
+ *
57
+ * A special case of whitespace sensitive nodes are nodes that are also
58
+ * indentation sensitive.
59
+ *
60
+ * examples:
61
+ * - script-like tags
62
+ * - indentation-sensitive tags (e.g. <pre></pre>)
63
+ */
64
+ function isWhitespaceSensitiveNode(node) {
65
+ return (
66
+ // isScriptLikeTag(node) ||
67
+ isIndentationSensitiveNode(node));
68
+ }
69
+ /**
70
+ * A node is indentation sensitive when the indentation used in the output
71
+ * must match the indentation used in the source, otherwise the rendered
72
+ * output would be different.
73
+ *
74
+ * example:
75
+ * - <pre></pre>
76
+ */
77
+ function isIndentationSensitiveNode(node) {
78
+ return getNodeCssStyleWhiteSpace(node).startsWith('pre');
79
+ }
80
+ /**
81
+ * A node is leading whitespace sensitive when whitespace to the outer left
82
+ * of it has meaning. Removing or adding whitespace there would alter the
83
+ * rendered output.
84
+ * <div attr-{{ hi }}
85
+ */
86
+ function isLeadingWhitespaceSensitiveNode(node) {
87
+ if (!node) {
88
+ return false;
89
+ }
90
+ if (node.type === liquid_html_parser_1.NodeTypes.LiquidBranch) {
91
+ const isDefaultBranch = node.name === null;
92
+ const hasNoChildren = !!node.firstChild;
93
+ const isParentInnerRightSensitive = isInnerLeftSpaceSensitiveCssDisplay(node.parentNode.cssDisplay);
94
+ const isFirstChildLeadingSensitive = isLeadingWhitespaceSensitiveNode(node.firstChild);
95
+ // {% if %}<emptythis>{% endif %}
96
+ // {% if %}this{% endif %}
97
+ if (isDefaultBranch) {
98
+ return isParentInnerRightSensitive && (!hasNoChildren || isFirstChildLeadingSensitive);
99
+ }
100
+ // {% if %}{% <elseasthis> %}anything{% endif %}
101
+ return isParentInnerRightSensitive;
102
+ }
103
+ // <a data-{{ this }}="hi">
104
+ if (node.parentNode &&
105
+ (0, utils_1.isAttributeNode)(node.parentNode) &&
106
+ node.type === liquid_html_parser_1.NodeTypes.LiquidVariableOutput) {
107
+ return true;
108
+ }
109
+ // {{- this }}
110
+ if (isTrimmingOuterLeft(node)) {
111
+ return false;
112
+ }
113
+ // {{ drop -}} this
114
+ if (node.prev && isTrimmingOuterRight(node.prev)) {
115
+ return false;
116
+ }
117
+ // Invisible nodes aren't whitespace sensitive
118
+ if (!node.parentNode || node.parentNode.cssDisplay === 'none') {
119
+ return false;
120
+ }
121
+ // <pre> tags are whitespace sensitive, so nodes in 'em are all leading
122
+ // whitespace sensitive.
123
+ if ((0, utils_1.isPreLikeNode)(node.parentNode)) {
124
+ return true;
125
+ }
126
+ // TODO I added this as a short term fix for HtmlRawNode printing.
127
+ if ((0, utils_1.isScriptLikeTag)(node)) {
128
+ return false;
129
+ }
130
+ // The first child of a node is NOT leading whitespace sensitive if one of
131
+ // the following is true:
132
+ //
133
+ // - the parent is DocumentNode
134
+ // - the node itself is pre-like (since pre are block-like)
135
+ // - the parent is a script-like (since scripts are not rendered)
136
+ // - the parent has a CSS display that strips whitespace from both ends
137
+ // - the parent is whitespace stripping to the inner left
138
+ //
139
+ // prettier-ignore
140
+ if (!node.prev && (node.parentNode.type === liquid_html_parser_1.NodeTypes.Document
141
+ || (0, utils_1.isPreLikeNode)(node)
142
+ || (0, utils_1.isScriptLikeTag)(node.parentNode)
143
+ || !isInnerLeftSpaceSensitiveCssDisplay(node.parentNode.cssDisplay)
144
+ || isTrimmingInnerLeft(node.parentNode))) {
145
+ return false;
146
+ }
147
+ // This node is not leading whitespace sensitive if the previous node
148
+ // creates a block rendering context.
149
+ //
150
+ // example:
151
+ // - <p><div>hello</div> this</p>
152
+ if (node.prev && !isOuterRightWhitespaceSensitiveCssDisplay(node.prev.cssDisplay)) {
153
+ return false;
154
+ }
155
+ // this node is not leading whitespace sensitive if it creates a block
156
+ // rendering context
157
+ //
158
+ // example:
159
+ // - <p>hello <div>this</div></p>
160
+ if (!isOuterLeftWhitespaceSensitiveCssDisplay(node.cssDisplay)) {
161
+ return false;
162
+ }
163
+ return true;
164
+ }
165
+ /**
166
+ * A node is trailing whitespace sensitive when removing (or adding) whitespace
167
+ * between this node and the next sibling (or parent closing tag) would alter the
168
+ * rendered output.
169
+ *
170
+ * As such, it is whitespace _to the right_ of this node (it is not
171
+ * contained by the node).
172
+ *
173
+ * example:
174
+ * ```
175
+ * <p>
176
+ * hello <span>world</span>
177
+ * </p>
178
+ * ```
179
+ *
180
+ * - "hello" is trailing whitespace sensitive
181
+ * - <span>world</span> is not
182
+ * - "world" is trailing whitespace sensitive
183
+ *
184
+ * This is really complicated to get right, so treat it as though it is not
185
+ * the actual solution. We'll default to true and consider the edge cases.
186
+ */
187
+ function isTrailingWhitespaceSensitiveNode(node) {
188
+ if (!node) {
189
+ return false;
190
+ }
191
+ if (node.type === liquid_html_parser_1.NodeTypes.LiquidBranch) {
192
+ const isLastBranch = node.parentNode && node.parentNode.lastChild === node;
193
+ const hasNoLastChild = !node.lastChild;
194
+ const lastChild = node.lastChild;
195
+ const isLastChildTrailingSensitive = !!lastChild && isTrailingWhitespaceSensitiveNode(lastChild);
196
+ // {% if %}{% elsif cond %}<emptythis>{% endif %}
197
+ // {% if %}{% elsif cond %}this{% endif %}
198
+ // {% if %}{% else %}<emptythis>{% endif %}
199
+ // {% if %}{% else %}this{% endif %}
200
+ if (isLastBranch) {
201
+ const isParentInnerRightSensitive = isInnerRightWhitespaceSensitiveCssDisplay(node.parentNode.cssDisplay);
202
+ return isParentInnerRightSensitive && (hasNoLastChild || isLastChildTrailingSensitive);
203
+ }
204
+ // {% if %}<emptythis>{% endif %}
205
+ // {% if %}<emptythis>{% else %}{% endif %}
206
+ // {% if %}{% elsif cond %}<emptythis>{% else %}{% endif %}
207
+ // {% if %}this{% endif %}
208
+ // {% if %}this{% else %}{% endif %}
209
+ // {% if %}{% elsif cond %}this{% else %}{% endif %}
210
+ return hasNoLastChild || isLastChildTrailingSensitive;
211
+ }
212
+ // {% if cond %}<this>{% endif %}
213
+ // {% if cond %}<this><a>{% endif %}
214
+ // {% if cond %}<this><div>{% endif %}
215
+ // {% if cond %}<this><div></div>{% endif %}
216
+ // {% if cond %}<this>{% render 'icon' %}{% endif %}
217
+ if (isHtmlElementWithoutCloseTag(node)) {
218
+ if (!node.lastChild) {
219
+ return isInnerLeftSpaceSensitiveCssDisplay(node.cssDisplay);
220
+ }
221
+ return (createsInlineFormattingContext(node.cssDisplay) &&
222
+ isTrailingWhitespaceSensitiveNode(node.lastChild));
223
+ }
224
+ // '{{ drop -}} text'
225
+ if (isTrimmingOuterRight(node)) {
226
+ return false;
227
+ }
228
+ // <a data-{{ this }}="hi">
229
+ if (node.parentNode &&
230
+ (0, utils_1.isAttributeNode)(node.parentNode) &&
231
+ node.type === liquid_html_parser_1.NodeTypes.LiquidVariableOutput) {
232
+ return true;
233
+ }
234
+ // 'text {{- drop }}'
235
+ if (node.next && isTrimmingOuterLeft(node.next)) {
236
+ return false;
237
+ }
238
+ // the root node and invisible nodes are not trailing whitespace
239
+ // sensitive
240
+ if (!node.parentNode || node.parentNode.cssDisplay === 'none') {
241
+ return false;
242
+ }
243
+ // pre-like nodes are whitespace sensitive (globally), therefore if this
244
+ // node's parent is pre-like, this node is whitespace sensitive to the right.
245
+ if ((0, utils_1.isPreLikeNode)(node.parentNode)) {
246
+ return true;
247
+ }
248
+ // We do it slightly differently than prettier/prettier.
249
+ if ((0, utils_1.isScriptLikeTag)(node)) {
250
+ return false;
251
+ }
252
+ // BRs are not trailing whitespace sensitive, it's an exception as per prettier/language-html
253
+ // https://github.com/prettier/prettier/blob/c36d89712a24fdef753c056f4c82bc87ebe07865/src/language-html/utils/index.js#L290-L296
254
+ if (isHtmlNode(node) && typeof node.name === 'string' && node.name === 'br') {
255
+ return false;
256
+ }
257
+ // The following block handles the case when the node is the last child of its parent.
258
+ //
259
+ // The node would not be trailing whitespace sensitive if any of the following conditions are true:
260
+ // - the parent is the root
261
+ // - this node is pre-like (whitespace outside pre tags is irrelevant)
262
+ // - this node is script-like (since the whitespace following a script is irrelevant)
263
+ // - the parent is not (inner) trailing whitespace sensitive (e.g. block)
264
+ // - the parent is trimming the inner right (e.g. {% form %} hello {%- endform %})
265
+ // - the node is an attribute node
266
+ //
267
+ // prettier-ignore
268
+ if (!node.next && (node.parentNode.type === liquid_html_parser_1.NodeTypes.Document ||
269
+ (0, utils_1.isPreLikeNode)(node) ||
270
+ (0, utils_1.isScriptLikeTag)(node.parentNode) ||
271
+ (!isHtmlElementWithoutCloseTag(node.parentNode) && !isInnerRightWhitespaceSensitiveCssDisplay(node.parentNode.cssDisplay)) ||
272
+ isTrimmingInnerRight(node.parentNode) ||
273
+ (0, utils_1.isAttributeNode)(node))) {
274
+ return false;
275
+ }
276
+ // When the next child is not whitespace sensitive to the outer left.
277
+ //
278
+ // example:
279
+ // <p>Hello <div>world</div></p>
280
+ //
281
+ // 'Hello' is not whitespace sensitive to the right because the next
282
+ // element is a block and doesn't care about whitespace to its left.
283
+ if (node.next && !isOuterLeftWhitespaceSensitiveCssDisplay(node.next.cssDisplay)) {
284
+ return false;
285
+ }
286
+ // That's for when the node would create a block formatting context.
287
+ //
288
+ // example:
289
+ // <p><div>hello</div> {{ drop }}</p>
290
+ //
291
+ // The div would create a block formatting context, so even though
292
+ // {{ drop }} is inline, it isn't because of the block.
293
+ if (!isOuterRightWhitespaceSensitiveCssDisplay(node.cssDisplay)) {
294
+ return false;
295
+ }
296
+ // Default to true. We might be wrong, but we err on the side of caution.
297
+ return true;
298
+ }
299
+ /**
300
+ * Dangling whitespace is whitespace in an empty parent.
301
+ *
302
+ * examples
303
+ * - <div> </div>
304
+ * - {% if A %} {% else %} nope {% endif %}
305
+ */
306
+ function hasDanglingWhitespace(node) {
307
+ if (!isParentNode(node)) {
308
+ return false;
309
+ }
310
+ else if (node.type === liquid_html_parser_1.NodeTypes.Document) {
311
+ return node.children.length === 0 && node.source.length > 0;
312
+ }
313
+ else if (!node.children) {
314
+ return false;
315
+ }
316
+ else if (node.type === liquid_html_parser_1.NodeTypes.LiquidTag &&
317
+ (0, liquid_html_parser_1.isBranchedTag)(node) &&
318
+ node.children.length === 1) {
319
+ return hasDanglingWhitespace(node.firstChild);
320
+ }
321
+ else if (node.children.length > 0) {
322
+ return false;
323
+ }
324
+ return (0, utils_1.isWhitespace)(node.source, node.blockStartPosition.end);
325
+ }
326
+ function hasLeadingWhitespace(node) {
327
+ // Edge case for default branch.
328
+ if (node.type === liquid_html_parser_1.NodeTypes.LiquidBranch && !node.prev) {
329
+ return node.firstChild ? hasLeadingWhitespace(node.firstChild) : hasDanglingWhitespace(node);
330
+ }
331
+ return (0, utils_1.isWhitespace)(node.source, node.position.start - 1);
332
+ }
333
+ function hasTrailingWhitespace(node) {
334
+ if (node.type === liquid_html_parser_1.NodeTypes.LiquidBranch || isHtmlElementWithoutCloseTag(node)) {
335
+ return node.lastChild ? hasTrailingWhitespace(node.lastChild) : hasDanglingWhitespace(node);
336
+ }
337
+ return (0, utils_1.isWhitespace)(node.source, node.position.end);
338
+ }
339
+ function isHtmlNode(node) {
340
+ return liquid_html_parser_1.HtmlNodeTypes.includes(node.type);
341
+ }
342
+ function isLiquidNode(node) {
343
+ return !!node && liquid_html_parser_1.LiquidNodeTypes.includes(node.type);
344
+ }
345
+ function isParentNode(node) {
346
+ return 'children' in node;
347
+ }
348
+ function isTrimmingOuterRight(node) {
349
+ if (!node)
350
+ return false;
351
+ switch (node.type) {
352
+ case liquid_html_parser_1.NodeTypes.LiquidRawTag:
353
+ case liquid_html_parser_1.NodeTypes.LiquidTag: // {% if a %}{% endif -%}, {% assign x -%}
354
+ return (node.delimiterWhitespaceEnd ?? node.whitespaceEnd) === '-';
355
+ case liquid_html_parser_1.NodeTypes.LiquidBranch:
356
+ return false;
357
+ case liquid_html_parser_1.NodeTypes.LiquidVariableOutput: // {{ foo -}}
358
+ return node.whitespaceEnd === '-';
359
+ default:
360
+ return false;
361
+ }
362
+ }
363
+ function isTrimmingOuterLeft(node) {
364
+ if (!node)
365
+ return false;
366
+ switch (node.type) {
367
+ case liquid_html_parser_1.NodeTypes.LiquidRawTag:
368
+ case liquid_html_parser_1.NodeTypes.LiquidTag: // {%- if a %}{% endif %}, {%- assign x = 1 %}
369
+ case liquid_html_parser_1.NodeTypes.LiquidBranch: // {%- else %}
370
+ case liquid_html_parser_1.NodeTypes.LiquidVariableOutput: // {{- 'val' }}
371
+ return node.whitespaceStart === '-';
372
+ default:
373
+ return false;
374
+ }
375
+ }
376
+ function isTrimmingInnerLeft(node) {
377
+ if (!node)
378
+ return false;
379
+ switch (node.type) {
380
+ case liquid_html_parser_1.NodeTypes.LiquidRawTag:
381
+ case liquid_html_parser_1.NodeTypes.LiquidTag: // {% form a -%}{% endform %}
382
+ if (node.delimiterWhitespaceEnd === undefined)
383
+ return false;
384
+ return node.whitespaceEnd === '-';
385
+ case liquid_html_parser_1.NodeTypes.LiquidBranch: // {% if a -%}{% else -%}{% endif %}
386
+ // This branch should never happen.
387
+ if (!node.parentNode || node.parentNode.type !== liquid_html_parser_1.NodeTypes.LiquidTag) {
388
+ return false;
389
+ }
390
+ // First branch gets this from the parent
391
+ if (!node.prev) {
392
+ return isTrimmingInnerLeft(node.parentNode);
393
+ }
394
+ // Otherwise gets it from the delimiter. e.g. {% else -%}
395
+ return node.whitespaceEnd === '-';
396
+ case liquid_html_parser_1.NodeTypes.LiquidVariableOutput:
397
+ default:
398
+ return false;
399
+ }
400
+ }
401
+ function isTrimmingInnerRight(node) {
402
+ if (!node)
403
+ return false;
404
+ switch (node.type) {
405
+ case liquid_html_parser_1.NodeTypes.LiquidRawTag:
406
+ case liquid_html_parser_1.NodeTypes.LiquidTag: // {% if a %}{%- endif %}
407
+ if (node.delimiterWhitespaceStart === undefined)
408
+ return false;
409
+ return node.delimiterWhitespaceStart === '-';
410
+ case liquid_html_parser_1.NodeTypes.LiquidBranch:
411
+ // This branch should never happen.
412
+ if (!node.parentNode || node.parentNode.type !== liquid_html_parser_1.NodeTypes.LiquidTag) {
413
+ return false;
414
+ }
415
+ // Last branch gets this from the parent
416
+ if (!node.next) {
417
+ return isTrimmingInnerRight(node.parentNode);
418
+ }
419
+ // Otherwise gets it from the next branch
420
+ return isTrimmingOuterLeft(node.next);
421
+ case liquid_html_parser_1.NodeTypes.LiquidVariableOutput:
422
+ default:
423
+ return false;
424
+ }
425
+ }
426
+ function createsInlineFormattingContext(cssDisplay) {
427
+ return (isBlockLikeCssDisplay(cssDisplay) || cssDisplay === 'inline' || cssDisplay === 'inline-block');
428
+ }
429
+ function isBlockLikeCssDisplay(cssDisplay) {
430
+ return cssDisplay === 'block' || cssDisplay === 'list-item' || cssDisplay.startsWith('table');
431
+ }
432
+ function isInnerLeftSpaceSensitiveCssDisplay(cssDisplay) {
433
+ return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== 'inline-block';
434
+ }
435
+ function isInnerRightWhitespaceSensitiveCssDisplay(cssDisplay) {
436
+ return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== 'inline-block';
437
+ }
438
+ function isOuterLeftWhitespaceSensitiveCssDisplay(cssDisplay) {
439
+ return !isBlockLikeCssDisplay(cssDisplay);
440
+ }
441
+ function isOuterRightWhitespaceSensitiveCssDisplay(cssDisplay) {
442
+ return !isBlockLikeCssDisplay(cssDisplay);
443
+ }
444
+ function isDanglingSpaceSensitiveCssDisplay(cssDisplay) {
445
+ return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== 'inline-block';
446
+ }
447
+ function getNodeCssStyleWhiteSpace(node) {
448
+ return ((isHtmlNode(node) && typeof node.name === 'string' && constants_evaluate_1.CSS_WHITE_SPACE_TAGS[node.name]) ||
449
+ (isLiquidNode(node) &&
450
+ 'name' in node &&
451
+ typeof node.name === 'string' &&
452
+ constants_evaluate_1.CSS_WHITE_SPACE_LIQUID_TAGS[node.name]) ||
453
+ constants_evaluate_1.CSS_WHITE_SPACE_DEFAULT);
454
+ }
455
+ function isHtmlElementWithoutCloseTag(node) {
456
+ return (!!node &&
457
+ node.type === liquid_html_parser_1.NodeTypes.HtmlElement &&
458
+ node.blockEndPosition.start === node.blockEndPosition.end);
459
+ }
460
+ //# sourceMappingURL=augment-with-whitespace-helpers.js.map
@@ -0,0 +1 @@
1
+ export declare const AUGMENTATION_PIPELINE: import("../../types").Augment<import("../../types").WithParent & import("../../types").WithSiblings & import("../../types").WithFamily & import("../../types").WithCssProperties>[];
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AUGMENTATION_PIPELINE = void 0;
4
+ const augment_with_css_properties_1 = require("./augment-with-css-properties");
5
+ const augment_with_parent_1 = require("./augment-with-parent");
6
+ const augment_with_siblings_1 = require("./augment-with-siblings");
7
+ const augment_with_whitespace_helpers_1 = require("./augment-with-whitespace-helpers");
8
+ const augment_with_family_1 = require("./augment-with-family");
9
+ exports.AUGMENTATION_PIPELINE = [
10
+ augment_with_parent_1.augmentWithParent,
11
+ augment_with_siblings_1.augmentWithSiblings,
12
+ augment_with_family_1.augmentWithFamily,
13
+ augment_with_css_properties_1.augmentWithCSSProperties,
14
+ augment_with_whitespace_helpers_1.augmentWithWhitespaceHelpers,
15
+ ];
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ import { doc } from 'prettier';
2
+ import { AstPath, LiquidHtmlNode, LiquidParserOptions, LiquidPrinter, LiquidPrinterArgs } from '../../types';
3
+ export type HasChildren = Extract<LiquidHtmlNode, {
4
+ children?: LiquidHtmlNode[];
5
+ }>;
6
+ export declare function printChildren(path: AstPath<HasChildren>, options: LiquidParserOptions, print: LiquidPrinter, args: LiquidPrinterArgs): (doc.builders.BreakParent | (string | any[] | doc.builders.Concat | doc.builders.Line | doc.builders.Align | doc.builders.BreakParent | doc.builders.Cursor | doc.builders.Fill | doc.builders.Group | doc.builders.IfBreak | doc.builders.Indent | doc.builders.IndentIfBreak | doc.builders.Label | doc.builders.LineSuffix | doc.builders.LineSuffixBoundary | doc.builders.Trim)[])[];