@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
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ <h1 align="center" style="position: relative;" >
2
+ <br>
3
+ <img src="https://github.com/Platform-OS/platformos-tools/blob/main/packages/vscode-extension/images/platformos_logo.png?raw=true" alt="platformOS logo" width="200">
4
+ <br>
5
+ platformOS Liquid Prettier Plugin
6
+ </h1>
7
+
8
+ <p align="center">
9
+ <a href="https://www.npmjs.com/package/@platformos/prettier-plugin-liquid"><img src="https://img.shields.io/npm/v/@platformos/prettier-plugin-liquid.svg?sanitize=true" alt="Version"></a>
10
+ <a href="https://github.com/Platform-OS/platformos-tools/blob/main/LICENSE.md"><img src="https://img.shields.io/npm/l/@platformos/prettier-plugin-liquid.svg?sanitize=true" alt="License"></a>
11
+ <a href="https://github.com/Platform-OS/platformos-tools/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/Platform-OS/platformos-tools/actions/workflows/ci.yml/badge.svg"></a>
12
+ <!--
13
+ <a href="https://npmcharts.com/compare/@platformos/prettier-plugin-liquid?minimal=true"><img src="https://img.shields.io/npm/dm/@platformos/prettier-plugin-liquid.svg?sanitize=true" alt="Downloads"></a>
14
+ -->
15
+ </p>
16
+
17
+ <div align="center">
18
+
19
+ 💬 [Discussions](https://github.com/Platform-OS/platformos-tools/discussions) | 📝 [Changelog](./CHANGELOG.md)
20
+
21
+ </div>
22
+
23
+ [Prettier](https://prettier.io) is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.
24
+
25
+ ![demo](https://github.com/Platform-OS/platformos-tools/blob/main/docs/demo.gif?raw=true)
26
+
27
+ ## Can this be used in production?
28
+
29
+ Yes!
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ # with npm
35
+ npm install --save-dev prettier @platformos/prettier-plugin-liquid
36
+
37
+ # with yarn
38
+ yarn add --dev prettier @platformos/prettier-plugin-liquid
39
+ ```
40
+
41
+ For Prettier version 3 and above, the plugin must also be declared in the [configuration](https://prettier.io/docs/en/configuration.html).
42
+
43
+ ```
44
+ {
45
+ "plugins": ["@platformos/prettier-plugin-liquid"]
46
+ }
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ See our [Wiki](https://github.com/Platform-OS/platformos-tools/wiki) pages on the subject:
52
+
53
+ - [In the terminal](https://github.com/Platform-OS/platformos-tools/wiki/Use-it-in-your-terminal) (with Node.js)
54
+ - [In the browser](https://github.com/Platform-OS/platformos-tools/wiki/Use-it-in-the-browser)
55
+ - [In your editor](https://github.com/Platform-OS/platformos-tools/wiki/Use-it-in-your-editor)
56
+ - [In a CI workflow](https://github.com/Platform-OS/platformos-tools/wiki/Use-it-in-CI)
57
+ - [As a pre-commit hook](https://github.com/Platform-OS/platformos-tools/wiki/Use-it-as-a-pre-commit-hook)
58
+ - [With a bundler](https://github.com/Platform-OS/platformos-tools/wiki/Use-it-with-a-bundler)
59
+
60
+ ## Playground
61
+
62
+ You can try it out in your browser in the [playground](https://shopify.github.io/prettier-plugin-liquid/).
63
+
64
+ ## Configuration
65
+
66
+ Prettier for Liquid supports the following options.
67
+
68
+ | Name | Default | Description |
69
+ | ------------------------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
70
+ | `printWidth` | `120` | Changed from Prettier's default (`80`) ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)) |
71
+ | `tabWidth` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)) |
72
+ | `useTabs` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tabs)) |
73
+ | `singleQuote` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#quotes)) |
74
+ | `bracketSameLine` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#bracket-line)) |
75
+ | `liquidSingleQuote` | `true` | Use single quotes instead of double quotes in Liquid tag and objects (since v0.2.0). |
76
+ | `embeddedSingleQuote` | `true` | Use single quotes instead of double quotes in embedded languages (JavaScript, CSS, TypeScript inside `<script>`, `<style>` or Liquid equivalent) (since v0.4.0). |
77
+ | `htmlWhitespaceSensitivity` | `css` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#html-whitespace-sensitivity)) |
78
+ | `captureWhitespaceSensitivity` | `strict` | Specify the default whitespace sensitivity of the `capture` Liquid tag. Valid options: `"strict"` \| `"ignore"`. |
79
+ | `singleLineLinkTags` | `false` | If set to `true`, will print `<link>` tags on a single line to remove clutter |
80
+ | `indentSchema` | `false` | If set to `true`, will indent the contents of the `{% schema %}` tag |
81
+
82
+ ## Ignoring code
83
+
84
+ We support the following comments (either via HTML or Liquid comments):
85
+
86
+ - `prettier-ignore`
87
+ - `prettier-ignore-attribute`
88
+ - `prettier-ignore-attributes` (alias)
89
+
90
+ They target the next node in the tree. Unparseable code can't be ignored and will throw an error.
91
+
92
+ ```liquid
93
+ {% # prettier-ignore %}
94
+ <div class="x" >hello world</div >
95
+
96
+ {% # prettier-ignore-attributes %}
97
+ <div
98
+ [[#if Condition]]
99
+ class="a b c"
100
+ [[/if ]]
101
+ ></div>
102
+ ```
103
+
104
+ ## Whitespace handling
105
+
106
+ You'll quickly notice that the default value for `--htmlWhitespaceSensitivity` is set to `css` (like [Prettier's](https://prettier.io/blog/2018/11/07/1.15.0#whitespace-sensitive-formatting)).
107
+
108
+ If you want to change this behaviour for a specific tag that has a different default, you can use either the `display` or `white-space` comment to alter the behaviour.
109
+
110
+ Examples:
111
+
112
+ ```liquid
113
+ {% # this tag is whitespace sensitive by default, since the value of the string shouldn't change by formatting. %}
114
+ {% capture value %}
115
+ Hello {% name %}
116
+ {% endcapture %}
117
+
118
+ {% # here we alter its white-space property so that we allow pretty printing of its body %}
119
+ {% # white-space: normal %}
120
+ {% capture _ %}
121
+ <div>
122
+ {% render 'snip' %}
123
+ </div>
124
+ {% endcapture %}
125
+
126
+ {% # this will prevent prettier from formatting it %}
127
+ {% # white-space: pre %}
128
+ {% capture _ %}
129
+ <div>
130
+ {% render 'snip' %}
131
+ </div>
132
+ {% endcapture %}
133
+
134
+ {% # a span is normally sensitive to whitespace on both ends %}
135
+ <span
136
+ ><b
137
+ >hi</b
138
+ ></span
139
+ >
140
+
141
+ {% # with display: block, it isn't %}
142
+ {% # display: block %}
143
+ <span>
144
+ <b>hi</b>
145
+ </span>
146
+ ```
147
+
148
+ ## Known issues
149
+
150
+ Take a look at our [known issues](./KNOWN_ISSUES.md) and [open issues](https://github.com/Platform-OS/platformos-tools/issues).
151
+
152
+ ## Contributing
153
+
154
+ [Read our contributing guide](CONTRIBUTING.md)
155
+
156
+ ## License
157
+
158
+ MIT.
@@ -0,0 +1,17 @@
1
+ THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
2
+
3
+ The latest prettier plugin for Liquid incorporates third party material from the projects listed below. The original copyright notice and the license under which Shopify received such third party material are set forth below. Shopify reserves all other rights not expressly granted, whether by implication, estoppel or otherwise.
4
+
5
+ 1. prettier (https://github.com/prettier/prettier)
6
+
7
+ %% prettier NOTICES, INFORMATION, AND LICENSE BEGIN HERE
8
+ =========================================
9
+ Copyright © James Long and contributors
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ =========================================
17
+ END OF prettier NOTICES, INFORMATION, AND LICENSE
@@ -0,0 +1,7 @@
1
+ export declare const CSS_DISPLAY_TAGS: Record<string, string>;
2
+ export declare const CSS_DISPLAY_LIQUID_TAGS: Record<string, string>;
3
+ export declare const CSS_DISPLAY_LIQUID_DEFAULT = "inline";
4
+ export declare const CSS_DISPLAY_DEFAULT = "inline";
5
+ export declare const CSS_WHITE_SPACE_TAGS: Record<string, string>;
6
+ export declare const CSS_WHITE_SPACE_DEFAULT = "normal";
7
+ export declare const CSS_WHITE_SPACE_LIQUID_TAGS: Record<string, string>;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CSS_WHITE_SPACE_LIQUID_TAGS = exports.CSS_WHITE_SPACE_DEFAULT = exports.CSS_WHITE_SPACE_TAGS = exports.CSS_DISPLAY_DEFAULT = exports.CSS_DISPLAY_LIQUID_DEFAULT = exports.CSS_DISPLAY_LIQUID_TAGS = exports.CSS_DISPLAY_TAGS = void 0;
4
+ // This code is adapted from prettier/src/language-html/constants.evaluate.js
5
+ const htmlStyles = require('html-styles');
6
+ const getCssStyleTags = (property) => Object.fromEntries(htmlStyles
7
+ .filter((htmlStyle) => htmlStyle.style[property])
8
+ .flatMap((htmlStyle) => htmlStyle.selectorText
9
+ .split(',')
10
+ .map((selector) => selector.trim())
11
+ .filter((selector) => /^[\dA-Za-z]+$/.test(selector))
12
+ .map((tagName) => [tagName, htmlStyle.style[property]])));
13
+ exports.CSS_DISPLAY_TAGS = {
14
+ ...getCssStyleTags('display'),
15
+ // TODO: send PR to upstream
16
+ button: 'inline-block',
17
+ // special cases for some css display=none elements
18
+ template: 'inline',
19
+ source: 'block',
20
+ track: 'block',
21
+ script: 'block',
22
+ param: 'block',
23
+ // `noscript` is inline
24
+ // noscript: "inline",
25
+ // there's no css display for these elements but they behave these ways
26
+ details: 'block',
27
+ summary: 'block',
28
+ dialog: 'block',
29
+ meter: 'inline-block',
30
+ progress: 'inline-block',
31
+ object: 'inline-block',
32
+ video: 'inline-block',
33
+ audio: 'inline-block',
34
+ select: 'inline-block',
35
+ option: 'block',
36
+ optgroup: 'block',
37
+ };
38
+ exports.CSS_DISPLAY_LIQUID_TAGS = {
39
+ // control flow tags
40
+ if: 'inline',
41
+ unless: 'inline',
42
+ else: 'inline',
43
+ elsif: 'inline',
44
+ case: 'inline',
45
+ when: 'inline',
46
+ // iteration tags,
47
+ for: 'inline',
48
+ cycle: 'inline',
49
+ tablerow: 'block',
50
+ break: 'none',
51
+ continue: 'none',
52
+ // theme tags
53
+ comment: 'none',
54
+ echo: 'inline',
55
+ form: 'block',
56
+ layout: 'none',
57
+ liquid: 'inline',
58
+ paginate: 'inline',
59
+ raw: 'inline',
60
+ render: 'inline',
61
+ include: 'inline',
62
+ section: 'block',
63
+ style: 'none',
64
+ // variable tags
65
+ assign: 'none',
66
+ capture: 'inline',
67
+ increment: 'inline',
68
+ decrement: 'inline',
69
+ };
70
+ exports.CSS_DISPLAY_LIQUID_DEFAULT = 'inline';
71
+ exports.CSS_DISPLAY_DEFAULT = 'inline';
72
+ exports.CSS_WHITE_SPACE_TAGS = getCssStyleTags('white-space');
73
+ exports.CSS_WHITE_SPACE_DEFAULT = 'normal';
74
+ exports.CSS_WHITE_SPACE_LIQUID_TAGS = {
75
+ capture: 'pre',
76
+ raw: 'pre',
77
+ };
78
+ //# sourceMappingURL=constants.evaluate.js.map
@@ -0,0 +1,2 @@
1
+ import plugin from './plugin';
2
+ export = plugin;
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const plugin_1 = __importDefault(require("./plugin"));
6
+ module.exports = plugin_1.default;
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,19 @@
1
+ import { LiquidHtmlNode } from '@platformos/liquid-html-parser';
2
+ import { locEnd, locStart } from './utils';
3
+ export declare function parse(text: string): LiquidHtmlNode;
4
+ export declare const liquidHtmlAstFormat = "liquid-html-ast";
5
+ export declare const liquidHtmlLanguageName = "liquid-html";
6
+ export declare const liquidHtmlParser: {
7
+ parse: typeof parse;
8
+ astFormat: string;
9
+ locStart: typeof locStart;
10
+ locEnd: typeof locEnd;
11
+ };
12
+ export declare const parsers: {
13
+ "liquid-html": {
14
+ parse: typeof parse;
15
+ astFormat: string;
16
+ locStart: typeof locStart;
17
+ locEnd: typeof locEnd;
18
+ };
19
+ };
package/dist/parser.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parsers = exports.liquidHtmlParser = exports.liquidHtmlLanguageName = exports.liquidHtmlAstFormat = void 0;
4
+ exports.parse = parse;
5
+ const liquid_html_parser_1 = require("@platformos/liquid-html-parser");
6
+ const utils_1 = require("./utils");
7
+ function parse(text) {
8
+ return (0, liquid_html_parser_1.toLiquidHtmlAST)(text);
9
+ }
10
+ exports.liquidHtmlAstFormat = 'liquid-html-ast';
11
+ exports.liquidHtmlLanguageName = 'liquid-html';
12
+ exports.liquidHtmlParser = {
13
+ parse,
14
+ astFormat: exports.liquidHtmlAstFormat,
15
+ locStart: utils_1.locStart,
16
+ locEnd: utils_1.locEnd,
17
+ };
18
+ exports.parsers = {
19
+ [exports.liquidHtmlLanguageName]: exports.liquidHtmlParser,
20
+ };
21
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1,7 @@
1
+ import type { Plugin as Plugin2 } from 'prettier';
2
+ import type { Plugin as Plugin3 } from 'prettier3';
3
+ import { LiquidHtmlNode } from './types';
4
+ export declare const plugin2: Plugin2<LiquidHtmlNode>;
5
+ export declare const plugin3: Plugin3<LiquidHtmlNode>;
6
+ declare const _default: Plugin2<LiquidHtmlNode> | Plugin3<LiquidHtmlNode>;
7
+ export default _default;
package/dist/plugin.js ADDED
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.plugin3 = exports.plugin2 = void 0;
4
+ const prettier_1 = require("prettier");
5
+ const parser_1 = require("./parser");
6
+ const printer_1 = require("./printer");
7
+ const languages = [
8
+ {
9
+ name: 'LiquidHTML',
10
+ parsers: [parser_1.liquidHtmlLanguageName],
11
+ extensions: ['.liquid'],
12
+ vscodeLanguageIds: ['liquid', 'Liquid'],
13
+ },
14
+ ];
15
+ const options = {
16
+ captureWhitespaceSensitivity: {
17
+ type: 'choice',
18
+ description: 'Specify the global whitespace sensitivity for the capture Liquid tag.',
19
+ choices: [
20
+ {
21
+ value: 'strict',
22
+ description: 'Whitespace inside {% capture var %} tags is considered significant.',
23
+ },
24
+ {
25
+ value: 'ignore',
26
+ description: 'Whitespace inside {% capture var %} tags is considered insignificant.',
27
+ },
28
+ ],
29
+ category: 'LIQUID',
30
+ default: 'strict',
31
+ since: '1.5.0',
32
+ },
33
+ liquidSingleQuote: {
34
+ type: 'boolean',
35
+ category: 'LIQUID',
36
+ default: true,
37
+ description: 'Use single quotes instead of double quotes in Liquid tags and objects.',
38
+ since: '0.2.0',
39
+ },
40
+ embeddedSingleQuote: {
41
+ type: 'boolean',
42
+ category: 'LIQUID',
43
+ default: true,
44
+ description: 'Use single quotes instead of double quotes in embedded languages (JavaScript, CSS, TypeScript inside <script>, <style> or Liquid equivalent).',
45
+ since: '0.4.0',
46
+ },
47
+ singleLineLinkTags: {
48
+ type: 'boolean',
49
+ category: 'HTML',
50
+ default: false,
51
+ description: 'Always print link tags on a single line to remove clutter',
52
+ since: '0.1.0',
53
+ },
54
+ indentSchema: {
55
+ type: 'boolean',
56
+ category: 'LIQUID',
57
+ default: false,
58
+ description: 'Indent the contents of the {% schema %} tag',
59
+ since: '0.1.0',
60
+ },
61
+ liquidDocParamDash: {
62
+ type: 'boolean',
63
+ category: 'LIQUID',
64
+ default: true,
65
+ description: 'Append a dash (-) to separate descriptions in {% doc %} @param annotations',
66
+ since: '1.6.4',
67
+ },
68
+ };
69
+ const defaultOptions = {
70
+ printWidth: 120,
71
+ };
72
+ exports.plugin2 = {
73
+ languages,
74
+ parsers: parser_1.parsers,
75
+ printers: printer_1.printers2,
76
+ options,
77
+ defaultOptions,
78
+ };
79
+ exports.plugin3 = {
80
+ languages,
81
+ parsers: parser_1.parsers,
82
+ printers: printer_1.printers3,
83
+ options,
84
+ defaultOptions,
85
+ };
86
+ const prettierMajor = prettier_1.version.split('.')[0];
87
+ exports.default = prettierMajor === '2' ? exports.plugin2 : exports.plugin3;
88
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1,9 @@
1
+ import type { Printer as Printer2 } from 'prettier';
2
+ import type { Printer as Printer3 } from 'prettier3';
3
+ import { RawMarkupKinds } from '@platformos/liquid-html-parser';
4
+ import { LiquidHtmlNode } from '../types';
5
+ export declare const ParserMap: {
6
+ [key in RawMarkupKinds]: string | null;
7
+ };
8
+ export declare const embed2: Printer2<LiquidHtmlNode>['embed'];
9
+ export declare const embed3: Printer3<LiquidHtmlNode>['embed'];
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.embed3 = exports.embed2 = exports.ParserMap = void 0;
4
+ const prettier_1 = require("prettier");
5
+ const liquid_html_parser_1 = require("@platformos/liquid-html-parser");
6
+ const { builders: { dedentToRoot, indent, hardline }, } = prettier_1.doc;
7
+ // null will pass through
8
+ exports.ParserMap = {
9
+ [liquid_html_parser_1.RawMarkupKinds.css]: 'css',
10
+ [liquid_html_parser_1.RawMarkupKinds.html]: null,
11
+ [liquid_html_parser_1.RawMarkupKinds.javascript]: 'babel',
12
+ [liquid_html_parser_1.RawMarkupKinds.json]: 'json',
13
+ [liquid_html_parser_1.RawMarkupKinds.markdown]: 'markdown',
14
+ [liquid_html_parser_1.RawMarkupKinds.typescript]: 'typescript',
15
+ [liquid_html_parser_1.RawMarkupKinds.text]: null,
16
+ };
17
+ // Prettier 2 and 3 have a slightly different API for embed.
18
+ //
19
+ // https://github.com/prettier/prettier/wiki/How-to-migrate-my-plugin-to-support-Prettier-v3%3F
20
+ const embed2 = (path, _print, textToDoc, options) => {
21
+ const node = path.getValue();
22
+ switch (node.type) {
23
+ case liquid_html_parser_1.NodeTypes.RawMarkup: {
24
+ const parser = exports.ParserMap[node.kind];
25
+ if (parser && node.value.trim() !== '') {
26
+ const body = prettier_1.doc.utils.stripTrailingHardline(textToDoc(node.value, {
27
+ ...options,
28
+ singleQuote: options.embeddedSingleQuote,
29
+ parser,
30
+ __embeddedInHtml: true,
31
+ }));
32
+ if (shouldIndentBody(node, options)) {
33
+ return [indent([hardline, body]), hardline];
34
+ }
35
+ else {
36
+ return [dedentToRoot([hardline, body]), hardline];
37
+ }
38
+ }
39
+ }
40
+ default:
41
+ return null;
42
+ }
43
+ };
44
+ exports.embed2 = embed2;
45
+ const embed3 = (path, options) => {
46
+ return (textToDoc) => {
47
+ const node = path.node;
48
+ switch (node.type) {
49
+ case liquid_html_parser_1.NodeTypes.RawMarkup: {
50
+ const parser = exports.ParserMap[node.kind];
51
+ if (parser && node.value.trim() !== '') {
52
+ return textToDoc(node.value, {
53
+ ...options,
54
+ singleQuote: options.embeddedSingleQuote,
55
+ parser,
56
+ __embeddedInHtml: true,
57
+ }).then((document) => {
58
+ const body = prettier_1.doc.utils.stripTrailingHardline(document);
59
+ if (shouldIndentBody(node, options)) {
60
+ return [indent([hardline, body]), hardline];
61
+ }
62
+ else {
63
+ return [dedentToRoot([hardline, body]), hardline];
64
+ }
65
+ });
66
+ }
67
+ }
68
+ default:
69
+ return undefined;
70
+ }
71
+ };
72
+ };
73
+ exports.embed3 = embed3;
74
+ function shouldIndentBody(node, options) {
75
+ const parentNode = node.parentNode;
76
+ const shouldNotIndentBody = parentNode &&
77
+ parentNode.type === liquid_html_parser_1.NodeTypes.LiquidRawTag &&
78
+ parentNode.name === 'schema' &&
79
+ !options.indentSchema;
80
+ return node.kind !== liquid_html_parser_1.RawMarkupKinds.markdown && !shouldNotIndentBody;
81
+ }
82
+ //# sourceMappingURL=embed.js.map
@@ -0,0 +1,14 @@
1
+ export declare const printers2: {
2
+ "liquid-html-ast": import("prettier").Printer<import("../types").LiquidHtmlNode> & {
3
+ preprocess: any;
4
+ } & {
5
+ getVisitorKeys: any;
6
+ };
7
+ };
8
+ export declare const printers3: {
9
+ "liquid-html-ast": import("prettier3").Printer<import("../types").LiquidHtmlNode> & {
10
+ preprocess: any;
11
+ } & {
12
+ getVisitorKeys: any;
13
+ };
14
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printers3 = exports.printers2 = void 0;
4
+ const printer_liquid_html_1 = require("./printer-liquid-html");
5
+ const parser_1 = require("../parser");
6
+ exports.printers2 = {
7
+ [parser_1.liquidHtmlAstFormat]: printer_liquid_html_1.printerLiquidHtml2,
8
+ };
9
+ exports.printers3 = {
10
+ [parser_1.liquidHtmlAstFormat]: printer_liquid_html_1.printerLiquidHtml3,
11
+ };
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ import { Augment, WithSiblings } from '../../types';
2
+ export declare const augmentWithCSSProperties: Augment<WithSiblings>;