@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,44 @@
1
+ import { NodeTypes, Position } from '@platformos/liquid-html-parser';
2
+ import { HtmlSelfClosingElement, LiquidHtmlNode, TextNode, LiquidNode, HtmlNode, HtmlVoidElement, HtmlComment, HtmlElement, LiquidTag, AttributeNode, HtmlDanglingMarkerClose } from '../../types';
3
+ export declare function isScriptLikeTag(node: {
4
+ type: NodeTypes;
5
+ }): boolean;
6
+ export declare function isPreLikeNode(node: {
7
+ cssWhitespace: string;
8
+ }): boolean;
9
+ export declare function hasNoCloseMarker(node: LiquidHtmlNode): node is HtmlComment | HtmlVoidElement | HtmlSelfClosingElement | HtmlDanglingMarkerClose | HtmlElement;
10
+ export declare function hasNoChildren(node: LiquidHtmlNode): node is HtmlComment | HtmlVoidElement | HtmlSelfClosingElement | HtmlDanglingMarkerClose;
11
+ export declare function isHtmlDanglingMarkerOpen(node: LiquidHtmlNode): node is Omit<HtmlElement, 'blockEndPosition'> & {
12
+ blockEndPosition: Position;
13
+ };
14
+ export declare function isHtmlDanglingMarkerClose(node: LiquidHtmlNode): node is HtmlDanglingMarkerClose;
15
+ export declare function isHtmlComment(node: LiquidHtmlNode): node is HtmlComment;
16
+ export declare function isSelfClosing(node: LiquidHtmlNode): node is HtmlSelfClosingElement;
17
+ export declare function isVoidElement(node: LiquidHtmlNode): node is HtmlVoidElement;
18
+ export declare function isHtmlElement(node: LiquidHtmlNode): node is HtmlElement;
19
+ export declare function isTextLikeNode(node: LiquidHtmlNode | undefined): node is TextNode;
20
+ export declare function isLiquidNode(node: LiquidHtmlNode | undefined): node is LiquidNode;
21
+ export declare function isMultilineLiquidTag(node: LiquidHtmlNode | undefined): node is LiquidTag;
22
+ export declare function isHtmlNode(node: LiquidHtmlNode | undefined): node is HtmlNode;
23
+ export declare function isAttributeNode(node: LiquidHtmlNode): node is AttributeNode & {
24
+ parentNode: HtmlNode;
25
+ };
26
+ export declare function hasNonTextChild(node: LiquidHtmlNode): any;
27
+ export declare function shouldPreserveContent(node: LiquidHtmlNode): boolean;
28
+ export declare function isPrettierIgnoreHtmlNode(node: LiquidHtmlNode | undefined): node is HtmlComment;
29
+ export declare function isPrettierIgnoreLiquidNode(node: LiquidHtmlNode | undefined): node is LiquidTag;
30
+ export declare function isPrettierIgnoreNode(node: LiquidHtmlNode | undefined): node is HtmlComment | LiquidTag;
31
+ export declare function hasPrettierIgnore(node: LiquidHtmlNode): boolean;
32
+ export declare function isPrettierIgnoreAttributeNode(node: LiquidHtmlNode | undefined): boolean;
33
+ export declare function forceNextEmptyLine(node: LiquidHtmlNode | undefined): boolean;
34
+ /** firstChild leadingSpaces and lastChild trailingSpaces */
35
+ export declare function forceBreakContent(node: LiquidHtmlNode): boolean | undefined;
36
+ /** spaces between children */
37
+ export declare function forceBreakChildren(node: LiquidHtmlNode): boolean;
38
+ export declare function preferHardlineAsSurroundingSpaces(node: LiquidHtmlNode): boolean | undefined;
39
+ export declare function preferHardlineAsLeadingSpaces(node: LiquidHtmlNode): boolean;
40
+ export declare function preferHardlineAsTrailingSpaces(node: LiquidHtmlNode): boolean;
41
+ export declare function hasMeaningfulLackOfLeadingWhitespace(node: LiquidHtmlNode): boolean;
42
+ export declare function hasMeaningfulLackOfTrailingWhitespace(node: LiquidHtmlNode): boolean;
43
+ export declare function hasMeaningfulLackOfDanglingWhitespace(node: LiquidHtmlNode): boolean;
44
+ export declare function getLastDescendant(node: LiquidHtmlNode): LiquidHtmlNode;
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isScriptLikeTag = isScriptLikeTag;
4
+ exports.isPreLikeNode = isPreLikeNode;
5
+ exports.hasNoCloseMarker = hasNoCloseMarker;
6
+ exports.hasNoChildren = hasNoChildren;
7
+ exports.isHtmlDanglingMarkerOpen = isHtmlDanglingMarkerOpen;
8
+ exports.isHtmlDanglingMarkerClose = isHtmlDanglingMarkerClose;
9
+ exports.isHtmlComment = isHtmlComment;
10
+ exports.isSelfClosing = isSelfClosing;
11
+ exports.isVoidElement = isVoidElement;
12
+ exports.isHtmlElement = isHtmlElement;
13
+ exports.isTextLikeNode = isTextLikeNode;
14
+ exports.isLiquidNode = isLiquidNode;
15
+ exports.isMultilineLiquidTag = isMultilineLiquidTag;
16
+ exports.isHtmlNode = isHtmlNode;
17
+ exports.isAttributeNode = isAttributeNode;
18
+ exports.hasNonTextChild = hasNonTextChild;
19
+ exports.shouldPreserveContent = shouldPreserveContent;
20
+ exports.isPrettierIgnoreHtmlNode = isPrettierIgnoreHtmlNode;
21
+ exports.isPrettierIgnoreLiquidNode = isPrettierIgnoreLiquidNode;
22
+ exports.isPrettierIgnoreNode = isPrettierIgnoreNode;
23
+ exports.hasPrettierIgnore = hasPrettierIgnore;
24
+ exports.isPrettierIgnoreAttributeNode = isPrettierIgnoreAttributeNode;
25
+ exports.forceNextEmptyLine = forceNextEmptyLine;
26
+ exports.forceBreakContent = forceBreakContent;
27
+ exports.forceBreakChildren = forceBreakChildren;
28
+ exports.preferHardlineAsSurroundingSpaces = preferHardlineAsSurroundingSpaces;
29
+ exports.preferHardlineAsLeadingSpaces = preferHardlineAsLeadingSpaces;
30
+ exports.preferHardlineAsTrailingSpaces = preferHardlineAsTrailingSpaces;
31
+ exports.hasMeaningfulLackOfLeadingWhitespace = hasMeaningfulLackOfLeadingWhitespace;
32
+ exports.hasMeaningfulLackOfTrailingWhitespace = hasMeaningfulLackOfTrailingWhitespace;
33
+ exports.hasMeaningfulLackOfDanglingWhitespace = hasMeaningfulLackOfDanglingWhitespace;
34
+ exports.getLastDescendant = getLastDescendant;
35
+ const liquid_html_parser_1 = require("@platformos/liquid-html-parser");
36
+ const array_1 = require("./array");
37
+ function isScriptLikeTag(node) {
38
+ return node.type === liquid_html_parser_1.NodeTypes.HtmlRawNode;
39
+ }
40
+ function isPreLikeNode(node) {
41
+ return node.cssWhitespace.startsWith('pre');
42
+ }
43
+ // A bit like self-closing except we distinguish between them.
44
+ // Comments are also considered self-closing.
45
+ function hasNoCloseMarker(node) {
46
+ return hasNoChildren(node) || isHtmlDanglingMarkerOpen(node);
47
+ }
48
+ function hasNoChildren(node) {
49
+ return (isSelfClosing(node) ||
50
+ isVoidElement(node) ||
51
+ isHtmlComment(node) ||
52
+ isHtmlDanglingMarkerClose(node));
53
+ }
54
+ function isHtmlDanglingMarkerOpen(node) {
55
+ return (node.type === liquid_html_parser_1.NodeTypes.HtmlElement && node.blockEndPosition.start === node.blockEndPosition.end);
56
+ }
57
+ function isHtmlDanglingMarkerClose(node) {
58
+ return node.type === liquid_html_parser_1.NodeTypes.HtmlDanglingMarkerClose;
59
+ }
60
+ function isHtmlComment(node) {
61
+ return node.type === liquid_html_parser_1.NodeTypes.HtmlComment;
62
+ }
63
+ function isSelfClosing(node) {
64
+ return node.type === liquid_html_parser_1.NodeTypes.HtmlSelfClosingElement;
65
+ }
66
+ function isVoidElement(node) {
67
+ return node.type === liquid_html_parser_1.NodeTypes.HtmlVoidElement;
68
+ }
69
+ function isHtmlElement(node) {
70
+ return node.type === liquid_html_parser_1.NodeTypes.HtmlElement;
71
+ }
72
+ function isTextLikeNode(node) {
73
+ return !!node && node.type === liquid_html_parser_1.NodeTypes.TextNode;
74
+ }
75
+ function isLiquidNode(node) {
76
+ return !!node && liquid_html_parser_1.LiquidNodeTypes.includes(node.type);
77
+ }
78
+ function isMultilineLiquidTag(node) {
79
+ return !!node && node.type === liquid_html_parser_1.NodeTypes.LiquidTag && !!node.children && !(0, array_1.isEmpty)(node.children);
80
+ }
81
+ function isHtmlNode(node) {
82
+ return !!node && liquid_html_parser_1.HtmlNodeTypes.includes(node.type);
83
+ }
84
+ function isAttributeNode(node) {
85
+ return (isHtmlNode(node.parentNode) &&
86
+ 'attributes' in node.parentNode &&
87
+ node.parentNode.attributes.indexOf(node) !== -1);
88
+ }
89
+ function hasNonTextChild(node) {
90
+ return (node.children &&
91
+ node.children.some((child) => child.type !== liquid_html_parser_1.NodeTypes.TextNode));
92
+ }
93
+ function shouldPreserveContent(node) {
94
+ // // unterminated node in ie conditional comment
95
+ // // e.g. <!--[if lt IE 9]><html><![endif]-->
96
+ // if (
97
+ // node.type === "ieConditionalComment" &&
98
+ // node.lastChild &&
99
+ // !node.lastChild.isSelfClosing &&
100
+ // !node.lastChild.endSourceSpan
101
+ // ) {
102
+ // return true;
103
+ // }
104
+ // // incomplete html in ie conditional comment
105
+ // // e.g. <!--[if lt IE 9]></div><![endif]-->
106
+ // if (node.type === "ieConditionalComment" && !node.complete) {
107
+ // return true;
108
+ // }
109
+ // TODO: Handle pre correctly?
110
+ if (isPreLikeNode(node)) {
111
+ return true;
112
+ }
113
+ return false;
114
+ }
115
+ function isPrettierIgnoreHtmlNode(node) {
116
+ return (!!node && node.type === liquid_html_parser_1.NodeTypes.HtmlComment && /^\s*prettier-ignore(?=\s|$)/m.test(node.body));
117
+ }
118
+ function isPrettierIgnoreLiquidNode(node) {
119
+ return (!!node &&
120
+ node.type === liquid_html_parser_1.NodeTypes.LiquidTag &&
121
+ node.name === '#' &&
122
+ /^\s*prettier-ignore(?=\s|$)/m.test(node.markup));
123
+ }
124
+ function isPrettierIgnoreNode(node) {
125
+ return isPrettierIgnoreLiquidNode(node) || isPrettierIgnoreHtmlNode(node);
126
+ }
127
+ function hasPrettierIgnore(node) {
128
+ return isPrettierIgnoreNode(node) || isPrettierIgnoreNode(node.prev);
129
+ }
130
+ function getPrettierIgnoreAttributeCommentData(value) {
131
+ const match = value.trim().match(/prettier-ignore-attribute(?:s?)(?:\s+(.+))?$/s);
132
+ if (!match) {
133
+ return false;
134
+ }
135
+ if (!match[1]) {
136
+ return true;
137
+ }
138
+ // TODO We should support 'prettier-ignore-attribute a,b,c' and allow users to not
139
+ // format the insides of some attributes.
140
+ //
141
+ // But since we don't reformat the insides of attributes yet (because of
142
+ // issue #4), that feature doesn't really make sense.
143
+ //
144
+ // For now, we'll only support `prettier-ignore-attribute`
145
+ //
146
+ // https://github.com/Shopify/prettier-plugin-liquid/issues/4
147
+ //
148
+ // return match[1].split(/\s+/);
149
+ return true;
150
+ }
151
+ function isPrettierIgnoreAttributeNode(node) {
152
+ if (!node)
153
+ return false;
154
+ if (node.type === liquid_html_parser_1.NodeTypes.HtmlComment) {
155
+ return getPrettierIgnoreAttributeCommentData(node.body);
156
+ }
157
+ if (node.type === liquid_html_parser_1.NodeTypes.LiquidTag && node.name === '#') {
158
+ return getPrettierIgnoreAttributeCommentData(node.markup);
159
+ }
160
+ return false;
161
+ }
162
+ function forceNextEmptyLine(node) {
163
+ if (!node)
164
+ return false;
165
+ if (!node.next)
166
+ return false;
167
+ const source = node.source;
168
+ // Current implementation: force next empty line when two consecutive
169
+ // lines exist between nodes.
170
+ let tmp;
171
+ tmp = source.indexOf('\n', node.position.end);
172
+ if (tmp === -1)
173
+ return false;
174
+ tmp = source.indexOf('\n', tmp + 1);
175
+ if (tmp === -1)
176
+ return false;
177
+ return tmp < node.next.position.start;
178
+ }
179
+ /** firstChild leadingSpaces and lastChild trailingSpaces */
180
+ function forceBreakContent(node) {
181
+ return (forceBreakChildren(node) ||
182
+ (node.type === liquid_html_parser_1.NodeTypes.HtmlElement &&
183
+ node.children.length > 0 &&
184
+ (isTagNameIncluded(['body', 'script', 'style'], node.name) ||
185
+ node.children.some((child) => hasNonTextChild(child)))) ||
186
+ (node.firstChild &&
187
+ node.firstChild === node.lastChild &&
188
+ node.firstChild.type !== liquid_html_parser_1.NodeTypes.TextNode &&
189
+ hasLeadingLineBreak(node.firstChild) &&
190
+ (!node.lastChild.isTrailingWhitespaceSensitive || hasTrailingLineBreak(node.lastChild))));
191
+ }
192
+ /** spaces between children */
193
+ function forceBreakChildren(node) {
194
+ return (node.type === liquid_html_parser_1.NodeTypes.HtmlElement &&
195
+ node.children.length > 0 &&
196
+ (isTagNameIncluded(['html', 'head', 'ul', 'ol', 'select'], node.name) ||
197
+ (node.cssDisplay.startsWith('table') && node.cssDisplay !== 'table-cell')));
198
+ }
199
+ function preferHardlineAsSurroundingSpaces(node) {
200
+ switch (node.type) {
201
+ // case 'ieConditionalComment':
202
+ case liquid_html_parser_1.NodeTypes.HtmlComment:
203
+ return true;
204
+ case liquid_html_parser_1.NodeTypes.HtmlElement:
205
+ return isTagNameIncluded(['script', 'select'], node.name);
206
+ case liquid_html_parser_1.NodeTypes.LiquidTag:
207
+ if ((node.prev && isTextLikeNode(node.prev)) || (node.next && isTextLikeNode(node.next))) {
208
+ return false;
209
+ }
210
+ return node.children && node.children.length > 0;
211
+ }
212
+ return false;
213
+ }
214
+ function preferHardlineAsLeadingSpaces(node) {
215
+ return (preferHardlineAsSurroundingSpaces(node) ||
216
+ (isLiquidNode(node) && node.prev && isLiquidNode(node.prev)) ||
217
+ (node.prev && preferHardlineAsTrailingSpaces(node.prev)) ||
218
+ hasSurroundingLineBreak(node));
219
+ }
220
+ function preferHardlineAsTrailingSpaces(node) {
221
+ return (preferHardlineAsSurroundingSpaces(node) ||
222
+ (isLiquidNode(node) && node.next && (isLiquidNode(node.next) || isHtmlNode(node.next))) ||
223
+ (node.type === liquid_html_parser_1.NodeTypes.HtmlElement && isTagNameIncluded(['br'], node.name)) ||
224
+ hasSurroundingLineBreak(node));
225
+ }
226
+ function hasMeaningfulLackOfLeadingWhitespace(node) {
227
+ return node.isLeadingWhitespaceSensitive && !node.hasLeadingWhitespace;
228
+ }
229
+ function hasMeaningfulLackOfTrailingWhitespace(node) {
230
+ return node.isTrailingWhitespaceSensitive && !node.hasTrailingWhitespace;
231
+ }
232
+ function hasMeaningfulLackOfDanglingWhitespace(node) {
233
+ return node.isDanglingWhitespaceSensitive && !node.hasDanglingWhitespace;
234
+ }
235
+ function hasSurroundingLineBreak(node) {
236
+ return hasLeadingLineBreak(node) && hasTrailingLineBreak(node);
237
+ }
238
+ function hasLeadingLineBreak(node) {
239
+ if (node.type === liquid_html_parser_1.NodeTypes.Document)
240
+ return false;
241
+ return (node.hasLeadingWhitespace &&
242
+ hasLineBreakInRange(node.source, node.prev
243
+ ? node.prev.position.end
244
+ : node.parentNode.blockStartPosition
245
+ ? node.parentNode.blockStartPosition.end
246
+ : node.parentNode.position.start, node.position.start));
247
+ }
248
+ function hasTrailingLineBreak(node) {
249
+ if (node.type === liquid_html_parser_1.NodeTypes.Document)
250
+ return false;
251
+ return (node.hasTrailingWhitespace &&
252
+ hasLineBreakInRange(node.source, node.position.end, node.next
253
+ ? node.next.position.start
254
+ : node.parentNode.blockEndPosition
255
+ ? node.parentNode.blockEndPosition.start
256
+ : node.parentNode.position.end));
257
+ }
258
+ function hasLineBreakInRange(source, start, end) {
259
+ const index = source.indexOf('\n', start);
260
+ return index !== -1 && index < end;
261
+ }
262
+ function getLastDescendant(node) {
263
+ return node.lastChild ? getLastDescendant(node.lastChild) : node;
264
+ }
265
+ function isTagNameIncluded(collection, name) {
266
+ if (name.length !== 1 || name[0].type !== liquid_html_parser_1.NodeTypes.TextNode)
267
+ return false;
268
+ return collection.includes(name[0].value);
269
+ }
270
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1,15 @@
1
+ import { Position } from '@platformos/liquid-html-parser';
2
+ import { LiquidAstPath, LiquidParserOptions } from '../../types';
3
+ export declare function isWhitespace(source: string, loc: number): boolean;
4
+ export declare const trim: (x: string) => string;
5
+ export declare const trimEnd: (x: string) => string;
6
+ export declare function bodyLines(str: string): string[];
7
+ export declare function markupLines(markup: string): string[];
8
+ export declare function reindent(lines: string[], skipFirst?: boolean): string[];
9
+ export declare function originallyHadLineBreaks(path: LiquidAstPath, { locStart, locEnd }: LiquidParserOptions): boolean;
10
+ export declare function hasLineBreakInRange(source: string, locStart: number, locEnd: number): boolean;
11
+ export declare function hasMoreThanOneNewLineBetweenNodes(source: string, prev: {
12
+ position: Position;
13
+ } | undefined, next: {
14
+ position: Position;
15
+ } | undefined): boolean;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trimEnd = exports.trim = void 0;
4
+ exports.isWhitespace = isWhitespace;
5
+ exports.bodyLines = bodyLines;
6
+ exports.markupLines = markupLines;
7
+ exports.reindent = reindent;
8
+ exports.originallyHadLineBreaks = originallyHadLineBreaks;
9
+ exports.hasLineBreakInRange = hasLineBreakInRange;
10
+ exports.hasMoreThanOneNewLineBetweenNodes = hasMoreThanOneNewLineBetweenNodes;
11
+ function isWhitespace(source, loc) {
12
+ if (loc < 0 || loc >= source.length)
13
+ return false;
14
+ return !!source[loc].match(/\s/);
15
+ }
16
+ const trim = (x) => x.trim();
17
+ exports.trim = trim;
18
+ const trimEnd = (x) => x.trimEnd();
19
+ exports.trimEnd = trimEnd;
20
+ function bodyLines(str) {
21
+ return str
22
+ .replace(/^(?: |\t)*(\r?\n)*|\s*$/g, '') // only want the meat
23
+ .split(/\r?\n/);
24
+ }
25
+ function markupLines(markup) {
26
+ return markup.trim().split('\n');
27
+ }
28
+ function reindent(lines, skipFirst = false) {
29
+ const minIndentLevel = lines
30
+ .filter((_, i) => (skipFirst ? i > 0 : true))
31
+ .filter((line) => line.trim().length > 0)
32
+ .map((line) => line.match(/^\s*/)[0].length)
33
+ .reduce((a, b) => Math.min(a, b), Infinity);
34
+ if (minIndentLevel === Infinity) {
35
+ return lines;
36
+ }
37
+ const indentStrip = new RegExp('^' + '\\s'.repeat(minIndentLevel));
38
+ return lines.map((line) => line.replace(indentStrip, '')).map(exports.trimEnd);
39
+ }
40
+ function originallyHadLineBreaks(path, { locStart, locEnd }) {
41
+ const node = path.getValue();
42
+ return hasLineBreakInRange(node.source, locStart(node), locEnd(node));
43
+ }
44
+ function hasLineBreakInRange(source, locStart, locEnd) {
45
+ const indexOfNewLine = source.indexOf('\n', locStart);
46
+ return 0 <= indexOfNewLine && indexOfNewLine < locEnd;
47
+ }
48
+ function hasMoreThanOneNewLineBetweenNodes(source, prev, next) {
49
+ if (!prev || !next)
50
+ return false;
51
+ const between = source.slice(prev.position.end, next.position.start);
52
+ const count = between.match(/\n/g)?.length || 0;
53
+ return count > 1;
54
+ }
55
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1,85 @@
1
+ import { Doc } from 'prettier';
2
+ import type { AstPath } from 'prettier';
3
+ import type { ParserOptions as ParserOptions3 } from 'prettier3';
4
+ import * as AST from '@platformos/liquid-html-parser';
5
+ export type CommonKeys<T1, T2> = Extract<keyof T1, keyof T2>;
6
+ export type { AstPath };
7
+ export type ParserOptions<T = any> = ParserOptions3<T>;
8
+ export declare function isLiquidHtmlNode(value: any): value is LiquidHtmlNode;
9
+ export type LiquidAstPath = AstPath<LiquidHtmlNode>;
10
+ export type LiquidParserOptions = ParserOptions<LiquidHtmlNode> & {
11
+ singleAttributePerLine: boolean;
12
+ singleLineLinkTags: boolean;
13
+ liquidSingleQuote: boolean;
14
+ embeddedSingleQuote: boolean;
15
+ indentSchema: boolean;
16
+ captureWhitespaceSensitivity: 'strict' | 'ignore';
17
+ liquidDocParamDash: boolean;
18
+ };
19
+ export type LiquidPrinterArgs = {
20
+ leadingSpaceGroupId?: symbol[] | symbol;
21
+ trailingSpaceGroupId?: symbol[] | symbol;
22
+ isLiquidStatement?: boolean;
23
+ truncate?: boolean;
24
+ };
25
+ export type LiquidPrinter = (path: AstPath<LiquidHtmlNode>, args?: LiquidPrinterArgs) => Doc;
26
+ export declare const nonTraversableProperties: Set<string>;
27
+ export type Augmented<T, Aug> = {
28
+ [Property in keyof T]: [T[Property]] extends [(infer Item)[] | undefined] ? [Item] extends [AST.LiquidHtmlNode] ? Augmented<Item, Aug>[] : Item[] : T[Property] extends infer P ? P extends AST.LiquidHtmlNode ? Augmented<P, Aug> : P : never;
29
+ } & Aug;
30
+ export type AllAugmentations = WithParent & WithSiblings & WithFamily & WithCssProperties & WithWhitespaceHelpers;
31
+ export type WithParent = {
32
+ parentNode?: ParentNode;
33
+ };
34
+ export type WithSiblings = {
35
+ prev: LiquidHtmlNode | undefined;
36
+ next: LiquidHtmlNode | undefined;
37
+ };
38
+ export type WithFamily = {
39
+ firstChild: LiquidHtmlNode | undefined;
40
+ lastChild: LiquidHtmlNode | undefined;
41
+ };
42
+ export type WithCssProperties = {
43
+ cssDisplay: string;
44
+ cssWhitespace: string;
45
+ };
46
+ export type WithWhitespaceHelpers = {
47
+ isDanglingWhitespaceSensitive: boolean;
48
+ isWhitespaceSensitive: boolean;
49
+ isLeadingWhitespaceSensitive: boolean;
50
+ isTrailingWhitespaceSensitive: boolean;
51
+ isIndentationSensitive: boolean;
52
+ hasLeadingWhitespace: boolean;
53
+ hasTrailingWhitespace: boolean;
54
+ hasDanglingWhitespace: boolean;
55
+ };
56
+ export type AugmentedNode<Aug> = Augmented<AST.LiquidHtmlNode, Aug>;
57
+ export type Augment<Aug> = <NodeType extends AugmentedNode<Aug>>(options: LiquidParserOptions, node: NodeType, parentNode?: NodeType) => void;
58
+ export type LiquidHtmlNode = Augmented<AST.LiquidHtmlNode, AllAugmentations>;
59
+ export type DocumentNode = Augmented<AST.DocumentNode, AllAugmentations>;
60
+ export type LiquidNode = Augmented<AST.LiquidNode, AllAugmentations>;
61
+ export type LiquidStatement = Augmented<AST.LiquidStatement, AllAugmentations>;
62
+ export type ParentNode = Augmented<AST.ParentNode, AllAugmentations>;
63
+ export type LiquidRawTag = Augmented<AST.LiquidRawTag, AllAugmentations>;
64
+ export type LiquidTag = Augmented<AST.LiquidTag, AllAugmentations>;
65
+ export type LiquidTagNamed = Augmented<AST.LiquidTagNamed, AllAugmentations>;
66
+ export type LiquidBranch = Augmented<AST.LiquidBranch, AllAugmentations>;
67
+ export type LiquidBranchNamed = Augmented<AST.LiquidBranchNamed, AllAugmentations>;
68
+ export type LiquidVariableOutput = Augmented<AST.LiquidVariableOutput, AllAugmentations>;
69
+ export type HtmlNode = Augmented<AST.HtmlNode, AllAugmentations>;
70
+ export type HtmlTag = Exclude<HtmlNode, HtmlComment>;
71
+ export type HtmlElement = Augmented<AST.HtmlElement, AllAugmentations>;
72
+ export type HtmlDanglingMarkerClose = Augmented<AST.HtmlDanglingMarkerClose, AllAugmentations>;
73
+ export type HtmlVoidElement = Augmented<AST.HtmlVoidElement, AllAugmentations>;
74
+ export type HtmlSelfClosingElement = Augmented<AST.HtmlSelfClosingElement, AllAugmentations>;
75
+ export type HtmlRawNode = Augmented<AST.HtmlRawNode, AllAugmentations>;
76
+ export type HtmlDoctype = Augmented<AST.HtmlDoctype, AllAugmentations>;
77
+ export type HtmlComment = Augmented<AST.HtmlComment, AllAugmentations>;
78
+ export type AttributeNode = Augmented<AST.AttributeNode, AllAugmentations>;
79
+ export type AttrSingleQuoted = Augmented<AST.AttrSingleQuoted, AllAugmentations>;
80
+ export type AttrDoubleQuoted = Augmented<AST.AttrDoubleQuoted, AllAugmentations>;
81
+ export type AttrUnquoted = Augmented<AST.AttrUnquoted, AllAugmentations>;
82
+ export type AttrEmpty = Augmented<AST.AttrEmpty, AllAugmentations>;
83
+ export type LiquidExpression = Augmented<AST.LiquidExpression, AllAugmentations>;
84
+ export type TextNode = Augmented<AST.TextNode, AllAugmentations>;
85
+ export type RawMarkup = Augmented<AST.RawMarkup, AllAugmentations>;
package/dist/types.js ADDED
@@ -0,0 +1,53 @@
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.nonTraversableProperties = void 0;
37
+ exports.isLiquidHtmlNode = isLiquidHtmlNode;
38
+ const AST = __importStar(require("@platformos/liquid-html-parser"));
39
+ function isLiquidHtmlNode(value) {
40
+ return (value !== null &&
41
+ typeof value === 'object' &&
42
+ 'type' in value &&
43
+ AST.NodeTypes.hasOwnProperty(value.type));
44
+ }
45
+ // Those properties create loops that would make walking infinite
46
+ exports.nonTraversableProperties = new Set([
47
+ 'parentNode',
48
+ 'prev',
49
+ 'next',
50
+ 'firstChild',
51
+ 'lastChild',
52
+ ]);
53
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,6 @@
1
+ import { LiquidHtmlNode } from './types';
2
+ export declare function assertNever(x: never): never;
3
+ export declare function locStart(node: Pick<LiquidHtmlNode, 'position'> | string): number;
4
+ export declare function locEnd(node: Pick<LiquidHtmlNode, 'position'> | string): number;
5
+ export declare function deepGet<T = any>(path: (string | number)[], obj: any): T;
6
+ export declare function dropLast<T>(n: number, xs: readonly T[]): T[];
package/dist/utils.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertNever = assertNever;
4
+ exports.locStart = locStart;
5
+ exports.locEnd = locEnd;
6
+ exports.deepGet = deepGet;
7
+ exports.dropLast = dropLast;
8
+ function assertNever(x) {
9
+ throw new Error(`Unexpected object: ${x.type}`);
10
+ }
11
+ function locStart(node) {
12
+ if (typeof node === 'string')
13
+ return -1;
14
+ return node.position.start;
15
+ }
16
+ function locEnd(node) {
17
+ if (typeof node === 'string')
18
+ return -1;
19
+ return node.position.end;
20
+ }
21
+ function deepGet(path, obj) {
22
+ return path.reduce((curr, k) => {
23
+ if (curr && curr[k] !== undefined)
24
+ return curr[k];
25
+ return undefined;
26
+ }, obj);
27
+ }
28
+ function dropLast(n, xs) {
29
+ const result = [...xs];
30
+ for (let i = 0; i < n; i++) {
31
+ result.pop();
32
+ }
33
+ return result;
34
+ }
35
+ //# sourceMappingURL=utils.js.map
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@platformos/prettier-plugin-liquid",
3
+ "version": "0.0.2",
4
+ "description": "Prettier Liquid/HTML plugin for platformOS",
5
+ "author": "platformOS",
6
+ "homepage": "https://github.com/Platform-OS/platformos-tools/tree/main/packages/prettier-plugin-liquid#readme",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/Platform-OS/platformos-tools.git",
10
+ "directory": "packages/prettier-plugin-liquid"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/Platform-OS/platformos-tools/issues"
14
+ },
15
+ "license": "MIT",
16
+ "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "publishConfig": {
19
+ "access": "public",
20
+ "@platformos:registry": "https://registry.npmjs.org"
21
+ },
22
+ "files": [
23
+ "grammar/*",
24
+ "dist/**/*.js",
25
+ "dist/**/*.ts",
26
+ "standalone.js",
27
+ "standalone.d.ts",
28
+ "standalone.js.LICENSE.txt",
29
+ "ThirdPartyNotices.txt"
30
+ ],
31
+ "scripts": {
32
+ "build": "yarn build:ts && yarn build:standalone",
33
+ "build:ci": "yarn build",
34
+ "build:standalone": "webpack -c webpack.config.js",
35
+ "build:ts": "tsc -p tsconfig.build.json",
36
+ "format": "prettier --write --ignore-unknown \"src/**/*.ts\"",
37
+ "format:check": "prettier --check --ignore-unknown \"src/**/*.ts\"",
38
+ "playground": "npx http-server playground",
39
+ "prerelease": "scripts/prerelease",
40
+ "prettier": "scripts/prettier",
41
+ "prettier2": "cross-env PRETTIER_MAJOR=2 scripts/prettier",
42
+ "prettier3": "cross-env PRETTIER_MAJOR=3 scripts/prettier",
43
+ "test": "vitest -c \"./vitest.config.mjs\"",
44
+ "test:3": "cross-env PRETTIER_MAJOR=3 yarn test",
45
+ "test:idempotence": "cross-env TEST_IDEMPOTENCE=true vitest run 'src/test/'",
46
+ "test:idempotence:3": "cross-env PRETTIER_MAJOR=3 yarn test:idempotence",
47
+ "type-check": "tsc --noEmit"
48
+ },
49
+ "peerDependencies": {
50
+ "prettier": "^2.0.0 || ^3.0.0"
51
+ },
52
+ "devDependencies": {
53
+ "@types/prettier": "^2.4.2",
54
+ "cross-env": "^7.0.3",
55
+ "module-alias": "^2.2.3",
56
+ "prettier2": "npm:prettier@^2.6.1",
57
+ "prettier3": "npm:prettier@^3.0.0",
58
+ "source-map-support": "^0.5.21",
59
+ "tsconfig-paths": "^3.14.1"
60
+ },
61
+ "dependencies": {
62
+ "@platformos/liquid-html-parser": "^0.0.2",
63
+ "html-styles": "^1.0.0"
64
+ }
65
+ }