oxfmt 0.50.0 → 0.52.0
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/dist/{acorn-sBRpswSh.js → acorn-C-l7ouWN.js} +1 -1
- package/dist/{angular-DtI-eDW8.js → angular-4Mc0TmPv.js} +3 -5
- package/dist/{apis-CKvPKBJI.js → apis-Cc9jzUH4.js} +7 -53
- package/dist/{babel-DaNjvh9L.js → babel-DjR61Wf3.js} +2 -3
- package/dist/{bindings-Dj_YoR0Z.js → bindings-BJw0GhQr.js} +26 -26
- package/dist/chunk-CNf5ZN-e.js +37 -0
- package/dist/cli-worker.js +1 -1
- package/dist/cli.js +79 -41
- package/dist/{dist-D_YbN99t.js → dist-CJyFMFm2.js} +70 -50
- package/dist/{estree-CzfNsl8m.js → estree-DHQPBKqf.js} +1 -1
- package/dist/{flow-c9AjoQam.js → flow-Cz3mJAtC.js} +1 -1
- package/dist/{glimmer-D_zkI0w_.js → glimmer-ubhL-0tG.js} +1 -1
- package/dist/{graphql-BFXkB4Nq.js → graphql-Cl0TIiHU.js} +1 -1
- package/dist/{html-DkcPxRXg.js → html-Cqnv8X__.js} +1 -1
- package/dist/index.js +4 -4
- package/dist/{init-C3nxU_Wc.js → init-DGfXRYLw.js} +1 -1
- package/dist/{jiti-Bb1dT6Cw-C0N20Za1.js → jiti-Bb1dT6Cw-B_5IaZk7.js} +2 -2
- package/dist/{markdown-DVLNmbQg.js → markdown-Eujfu-fQ.js} +1 -1
- package/dist/{meriyah-BGPf00Rn.js → meriyah-DESRG6oe.js} +1 -1
- package/dist/{migrate-biome-DclTzwKW.js → migrate-biome-P928W9-y.js} +1 -1
- package/dist/{migrate-prettier-DLfviW85.js → migrate-prettier-CotsZUFl.js} +2 -2
- package/dist/{plugin-DOdiccQR.js → plugin-C4twtOn4.js} +433 -374
- package/dist/{postcss-D-ql-dm8.js → postcss-BFLfznNY.js} +1 -1
- package/dist/{prettier-Cw36juP9.js → prettier-Cy-lZk4k.js} +15 -15
- package/dist/{sorter-BZkvDMjt-DpGe0QK9.js → sorter-BZkvDMjt-C3eOnP5z.js} +7 -7
- package/dist/{sorter-w0dgpoFw.js → sorter-CHFUGfz-.js} +1 -1
- package/dist/{typescript-C_eN_ThF.js → typescript-lqJOqGcK.js} +1 -1
- package/dist/{v3-D-mr2VVh-CU7hQIit.js → v3-D-mr2VVh-BXhnMySQ.js} +3 -3
- package/dist/{v4-C-HWEQJm-C8EWwksG.js → v4-C-HWEQJm-CvgekpKf.js} +3 -3
- package/dist/{yaml-Bqxyk-13.js → yaml-D3PpfZBy.js} +1 -1
- package/package.json +25 -21
- /package/dist/{prettier-plugin-oxfmt-BlJcmKAv.js → prettier-plugin-oxfmt-Dj6FaAil.js} +0 -0
- /package/dist/{shared-BtJbjkue.js → shared-BiMl-bLP.js} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as init_babel, t as babel_exports } from "./babel-
|
|
3
|
-
import { n as prettier_exports, t as init_prettier } from "./prettier-
|
|
4
|
-
//#region ../../node_modules/.pnpm/prettier-plugin-svelte@
|
|
1
|
+
import { a as __toCommonJS, i as __require, t as __commonJSMin } from "./chunk-CNf5ZN-e.js";
|
|
2
|
+
import { n as init_babel, t as babel_exports } from "./babel-DjR61Wf3.js";
|
|
3
|
+
import { n as prettier_exports, t as init_prettier } from "./prettier-Cy-lZk4k.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/prettier-plugin-svelte@4.0.1_prettier@3.8.3_svelte@5.55.9_@typescript-eslint+types@8.59.4_/node_modules/prettier-plugin-svelte/plugin.js
|
|
5
5
|
var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
var prettierPluginBabel = (init_babel(), __toCommonJS(babel_exports));
|
|
@@ -193,7 +193,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
193
193
|
category: "Svelte",
|
|
194
194
|
type: "string",
|
|
195
195
|
default: "",
|
|
196
|
-
description: "
|
|
196
|
+
description: "Path to the Svelte compiler. You normally don't need to set this."
|
|
197
197
|
},
|
|
198
198
|
svelteSortOrder: {
|
|
199
199
|
category: "Svelte",
|
|
@@ -228,18 +228,6 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
228
228
|
makeChoice("none")
|
|
229
229
|
]
|
|
230
230
|
},
|
|
231
|
-
svelteStrictMode: {
|
|
232
|
-
category: "Svelte",
|
|
233
|
-
type: "boolean",
|
|
234
|
-
default: false,
|
|
235
|
-
description: "More strict HTML syntax: Quotes in attributes, no self-closing DOM tags"
|
|
236
|
-
},
|
|
237
|
-
svelteBracketNewLine: {
|
|
238
|
-
category: "Svelte",
|
|
239
|
-
type: "boolean",
|
|
240
|
-
description: "Put the `>` of a multiline element on a new line",
|
|
241
|
-
deprecated: "2.5.0"
|
|
242
|
-
},
|
|
243
231
|
svelteAllowShorthand: {
|
|
244
232
|
category: "Svelte",
|
|
245
233
|
type: "boolean",
|
|
@@ -261,7 +249,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
261
249
|
return order;
|
|
262
250
|
}
|
|
263
251
|
function isBracketSameLine(options) {
|
|
264
|
-
return options.
|
|
252
|
+
return options.bracketSameLine != null ? options.bracketSameLine : false;
|
|
265
253
|
}
|
|
266
254
|
/**
|
|
267
255
|
* Determines whether or not given node
|
|
@@ -271,7 +259,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
271
259
|
return n && n.__isRoot;
|
|
272
260
|
}
|
|
273
261
|
function isPreTagContent(path) {
|
|
274
|
-
return path.stack.some((node) => node.type === "
|
|
262
|
+
return path.stack.some((node) => node.type === "RegularElement" && node.name.toLowerCase() === "pre" || node.type === "Attribute" && !formattableAttributes.includes(node.name));
|
|
275
263
|
}
|
|
276
264
|
function flatten(arrays) {
|
|
277
265
|
return [].concat.apply([], arrays);
|
|
@@ -291,7 +279,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
291
279
|
}
|
|
292
280
|
function getAttributeLine(node, options) {
|
|
293
281
|
const { hardline, line } = prettier.doc.builders;
|
|
294
|
-
const hasThisBinding = node.type === "
|
|
282
|
+
const hasThisBinding = (node.type === "Component" || node.type === "SvelteComponent") && !!node.expression || node.type === "SvelteElement" && !!node.tag;
|
|
295
283
|
const attributes = node.attributes.filter((attribute) => attribute.name !== snippedTagContentAttribute);
|
|
296
284
|
return options.singleAttributePerLine && (attributes.length > 1 || attributes.length && hasThisBinding) ? hardline : line;
|
|
297
285
|
}
|
|
@@ -436,43 +424,31 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
436
424
|
return ONLY_HTML_COLLAPSE_WHITESPACE_RE.test(text);
|
|
437
425
|
}
|
|
438
426
|
function isInlineElement(path, options, node) {
|
|
439
|
-
return node && node.type === "
|
|
427
|
+
return node && node.type === "RegularElement" && !isBlockElement(node, options) && !isPreTagContent(path);
|
|
440
428
|
}
|
|
441
429
|
function isBlockElement(node, options) {
|
|
442
|
-
return node && node.type === "
|
|
443
|
-
}
|
|
444
|
-
function isSvelteBlock(node) {
|
|
445
|
-
return [
|
|
446
|
-
"IfBlock",
|
|
447
|
-
"SnippetBlock",
|
|
448
|
-
"AwaitBlock",
|
|
449
|
-
"CatchBlock",
|
|
450
|
-
"EachBlock",
|
|
451
|
-
"ElseBlock",
|
|
452
|
-
"KeyBlock",
|
|
453
|
-
"PendingBlock",
|
|
454
|
-
"ThenBlock"
|
|
455
|
-
].includes(node.type);
|
|
430
|
+
return node && node.type === "RegularElement" && options.htmlWhitespaceSensitivity !== "strict" && (options.htmlWhitespaceSensitivity === "ignore" || blockElements.includes(node.name));
|
|
456
431
|
}
|
|
457
432
|
function isNodeWithChildren(node) {
|
|
458
|
-
return node
|
|
433
|
+
return !!getMaybeChildren(node);
|
|
459
434
|
}
|
|
460
|
-
function
|
|
461
|
-
|
|
435
|
+
function getMaybeChildren(_node) {
|
|
436
|
+
if (_node.type === "Fragment") return _node.nodes;
|
|
437
|
+
for (const key of Object.keys(_node)) {
|
|
438
|
+
const value = _node[key];
|
|
439
|
+
if (typeof value === "object" && value != null && value.type === "Fragment") return value.nodes;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function getChildren(_node) {
|
|
443
|
+
return getMaybeChildren(_node) || [];
|
|
462
444
|
}
|
|
463
445
|
/**
|
|
464
446
|
* Returns siblings, that is, the children of the parent.
|
|
465
447
|
*/
|
|
466
448
|
function getSiblings(path) {
|
|
467
449
|
let parent = path.getParentNode();
|
|
468
|
-
if (isASTNode(parent)) parent = parent.
|
|
469
|
-
return
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Returns the next sibling node.
|
|
473
|
-
*/
|
|
474
|
-
function getNextNode(path, node = path.getNode()) {
|
|
475
|
-
return getSiblings(path).find((child) => child.start === node.end);
|
|
450
|
+
if (isASTNode(parent)) parent = parent.fragment;
|
|
451
|
+
return parent.nodes;
|
|
476
452
|
}
|
|
477
453
|
/**
|
|
478
454
|
* Returns the comment that is above the current node.
|
|
@@ -487,27 +463,9 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
487
463
|
prev = siblings.find((child) => child.end === node.start);
|
|
488
464
|
} else return;
|
|
489
465
|
}
|
|
490
|
-
/**
|
|
491
|
-
* Did there use to be any embedded object (that has been snipped out of the AST to be moved)
|
|
492
|
-
* at the specified position?
|
|
493
|
-
*/
|
|
494
|
-
function doesEmbedStartAfterNode(node, path, siblings = getSiblings(path)) {
|
|
495
|
-
if (!isNodeTopLevelHTML(node, path)) return false;
|
|
496
|
-
const position = node.end;
|
|
497
|
-
const root = path.stack[0];
|
|
498
|
-
const embeds = [
|
|
499
|
-
root.css,
|
|
500
|
-
root.html,
|
|
501
|
-
root.instance,
|
|
502
|
-
root.js,
|
|
503
|
-
root.module
|
|
504
|
-
];
|
|
505
|
-
const nextNode = siblings[siblings.indexOf(node) + 1];
|
|
506
|
-
return embeds.find((n) => n && n.start >= position && (!nextNode || n.end <= nextNode.start));
|
|
507
|
-
}
|
|
508
466
|
function isNodeTopLevelHTML(node, path) {
|
|
509
467
|
const root = path.stack[0];
|
|
510
|
-
return !!root.
|
|
468
|
+
return !!root.fragment && !!root.fragment.nodes && root.fragment.nodes.includes(node);
|
|
511
469
|
}
|
|
512
470
|
function isEmptyTextNode(node) {
|
|
513
471
|
return !!node && node.type === "Text" && isOnlyHtmlCollapseWhitespace(getUnencodedText(node));
|
|
@@ -522,9 +480,10 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
522
480
|
return !!node && node.type === "Comment" && node.data.trim() === "prettier-ignore-end";
|
|
523
481
|
}
|
|
524
482
|
function printRaw(node, originalText, stripLeadingAndTrailingNewline = false) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
const
|
|
483
|
+
const children = getChildren(node);
|
|
484
|
+
if (children.length === 0) return "";
|
|
485
|
+
const firstChild = children[0];
|
|
486
|
+
const lastChild = children[children.length - 1];
|
|
528
487
|
let raw = originalText.substring(firstChild.start, lastChild.end);
|
|
529
488
|
if (!stripLeadingAndTrailingNewline) return raw;
|
|
530
489
|
if (startsWithLinebreak(raw)) raw = raw.substring(raw.indexOf("\n") + 1);
|
|
@@ -545,7 +504,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
545
504
|
function getAttributeTextValue(attributeName, node) {
|
|
546
505
|
const value = getAttributeValue(attributeName, node);
|
|
547
506
|
if (value != null && typeof value === "object") {
|
|
548
|
-
const textValue = value.find(isTextNode);
|
|
507
|
+
const textValue = (Array.isArray(value) ? value : [value]).find(isTextNode);
|
|
549
508
|
if (textValue) return textValue.data;
|
|
550
509
|
}
|
|
551
510
|
return null;
|
|
@@ -587,21 +546,21 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
587
546
|
return ["sass", "scss"].includes(lang);
|
|
588
547
|
}
|
|
589
548
|
function isPugTemplate(node) {
|
|
590
|
-
return node.type === "
|
|
549
|
+
return node.type === "RegularElement" && node.name === "template" && getLangAttribute(node) === "pug";
|
|
591
550
|
}
|
|
592
551
|
function isLoneMustacheTag(node) {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
return node !== true && node.length === 1 && node[0].type === "AttributeShorthand";
|
|
552
|
+
if (node === true || node == null) return false;
|
|
553
|
+
if (Array.isArray(node)) return node.length === 1 && node[0].type === "ExpressionTag";
|
|
554
|
+
return node.type === "ExpressionTag";
|
|
597
555
|
}
|
|
598
556
|
/**
|
|
599
557
|
* True if node is of type `{a}` or `a={a}`
|
|
600
558
|
*/
|
|
601
559
|
function isOrCanBeConvertedToShorthand(node) {
|
|
602
|
-
if (isAttributeShorthand(node.value)) return true;
|
|
603
560
|
if (isLoneMustacheTag(node.value)) {
|
|
604
|
-
const
|
|
561
|
+
const value_node = Array.isArray(node.value) ? node.value[0] : node.value;
|
|
562
|
+
const expression = value_node.type === "ExpressionTag" ? value_node.expression : null;
|
|
563
|
+
if (!expression) return false;
|
|
605
564
|
return expression.type === "Identifier" && expression.name === node.name;
|
|
606
565
|
}
|
|
607
566
|
return false;
|
|
@@ -639,12 +598,10 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
639
598
|
* Remove all leading whitespace up until the first non-empty text node,
|
|
640
599
|
* and all trailing whitespace from the last non-empty text node onwards.
|
|
641
600
|
*/
|
|
642
|
-
function trimChildren(children
|
|
643
|
-
let firstNonEmptyNode = children.findIndex((n) => !isEmptyTextNode(n)
|
|
601
|
+
function trimChildren(children) {
|
|
602
|
+
let firstNonEmptyNode = children.findIndex((n) => !isEmptyTextNode(n));
|
|
644
603
|
firstNonEmptyNode = firstNonEmptyNode === -1 ? children.length - 1 : firstNonEmptyNode;
|
|
645
|
-
let lastNonEmptyNode = findLastIndex((n
|
|
646
|
-
return !isEmptyTextNode(n) && (idx === children.length - 1 && n.type !== "Comment" || !doesEmbedStartAfterNode(n, path));
|
|
647
|
-
}, children);
|
|
604
|
+
let lastNonEmptyNode = findLastIndex((n) => !isEmptyTextNode(n), children);
|
|
648
605
|
lastNonEmptyNode = lastNonEmptyNode === -1 ? 0 : lastNonEmptyNode;
|
|
649
606
|
for (let i = 0; i <= firstNonEmptyNode; i++) {
|
|
650
607
|
const n = children[i];
|
|
@@ -664,7 +621,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
664
621
|
if (node.type === "SvelteBoundary") return false;
|
|
665
622
|
if (isBlockElement(node, options)) return false;
|
|
666
623
|
if (!isNodeWithChildren(node)) return false;
|
|
667
|
-
const children = node
|
|
624
|
+
const children = getChildren(node);
|
|
668
625
|
if (children.length === 0) return true;
|
|
669
626
|
if (options.htmlWhitespaceSensitivity === "ignore") return false;
|
|
670
627
|
const firstChild = children[0];
|
|
@@ -679,7 +636,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
679
636
|
if (node.type === "SvelteBoundary") return false;
|
|
680
637
|
if (isBlockElement(node, options)) return false;
|
|
681
638
|
if (!isNodeWithChildren(node)) return false;
|
|
682
|
-
const children = node
|
|
639
|
+
const children = getChildren(node);
|
|
683
640
|
if (children.length === 0) return true;
|
|
684
641
|
if (options.htmlWhitespaceSensitivity === "ignore") return false;
|
|
685
642
|
const lastChild = children[children.length - 1];
|
|
@@ -689,8 +646,8 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
689
646
|
* Check for a svelte block if there's whitespace at the start and if it's a space or a line.
|
|
690
647
|
*/
|
|
691
648
|
function checkWhitespaceAtStartOfSvelteBlock(node, options) {
|
|
692
|
-
if (!
|
|
693
|
-
const children = node.
|
|
649
|
+
if (!isNodeWithChildren(node)) return "none";
|
|
650
|
+
const children = node.nodes;
|
|
694
651
|
if (children.length === 0) return "none";
|
|
695
652
|
const firstChild = children[0];
|
|
696
653
|
if (isTextNodeStartingWithLinebreak(firstChild)) return "line";
|
|
@@ -706,8 +663,8 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
706
663
|
* Check for a svelte block if there's whitespace at the end and if it's a space or a line.
|
|
707
664
|
*/
|
|
708
665
|
function checkWhitespaceAtEndOfSvelteBlock(node, options) {
|
|
709
|
-
if (!
|
|
710
|
-
const children = node.
|
|
666
|
+
if (!isNodeWithChildren(node)) return "none";
|
|
667
|
+
const children = node.nodes;
|
|
711
668
|
if (children.length === 0) return "none";
|
|
712
669
|
const lastChild = children[children.length - 1];
|
|
713
670
|
if (isTextNodeEndingWithLinebreak(lastChild)) return "line";
|
|
@@ -720,7 +677,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
720
677
|
return "none";
|
|
721
678
|
}
|
|
722
679
|
function isInsideQuotedAttribute(path, options) {
|
|
723
|
-
return path.stack.some((node) => (node.type === "Attribute" || node.type === "StyleDirective") &&
|
|
680
|
+
return path.stack.some((node) => (node.type === "Attribute" || node.type === "StyleDirective") && !isLoneMustacheTag(node.value));
|
|
724
681
|
}
|
|
725
682
|
/**
|
|
726
683
|
* Returns true if the softline between `</tagName` and `>` can be omitted.
|
|
@@ -737,9 +694,10 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
737
694
|
return !STARTS_WITH_HTML_COLLAPSE_WHITESPACE_RE.test(options.originalText.substring(node.end));
|
|
738
695
|
}
|
|
739
696
|
function isLastChildWithinParentBlockElement(path, options) {
|
|
740
|
-
const
|
|
741
|
-
|
|
742
|
-
|
|
697
|
+
const fragment = path.getParentNode();
|
|
698
|
+
const parent = path.getParentNode(1);
|
|
699
|
+
if (!fragment || !parent || !isBlockElement(parent, options)) return false;
|
|
700
|
+
const children = fragment.nodes.filter((child) => !isEmptyTextNode(child));
|
|
743
701
|
return children[children.length - 1] === path.getNode();
|
|
744
702
|
}
|
|
745
703
|
function assignCommentsToNodes(ast) {
|
|
@@ -751,7 +709,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
751
709
|
* Returns the comments that are above the current node and deletes them from the html ast.
|
|
752
710
|
*/
|
|
753
711
|
function removeAndGetLeadingComments(ast, current) {
|
|
754
|
-
const siblings =
|
|
712
|
+
const siblings = ast.fragment.nodes;
|
|
755
713
|
const comments = [];
|
|
756
714
|
const newlines = [];
|
|
757
715
|
if (!siblings.length) return [];
|
|
@@ -786,14 +744,13 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
786
744
|
}
|
|
787
745
|
let ignoreNext = false;
|
|
788
746
|
let ignoreRange = false;
|
|
789
|
-
let svelteOptionsDoc;
|
|
790
747
|
function print(path, options, print) {
|
|
791
|
-
var _a, _b;
|
|
748
|
+
var _a, _b, _c, _d, _e, _f;
|
|
792
749
|
const bracketSameLine = isBracketSameLine(options);
|
|
793
|
-
const n = path.
|
|
750
|
+
const n = path.node;
|
|
794
751
|
if (!n) return "";
|
|
795
752
|
if (isASTNode(n)) return printTopLevelParts(n, options, path, print);
|
|
796
|
-
const [open, close] =
|
|
753
|
+
const [open, close] = ["{", "}"];
|
|
797
754
|
const printJsExpression = () => [
|
|
798
755
|
open,
|
|
799
756
|
printJS(path, print, "expression"),
|
|
@@ -806,24 +763,16 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
806
763
|
}
|
|
807
764
|
switch (node.type) {
|
|
808
765
|
case "Fragment":
|
|
809
|
-
const children = node.
|
|
766
|
+
const children = node.nodes;
|
|
810
767
|
if (children.length === 0 || children.every(isEmptyTextNode)) return "";
|
|
811
768
|
if (!isPreTagContent(path)) {
|
|
812
|
-
trimChildren(
|
|
769
|
+
trimChildren(children);
|
|
813
770
|
const output = trim([printChildren(path, print, options)], (n) => isLine(n) || typeof n === "string" && isOnlyHtmlCollapseWhitespace(n) || n === breakParent);
|
|
814
771
|
if (output.every((doc) => isEmptyDoc(doc))) return "";
|
|
815
772
|
return group([...output, hardline]);
|
|
816
|
-
} else return group(path.map(print, "
|
|
773
|
+
} else return group(path.map(print, "nodes"));
|
|
817
774
|
case "Text": if (!isPreTagContent(path)) {
|
|
818
|
-
if (isEmptyTextNode(node))
|
|
819
|
-
const text = getUnencodedText(node);
|
|
820
|
-
const hasWhiteSpace = text.length > 0;
|
|
821
|
-
const hasOneOrMoreNewlines = /\n/.test(text);
|
|
822
|
-
if (/\n\r?[\t\n\f\r ]*\n\r?/.test(text)) return [hardline, hardline];
|
|
823
|
-
if (hasOneOrMoreNewlines) return hardline;
|
|
824
|
-
if (hasWhiteSpace) return line;
|
|
825
|
-
return "";
|
|
826
|
-
}
|
|
775
|
+
if (isEmptyTextNode(node)) return printWhitespace(getUnencodedText(node));
|
|
827
776
|
/**
|
|
828
777
|
* For non-empty text nodes each sequence of non-whitespace characters (effectively,
|
|
829
778
|
* each "word") is joined by a single `line`, which will be rendered as a single space
|
|
@@ -835,7 +784,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
835
784
|
let rawText = getUnencodedText(node);
|
|
836
785
|
const parent = path.getParentNode();
|
|
837
786
|
if (parent.type === "Attribute") {
|
|
838
|
-
if (parent.name === "class" && path.getParentNode(1).type === "
|
|
787
|
+
if (parent.name === "class" && path.getParentNode(1).type === "RegularElement") {
|
|
839
788
|
rawText = rawText.replace(/([^ \t\n])(([ \t]+$)|([ \t]+(\r?\n))|[ \t]+)/g, (match, characterBeforeWhitespace, _, isEndOfString, isEndOfLine, endOfLine) => isEndOfString ? match : characterBeforeWhitespace + (isEndOfLine ? endOfLine : " "));
|
|
840
789
|
rawText = rawText.replace(/([^ \t\n])[ \t]+$/, parent.value.indexOf(node) === parent.value.length - 1 ? "$1" : "$1 ");
|
|
841
790
|
}
|
|
@@ -843,33 +792,53 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
843
792
|
}
|
|
844
793
|
return rawText;
|
|
845
794
|
}
|
|
846
|
-
case "
|
|
847
|
-
case "
|
|
848
|
-
case "
|
|
849
|
-
case "
|
|
850
|
-
case "
|
|
851
|
-
case "
|
|
795
|
+
case "RegularElement":
|
|
796
|
+
case "Component":
|
|
797
|
+
case "SvelteComponent":
|
|
798
|
+
case "SvelteSelf":
|
|
799
|
+
case "SlotElement":
|
|
800
|
+
case "SvelteFragment":
|
|
801
|
+
case "SvelteWindow":
|
|
802
|
+
case "SvelteHead":
|
|
803
|
+
case "SvelteBody":
|
|
804
|
+
case "SvelteDocument":
|
|
805
|
+
case "SvelteElement":
|
|
852
806
|
case "SvelteBoundary":
|
|
853
|
-
case "
|
|
807
|
+
case "TitleElement": {
|
|
854
808
|
const isSupportedLanguage = !(node.name === "template" && !isNodeSupportedLanguage(node));
|
|
855
|
-
const
|
|
809
|
+
const element_children = getChildren(node);
|
|
810
|
+
const isEmpty = element_children.every((child) => isEmptyTextNode(child));
|
|
856
811
|
const isDoctypeTag = node.name.toUpperCase() === "!DOCTYPE";
|
|
857
812
|
const didSelfClose = options.originalText[node.end - 2] === "/";
|
|
858
|
-
const isSelfClosingTag = isEmpty && ((node.type === "
|
|
813
|
+
const isSelfClosingTag = isEmpty && ((node.type === "RegularElement" || node.type === "SvelteHead" || node.type === "Component" || node.type === "SvelteComponent" || node.type === "SvelteSelf" || node.type === "SlotElement" || node.type === "SvelteFragment" || node.type === "SvelteBoundary" || node.type === "TitleElement" || node.type === "SvelteBody" || node.type === "SvelteDocument" || node.type === "SvelteElement") && didSelfClose || node.type === "SvelteWindow" || selfClosingTags.indexOf(node.name) !== -1 || isDoctypeTag);
|
|
859
814
|
const attributes = path.map(printWithPrependedAttributeLine(node, options, print), "attributes");
|
|
860
815
|
const attributeLine = getAttributeLine(node, options);
|
|
861
|
-
const possibleThisBinding = node.type === "
|
|
816
|
+
const possibleThisBinding = node.type === "SvelteComponent" && node.expression ? [
|
|
862
817
|
attributeLine,
|
|
863
818
|
"this=",
|
|
864
819
|
...printJsExpression()
|
|
865
|
-
] : node.type === "
|
|
820
|
+
] : node.type === "SvelteElement" && node.tag ? [
|
|
866
821
|
attributeLine,
|
|
867
822
|
"this=",
|
|
868
|
-
...
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
823
|
+
...(() => {
|
|
824
|
+
var _a;
|
|
825
|
+
if (typeof node.tag === "string") return [`"${node.tag}"`];
|
|
826
|
+
if (((_a = node.tag) === null || _a === void 0 ? void 0 : _a.type) === "Literal" && typeof node.tag.value === "string") {
|
|
827
|
+
const literal_value = node.tag.value;
|
|
828
|
+
const tag_start = node.tag.start;
|
|
829
|
+
if (typeof tag_start === "number" && options.originalText[tag_start - 1] === "{") return [
|
|
830
|
+
open,
|
|
831
|
+
`"${literal_value}"`,
|
|
832
|
+
close
|
|
833
|
+
];
|
|
834
|
+
return [`"${literal_value}"`];
|
|
835
|
+
}
|
|
836
|
+
return [
|
|
837
|
+
open,
|
|
838
|
+
printJS(path, print, "tag"),
|
|
839
|
+
close
|
|
840
|
+
];
|
|
841
|
+
})()
|
|
873
842
|
] : "";
|
|
874
843
|
if (isSelfClosingTag) return group([
|
|
875
844
|
"<",
|
|
@@ -881,17 +850,17 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
881
850
|
])),
|
|
882
851
|
...[bracketSameLine && !isDoctypeTag ? " " : "", `${isDoctypeTag ? "" : "/"}>`]
|
|
883
852
|
]);
|
|
884
|
-
const children =
|
|
853
|
+
const children = element_children;
|
|
885
854
|
const firstChild = children[0];
|
|
886
855
|
const lastChild = children[children.length - 1];
|
|
887
856
|
let body;
|
|
888
857
|
const hugStart = shouldHugStart(node, isSupportedLanguage, options);
|
|
889
858
|
const hugEnd = shouldHugEnd(node, isSupportedLanguage, options);
|
|
890
|
-
if (isEmpty) body = isInlineElement(path, options, node) &&
|
|
891
|
-
else if (isPreTagContent(path)) body = () => printPre(
|
|
859
|
+
if (isEmpty) body = isInlineElement(path, options, node) && children.length && isTextNodeStartingWithWhitespace(children[0]) && !isPreTagContent(path) ? () => line : () => bracketSameLine ? softline : "";
|
|
860
|
+
else if (isPreTagContent(path)) body = () => path.call((fragment_path) => printPre(options.originalText, fragment_path, print), "fragment");
|
|
892
861
|
else if (!isSupportedLanguage) body = () => printRaw(node, options.originalText, true);
|
|
893
|
-
else if (isInlineElement(path, options, node) && !isPreTagContent(path)) body = () => printChildren(
|
|
894
|
-
else body = () => printChildren(
|
|
862
|
+
else if (isInlineElement(path, options, node) && !isPreTagContent(path)) body = () => path.call((fragment_path) => printChildren(fragment_path, print, options), "fragment");
|
|
863
|
+
else body = () => path.call((fragment_path) => printChildren(fragment_path, print, options), "fragment");
|
|
895
864
|
const openingTag = [
|
|
896
865
|
"<",
|
|
897
866
|
node.name,
|
|
@@ -972,17 +941,29 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
972
941
|
`</${node.name}>`
|
|
973
942
|
]);
|
|
974
943
|
}
|
|
975
|
-
case "Options":
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
]);
|
|
944
|
+
case "Options":
|
|
945
|
+
if (options.svelteSortOrder !== "none") throw new Error("Options tags should have been handled by prepareChildren");
|
|
946
|
+
return group([
|
|
947
|
+
"<",
|
|
948
|
+
node.name,
|
|
949
|
+
indent(group([...path.map(printWithPrependedAttributeLine(node, options, print), "attributes"), bracketSameLine ? "" : dedent(line)])),
|
|
950
|
+
...[bracketSameLine ? " " : "", "/>"]
|
|
951
|
+
]);
|
|
984
952
|
case "Identifier": return node.name;
|
|
985
|
-
case "
|
|
953
|
+
case "Literal": return JSON.stringify(node.value);
|
|
954
|
+
case "ConditionalExpression": return group([printJS(path, print, "test"), indent([
|
|
955
|
+
line,
|
|
956
|
+
"? ",
|
|
957
|
+
printJS(path, print, "consequent"),
|
|
958
|
+
line,
|
|
959
|
+
": ",
|
|
960
|
+
printJS(path, print, "alternate")
|
|
961
|
+
])]);
|
|
962
|
+
case "VariableDeclarator": return [
|
|
963
|
+
printJS(path, print, "id"),
|
|
964
|
+
" = ",
|
|
965
|
+
printJS(path, print, "init")
|
|
966
|
+
];
|
|
986
967
|
case "Attribute": if (isOrCanBeConvertedToShorthand(node)) if (options.svelteAllowShorthand) return [
|
|
987
968
|
"{",
|
|
988
969
|
node.name,
|
|
@@ -996,7 +977,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
996
977
|
];
|
|
997
978
|
else {
|
|
998
979
|
if (node.value === true) return [node.name];
|
|
999
|
-
const quotes = !isLoneMustacheTag(node.value)
|
|
980
|
+
const quotes = !isLoneMustacheTag(node.value);
|
|
1000
981
|
const attrNodeValue = printAttributeNodeValue(path, print, quotes, node);
|
|
1001
982
|
if (quotes) return [
|
|
1002
983
|
node.name,
|
|
@@ -1011,7 +992,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1011
992
|
attrNodeValue
|
|
1012
993
|
];
|
|
1013
994
|
}
|
|
1014
|
-
case "
|
|
995
|
+
case "ExpressionTag": return [
|
|
1015
996
|
"{",
|
|
1016
997
|
printJS(path, print, "expression"),
|
|
1017
998
|
"}"
|
|
@@ -1019,43 +1000,31 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1019
1000
|
case "IfBlock": {
|
|
1020
1001
|
const def = [
|
|
1021
1002
|
"{#if ",
|
|
1022
|
-
printJS(path, print, "
|
|
1003
|
+
printJS(path, print, "test"),
|
|
1023
1004
|
"}",
|
|
1024
|
-
|
|
1005
|
+
printBlockFragment(path, print, options, "consequent")
|
|
1025
1006
|
];
|
|
1026
|
-
if (node.
|
|
1007
|
+
if (node.alternate) def.push(printIfBlockAlternate(path, print, options));
|
|
1027
1008
|
def.push("{/if}");
|
|
1028
1009
|
return group([def, breakParent]);
|
|
1029
1010
|
}
|
|
1030
|
-
case "ElseBlock": {
|
|
1031
|
-
const parent = path.getParentNode();
|
|
1032
|
-
if (node.children.length === 1 && node.children[0].type === "IfBlock" && parent.type !== "EachBlock") {
|
|
1033
|
-
const ifNode = node.children[0];
|
|
1034
|
-
const def = [
|
|
1035
|
-
"{:else if ",
|
|
1036
|
-
path.map((ifPath) => printJS(ifPath, print, "expression"), "children")[0],
|
|
1037
|
-
"}",
|
|
1038
|
-
path.map((ifPath) => printSvelteBlockChildren(ifPath, print, options), "children")[0]
|
|
1039
|
-
];
|
|
1040
|
-
if (ifNode.else) def.push(path.map((ifPath) => ifPath.call(print, "else"), "children")[0]);
|
|
1041
|
-
return def;
|
|
1042
|
-
}
|
|
1043
|
-
return ["{:else}", printSvelteBlockChildren(path, print, options)];
|
|
1044
|
-
}
|
|
1045
1011
|
case "EachBlock": {
|
|
1046
1012
|
const def = ["{#each ", printJS(path, print, "expression")];
|
|
1047
1013
|
if (node.context) def.push(" as", expandNode(node.context, options.originalText));
|
|
1048
1014
|
if (node.index) def.push(", ", node.index);
|
|
1049
1015
|
if (node.key) def.push(" (", printJS(path, print, "key"), ")");
|
|
1050
|
-
def.push("}",
|
|
1051
|
-
if (node.
|
|
1016
|
+
def.push("}", printBlockFragment(path, print, options, "body"));
|
|
1017
|
+
if (node.fallback) def.push(printEachBlockFallback(path, print, options));
|
|
1052
1018
|
def.push("{/each}");
|
|
1053
1019
|
return group([def, breakParent]);
|
|
1054
1020
|
}
|
|
1055
1021
|
case "AwaitBlock": {
|
|
1056
|
-
const
|
|
1057
|
-
const
|
|
1058
|
-
const
|
|
1022
|
+
const pending_children = (_b = (_a = node.pending) === null || _a === void 0 ? void 0 : _a.nodes) !== null && _b !== void 0 ? _b : [];
|
|
1023
|
+
const then_children = (_d = (_c = node.then) === null || _c === void 0 ? void 0 : _c.nodes) !== null && _d !== void 0 ? _d : [];
|
|
1024
|
+
const catch_children = (_f = (_e = node.catch) === null || _e === void 0 ? void 0 : _e.nodes) !== null && _f !== void 0 ? _f : [];
|
|
1025
|
+
const hasPendingBlock = pending_children.some((n) => !isEmptyTextNode(n));
|
|
1026
|
+
const hasThenBlock = then_children.some((n) => !isEmptyTextNode(n));
|
|
1027
|
+
const hasCatchBlock = catch_children.some((n) => !isEmptyTextNode(n));
|
|
1059
1028
|
let block = [];
|
|
1060
1029
|
if (!hasPendingBlock && hasThenBlock) block.push(group([
|
|
1061
1030
|
"{#await ",
|
|
@@ -1063,32 +1032,32 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1063
1032
|
" then",
|
|
1064
1033
|
expandNode(node.value, options.originalText),
|
|
1065
1034
|
"}"
|
|
1066
|
-
]), path
|
|
1035
|
+
]), printBlockFragment(path, print, options, "then"));
|
|
1067
1036
|
else if (!hasPendingBlock && hasCatchBlock) block.push(group([
|
|
1068
1037
|
"{#await ",
|
|
1069
1038
|
printJS(path, print, "expression"),
|
|
1070
1039
|
" catch",
|
|
1071
1040
|
expandNode(node.error, options.originalText),
|
|
1072
1041
|
"}"
|
|
1073
|
-
]), path
|
|
1042
|
+
]), printBlockFragment(path, print, options, "catch"));
|
|
1074
1043
|
else {
|
|
1075
1044
|
block.push(group([
|
|
1076
1045
|
"{#await ",
|
|
1077
1046
|
printJS(path, print, "expression"),
|
|
1078
1047
|
"}"
|
|
1079
1048
|
]));
|
|
1080
|
-
if (hasPendingBlock) block.push(path
|
|
1049
|
+
if (hasPendingBlock) block.push(printBlockFragment(path, print, options, "pending"));
|
|
1081
1050
|
if (hasThenBlock) block.push(group([
|
|
1082
1051
|
"{:then",
|
|
1083
1052
|
expandNode(node.value, options.originalText),
|
|
1084
1053
|
"}"
|
|
1085
|
-
]), path
|
|
1054
|
+
]), printBlockFragment(path, print, options, "then"));
|
|
1086
1055
|
}
|
|
1087
1056
|
if ((hasPendingBlock || hasThenBlock) && hasCatchBlock) block.push(group([
|
|
1088
1057
|
"{:catch",
|
|
1089
1058
|
expandNode(node.error, options.originalText),
|
|
1090
1059
|
"}"
|
|
1091
|
-
]), path
|
|
1060
|
+
]), printBlockFragment(path, print, options, "catch"));
|
|
1092
1061
|
block.push("{/await}");
|
|
1093
1062
|
return group(block);
|
|
1094
1063
|
}
|
|
@@ -1097,31 +1066,28 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1097
1066
|
"{#key ",
|
|
1098
1067
|
printJS(path, print, "expression"),
|
|
1099
1068
|
"}",
|
|
1100
|
-
|
|
1069
|
+
printBlockFragment(path, print, options, "fragment")
|
|
1101
1070
|
];
|
|
1102
1071
|
def.push("{/key}");
|
|
1103
1072
|
return group([def, breakParent]);
|
|
1104
1073
|
}
|
|
1105
|
-
case "ThenBlock":
|
|
1106
|
-
case "PendingBlock":
|
|
1107
|
-
case "CatchBlock": return printSvelteBlockChildren(path, print, options);
|
|
1108
1074
|
case "SnippetBlock": {
|
|
1109
1075
|
const snippet = ["{#snippet ", printJS(path, print, "expression")];
|
|
1110
|
-
snippet.push("}",
|
|
1076
|
+
snippet.push("}", printBlockFragment(path, print, options, "body"), "{/snippet}");
|
|
1111
1077
|
return snippet;
|
|
1112
1078
|
}
|
|
1113
|
-
case "
|
|
1079
|
+
case "OnDirective": return [
|
|
1114
1080
|
"on:",
|
|
1115
1081
|
node.name,
|
|
1116
1082
|
node.modifiers && node.modifiers.length ? ["|", join("|", node.modifiers)] : "",
|
|
1117
1083
|
node.expression ? ["=", ...printJsExpression()] : ""
|
|
1118
1084
|
];
|
|
1119
|
-
case "
|
|
1085
|
+
case "BindDirective": return [
|
|
1120
1086
|
"bind:",
|
|
1121
1087
|
node.name,
|
|
1122
1088
|
node.expression.type === "Identifier" && node.expression.name === node.name && options.svelteAllowShorthand ? "" : ["=", ...printJsExpression()]
|
|
1123
1089
|
];
|
|
1124
|
-
case "
|
|
1090
|
+
case "ClassDirective": return [
|
|
1125
1091
|
"class:",
|
|
1126
1092
|
node.name,
|
|
1127
1093
|
node.expression.type === "Identifier" && node.expression.name === node.name && options.svelteAllowShorthand ? "" : ["=", ...printJsExpression()]
|
|
@@ -1140,7 +1106,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1140
1106
|
close
|
|
1141
1107
|
];
|
|
1142
1108
|
else {
|
|
1143
|
-
const quotes = !isLoneMustacheTag(node.value)
|
|
1109
|
+
const quotes = !isLoneMustacheTag(node.value);
|
|
1144
1110
|
const attrNodeValue = printAttributeNodeValue(path, print, quotes, node);
|
|
1145
1111
|
if (quotes) return [
|
|
1146
1112
|
...prefix,
|
|
@@ -1155,7 +1121,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1155
1121
|
attrNodeValue
|
|
1156
1122
|
];
|
|
1157
1123
|
}
|
|
1158
|
-
case "
|
|
1124
|
+
case "LetDirective": return [
|
|
1159
1125
|
"let:",
|
|
1160
1126
|
node.name,
|
|
1161
1127
|
!node.expression || node.expression.type === "Identifier" && node.expression.name === node.name ? "" : ["=", ...printJsExpression()]
|
|
@@ -1165,33 +1131,29 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1165
1131
|
node.identifiers.length > 0 ? [" ", join(", ", path.map(print, "identifiers"))] : "",
|
|
1166
1132
|
"}"
|
|
1167
1133
|
];
|
|
1168
|
-
case "
|
|
1169
|
-
case "Comment": {
|
|
1170
|
-
const nodeAfterComment = getNextNode(path);
|
|
1134
|
+
case "Comment":
|
|
1171
1135
|
if (isIgnoreStartDirective(node) && isNodeTopLevelHTML(node, path)) ignoreRange = true;
|
|
1172
1136
|
else if (isIgnoreEndDirective(node) && isNodeTopLevelHTML(node, path)) ignoreRange = false;
|
|
1173
|
-
else if (doesEmbedStartAfterNode(node, path) || isEmptyTextNode(nodeAfterComment) && doesEmbedStartAfterNode(nodeAfterComment, path)) return "";
|
|
1174
1137
|
else if (isIgnoreDirective(node)) ignoreNext = true;
|
|
1175
1138
|
return printComment(node);
|
|
1176
|
-
|
|
1177
|
-
case "Transition": return [
|
|
1139
|
+
case "TransitionDirective": return [
|
|
1178
1140
|
node.intro && node.outro ? "transition" : node.intro ? "in" : "out",
|
|
1179
1141
|
":",
|
|
1180
1142
|
node.name,
|
|
1181
1143
|
node.modifiers && node.modifiers.length ? ["|", join("|", node.modifiers)] : "",
|
|
1182
1144
|
node.expression ? ["=", ...printJsExpression()] : ""
|
|
1183
1145
|
];
|
|
1184
|
-
case "
|
|
1146
|
+
case "UseDirective": return [
|
|
1185
1147
|
"use:",
|
|
1186
1148
|
node.name,
|
|
1187
1149
|
node.expression ? ["=", ...printJsExpression()] : ""
|
|
1188
1150
|
];
|
|
1189
|
-
case "
|
|
1151
|
+
case "AnimateDirective": return [
|
|
1190
1152
|
"animate:",
|
|
1191
1153
|
node.name,
|
|
1192
1154
|
node.expression ? ["=", ...printJsExpression()] : ""
|
|
1193
1155
|
];
|
|
1194
|
-
case "
|
|
1156
|
+
case "HtmlTag": return [
|
|
1195
1157
|
"{@html ",
|
|
1196
1158
|
printJS(path, print, "expression"),
|
|
1197
1159
|
"}"
|
|
@@ -1206,22 +1168,149 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1206
1168
|
printJS(path, print, "expression"),
|
|
1207
1169
|
"}"
|
|
1208
1170
|
];
|
|
1209
|
-
case "
|
|
1171
|
+
case "SpreadAttribute": return [
|
|
1210
1172
|
"{...",
|
|
1211
1173
|
printJS(path, print, "expression"),
|
|
1212
1174
|
"}"
|
|
1213
1175
|
];
|
|
1214
1176
|
case "ConstTag": return [
|
|
1215
1177
|
"{@const ",
|
|
1216
|
-
printJS(path, print, "
|
|
1178
|
+
printJS(path, print, "declaration"),
|
|
1217
1179
|
"}"
|
|
1218
1180
|
];
|
|
1219
1181
|
}
|
|
1220
1182
|
console.error(JSON.stringify(node, null, 4));
|
|
1221
1183
|
throw new Error("unknown node type: " + node.type);
|
|
1222
1184
|
}
|
|
1185
|
+
/** When reordering top-level parts, remove the leading comment above `<svelte:options>` and print it */
|
|
1186
|
+
function stripSvelteOptionsComment(n) {
|
|
1187
|
+
const rootOptions = n.options;
|
|
1188
|
+
if (!rootOptions) return;
|
|
1189
|
+
let leadingCommentDoc;
|
|
1190
|
+
const nodes = n.fragment.nodes;
|
|
1191
|
+
for (let idx = 0; idx < nodes.length; idx++) {
|
|
1192
|
+
const node = nodes[idx];
|
|
1193
|
+
if (node.type !== "Comment" || isIgnoreEndDirective(node) || isIgnoreStartDirective(node)) continue;
|
|
1194
|
+
if (node.end === rootOptions.start) {
|
|
1195
|
+
leadingCommentDoc = printComment(node);
|
|
1196
|
+
nodes.splice(idx, 1);
|
|
1197
|
+
break;
|
|
1198
|
+
} else {
|
|
1199
|
+
let k = idx + 1;
|
|
1200
|
+
if (k < nodes.length && isEmptyTextNode(nodes[k]) && nodes[k].end === rootOptions.start) {
|
|
1201
|
+
leadingCommentDoc = printComment(node);
|
|
1202
|
+
nodes.splice(idx, 2);
|
|
1203
|
+
break;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
return leadingCommentDoc;
|
|
1208
|
+
}
|
|
1209
|
+
function hoistedEndsDescending(n) {
|
|
1210
|
+
const out = [];
|
|
1211
|
+
if (n.options) out.push({
|
|
1212
|
+
kind: "options",
|
|
1213
|
+
end: n.options.end
|
|
1214
|
+
});
|
|
1215
|
+
if (n.module) out.push({
|
|
1216
|
+
kind: "module",
|
|
1217
|
+
end: n.module.end
|
|
1218
|
+
});
|
|
1219
|
+
if (n.instance) out.push({
|
|
1220
|
+
kind: "instance",
|
|
1221
|
+
end: n.instance.end
|
|
1222
|
+
});
|
|
1223
|
+
if (n.css) out.push({
|
|
1224
|
+
kind: "css",
|
|
1225
|
+
end: n.css.end
|
|
1226
|
+
});
|
|
1227
|
+
out.sort((a, b) => b.end - a.end);
|
|
1228
|
+
return out;
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1231
|
+
* Hoisted roots (`options`, `module`, `instance`, `css`) are printed outside `fragment.nodes`, but the
|
|
1232
|
+
* next sibling may be `<!-- #endregion -->`. With `svelteSortOrder`, that comment must stay below the
|
|
1233
|
+
* printed block. Peel optional whitespace-only text nodes + the first HTML comment after `hoistedEnd`
|
|
1234
|
+
* only when it matches `#endregion` and there is no non-whitespace in `originalText` between positions.
|
|
1235
|
+
*/
|
|
1236
|
+
function extractRegionEndTrailAfterHoistedEnd(nodes, hoistedEnd) {
|
|
1237
|
+
const idx = nodes.findIndex((child) => child.start >= hoistedEnd);
|
|
1238
|
+
if (idx === -1) return;
|
|
1239
|
+
let whitespace;
|
|
1240
|
+
for (let i = idx; i < Math.min(idx + 2, nodes.length); i++) {
|
|
1241
|
+
const child = nodes[i];
|
|
1242
|
+
if (child.type === "Text" && isOnlyHtmlCollapseWhitespace(getUnencodedText(child))) {
|
|
1243
|
+
whitespace = child;
|
|
1244
|
+
continue;
|
|
1245
|
+
} else if (child.type === "Comment" && /#\s*endregion\b/i.test(child.data)) {
|
|
1246
|
+
nodes.splice(idx, i + 1 - idx);
|
|
1247
|
+
return {
|
|
1248
|
+
whitespace,
|
|
1249
|
+
comment: child
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
function printRegionEndTrailDoc(trail) {
|
|
1256
|
+
const pieces = [];
|
|
1257
|
+
if (trail.whitespace) {
|
|
1258
|
+
const doc = printWhitespace(getUnencodedText(trail.whitespace).replace(/^\r?\n/, ""));
|
|
1259
|
+
pieces.push(...Array.isArray(doc) ? doc : [doc]);
|
|
1260
|
+
}
|
|
1261
|
+
pieces.push(printComment(trail.comment));
|
|
1262
|
+
return group([...pieces, hardline]);
|
|
1263
|
+
}
|
|
1264
|
+
function mergeAdjacentTextNodesInFragment(nodes) {
|
|
1265
|
+
for (let i = 0; i < nodes.length - 1;) {
|
|
1266
|
+
const current = nodes[i];
|
|
1267
|
+
const next = nodes[i + 1];
|
|
1268
|
+
if (current.type === "Text" && next.type === "Text") {
|
|
1269
|
+
trimTextNodeRight(current);
|
|
1270
|
+
current.raw += next.raw;
|
|
1271
|
+
current.data += next.data;
|
|
1272
|
+
current.end = next.end;
|
|
1273
|
+
nodes.splice(i + 1, 1);
|
|
1274
|
+
} else i++;
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
function printSvelteOptions(path, parserOptions, print, rootOptions, leadingCommentDoc) {
|
|
1278
|
+
const bracketSameLine = isBracketSameLine(parserOptions);
|
|
1279
|
+
const optsNode = {
|
|
1280
|
+
type: "Options",
|
|
1281
|
+
name: "svelte:options",
|
|
1282
|
+
start: rootOptions.start,
|
|
1283
|
+
end: rootOptions.end,
|
|
1284
|
+
attributes: rootOptions.attributes
|
|
1285
|
+
};
|
|
1286
|
+
let doc = group([[
|
|
1287
|
+
"<",
|
|
1288
|
+
optsNode.name,
|
|
1289
|
+
indent(group([...path.call((optionsPath) => optionsPath.map(printWithPrependedAttributeLine(optsNode, parserOptions, print), "attributes"), "options"), bracketSameLine ? "" : dedent(line)])),
|
|
1290
|
+
...[bracketSameLine ? " " : "", "/>"]
|
|
1291
|
+
], hardline]);
|
|
1292
|
+
if (leadingCommentDoc) doc = group([
|
|
1293
|
+
leadingCommentDoc,
|
|
1294
|
+
hardline,
|
|
1295
|
+
doc
|
|
1296
|
+
]);
|
|
1297
|
+
return doc;
|
|
1298
|
+
}
|
|
1223
1299
|
function printTopLevelParts(n, options, path, print) {
|
|
1224
1300
|
if (options.svelteSortOrder === "none") {
|
|
1301
|
+
if (n.options) {
|
|
1302
|
+
const nodes = n.fragment.nodes;
|
|
1303
|
+
if (!nodes.some((node) => node.type === "Options")) {
|
|
1304
|
+
nodes.push({
|
|
1305
|
+
type: "Options",
|
|
1306
|
+
name: "svelte:options",
|
|
1307
|
+
start: n.options.start,
|
|
1308
|
+
end: n.options.end,
|
|
1309
|
+
attributes: n.options.attributes
|
|
1310
|
+
});
|
|
1311
|
+
nodes.sort((a, b) => a.start - b.start);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1225
1314
|
const topLevelPartsByEnd = {};
|
|
1226
1315
|
const topLevelPartsByStart = {};
|
|
1227
1316
|
if (n.module) {
|
|
@@ -1236,7 +1325,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1236
1325
|
topLevelPartsByEnd[n.css.end] = n.css;
|
|
1237
1326
|
topLevelPartsByStart[n.css.start] = n.css;
|
|
1238
1327
|
}
|
|
1239
|
-
const children =
|
|
1328
|
+
const children = n.fragment.nodes;
|
|
1240
1329
|
for (let i = 0; i < children.length; i++) {
|
|
1241
1330
|
const node = children[i];
|
|
1242
1331
|
if (topLevelPartsByEnd[node.start]) {
|
|
@@ -1244,7 +1333,8 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1244
1333
|
delete topLevelPartsByEnd[node.start];
|
|
1245
1334
|
} else if (i === children.length - 1 && topLevelPartsByStart[node.end]) children.push(topLevelPartsByStart[node.end]);
|
|
1246
1335
|
}
|
|
1247
|
-
|
|
1336
|
+
mergeAdjacentTextNodesInFragment(children);
|
|
1337
|
+
const result = path.call(print, "fragment");
|
|
1248
1338
|
if (options.insertPragma && !hasPragma(options.originalText)) return [
|
|
1249
1339
|
`<!-- @format -->`,
|
|
1250
1340
|
hardline,
|
|
@@ -1258,16 +1348,41 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1258
1348
|
markup: [],
|
|
1259
1349
|
styles: []
|
|
1260
1350
|
};
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1351
|
+
const regionEndTrail = {};
|
|
1352
|
+
for (const { kind, end } of hoistedEndsDescending(n)) {
|
|
1353
|
+
const trail = extractRegionEndTrailAfterHoistedEnd(n.fragment.nodes, end);
|
|
1354
|
+
if (trail) regionEndTrail[kind] = trail;
|
|
1355
|
+
}
|
|
1356
|
+
if (n.module) {
|
|
1357
|
+
let doc = path.call(print, "module");
|
|
1358
|
+
const trail = regionEndTrail.module;
|
|
1359
|
+
if (trail) doc = group([doc, printRegionEndTrailDoc(trail)]);
|
|
1360
|
+
parts.scripts.push(doc);
|
|
1361
|
+
}
|
|
1362
|
+
if (n.instance) {
|
|
1363
|
+
let doc = path.call(print, "instance");
|
|
1364
|
+
const trail = regionEndTrail.instance;
|
|
1365
|
+
if (trail) doc = group([doc, printRegionEndTrailDoc(trail)]);
|
|
1366
|
+
parts.scripts.push(doc);
|
|
1367
|
+
}
|
|
1368
|
+
if (n.css) {
|
|
1369
|
+
let doc = path.call(print, "css");
|
|
1370
|
+
const trail = regionEndTrail.css;
|
|
1371
|
+
if (trail) doc = group([doc, printRegionEndTrailDoc(trail)]);
|
|
1372
|
+
parts.styles.push(doc);
|
|
1373
|
+
}
|
|
1374
|
+
if (n.options) {
|
|
1375
|
+
let doc = printSvelteOptions(path, options, print, n.options, stripSvelteOptionsComment(n));
|
|
1376
|
+
const trail = regionEndTrail.options;
|
|
1377
|
+
if (trail) doc = group([doc, printRegionEndTrailDoc(trail)]);
|
|
1378
|
+
parts.options.push(doc);
|
|
1379
|
+
}
|
|
1380
|
+
mergeAdjacentTextNodesInFragment(n.fragment.nodes);
|
|
1381
|
+
const htmlDoc = path.call(print, "fragment");
|
|
1265
1382
|
if (htmlDoc) parts.markup.push(htmlDoc);
|
|
1266
|
-
if (svelteOptionsDoc) parts.options.push(svelteOptionsDoc);
|
|
1267
1383
|
const docs = flatten(parseSortOrder(options.svelteSortOrder).map((p) => parts[p]));
|
|
1268
1384
|
ignoreNext = false;
|
|
1269
1385
|
ignoreRange = false;
|
|
1270
|
-
svelteOptionsDoc = void 0;
|
|
1271
1386
|
if (options.parentParser === "markdown") {
|
|
1272
1387
|
const lastDoc = docs[docs.length - 1];
|
|
1273
1388
|
trimRight([lastDoc], isLine);
|
|
@@ -1280,16 +1395,17 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1280
1395
|
else return group([join(hardline, docs)]);
|
|
1281
1396
|
}
|
|
1282
1397
|
function printAttributeNodeValue(path, print, quotes, node) {
|
|
1283
|
-
const valueDocs = path.map((childPath) => childPath.call(print), "value");
|
|
1398
|
+
const valueDocs = Array.isArray(node.value) ? path.map((childPath) => childPath.call(print), "value") : [path.call(print, "value")];
|
|
1284
1399
|
if (!quotes || !formattableAttributes.includes(node.name)) return valueDocs;
|
|
1285
1400
|
else return indent(group(trim(valueDocs, isLine)));
|
|
1286
1401
|
}
|
|
1287
1402
|
function printSvelteBlockChildren(path, print, options) {
|
|
1288
|
-
|
|
1289
|
-
const
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
const
|
|
1403
|
+
var _a;
|
|
1404
|
+
const fragment = path.node;
|
|
1405
|
+
const children = (_a = fragment === null || fragment === void 0 ? void 0 : fragment.nodes) !== null && _a !== void 0 ? _a : [];
|
|
1406
|
+
if (children.length === 0) return "";
|
|
1407
|
+
const whitespaceAtStartOfBlock = checkWhitespaceAtStartOfSvelteBlock(fragment, options);
|
|
1408
|
+
const whitespaceAtEndOfBlock = checkWhitespaceAtEndOfSvelteBlock(fragment, options);
|
|
1293
1409
|
const startline = whitespaceAtStartOfBlock === "none" ? "" : whitespaceAtEndOfBlock === "line" || whitespaceAtStartOfBlock === "line" ? hardline : line;
|
|
1294
1410
|
const endline = whitespaceAtEndOfBlock === "none" ? "" : whitespaceAtEndOfBlock === "line" || whitespaceAtStartOfBlock === "line" ? hardline : line;
|
|
1295
1411
|
const firstChild = children[0];
|
|
@@ -1298,28 +1414,58 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1298
1414
|
if (isTextNodeEndingWithWhitespace(lastChild)) trimTextNodeRight(lastChild);
|
|
1299
1415
|
return [indent([startline, group(printChildren(path, print, options))]), endline];
|
|
1300
1416
|
}
|
|
1301
|
-
function
|
|
1417
|
+
function printBlockFragment(path, print, options, to) {
|
|
1418
|
+
return path.call((fragment_path) => printSvelteBlockChildren(fragment_path, print, options), to);
|
|
1419
|
+
}
|
|
1420
|
+
function printIfBlockAlternate(path, print, options) {
|
|
1421
|
+
const alternate = path.node.alternate;
|
|
1422
|
+
if (!alternate) return "";
|
|
1423
|
+
if (alternate.type === "Fragment") {
|
|
1424
|
+
if (alternate.nodes.length === 1 && alternate.nodes[0].type === "IfBlock" && alternate.nodes[0].elseif) {
|
|
1425
|
+
const def = [
|
|
1426
|
+
"{:else if ",
|
|
1427
|
+
path.call((if_path) => printJS(if_path, print, "test"), "alternate", "nodes", 0),
|
|
1428
|
+
"}",
|
|
1429
|
+
path.call((if_path) => printBlockFragment(if_path, print, options, "consequent"), "alternate", "nodes", 0)
|
|
1430
|
+
];
|
|
1431
|
+
if (alternate.nodes[0].alternate) def.push(path.call((if_path) => printIfBlockAlternate(if_path, print, options), "alternate", "nodes", 0));
|
|
1432
|
+
return def;
|
|
1433
|
+
}
|
|
1434
|
+
return ["{:else}", printBlockFragment(path, print, options, "alternate")];
|
|
1435
|
+
}
|
|
1436
|
+
return ["{:else}", printBlockFragment(path, print, options, "alternate")];
|
|
1437
|
+
}
|
|
1438
|
+
function printEachBlockFallback(path, print, options) {
|
|
1439
|
+
if (!path.node.fallback) return "";
|
|
1440
|
+
return ["{:else}", printBlockFragment(path, print, options, "fallback")];
|
|
1441
|
+
}
|
|
1442
|
+
function printPre(originalText, path, print) {
|
|
1443
|
+
var _a;
|
|
1302
1444
|
const result = [];
|
|
1303
|
-
const
|
|
1445
|
+
const fragment = path.node;
|
|
1446
|
+
const children = (_a = fragment === null || fragment === void 0 ? void 0 : fragment.nodes) !== null && _a !== void 0 ? _a : [];
|
|
1447
|
+
if (children.length === 0) return "";
|
|
1448
|
+
const length = children.length;
|
|
1304
1449
|
for (let i = 0; i < length; i++) {
|
|
1305
|
-
const child =
|
|
1450
|
+
const child = children[i];
|
|
1306
1451
|
if (child.type === "Text") originalText.substring(child.start, child.end).split(/\r?\n/).forEach((line, j) => {
|
|
1307
1452
|
if (j > 0) result.push(literalline);
|
|
1308
1453
|
result.push(line);
|
|
1309
1454
|
});
|
|
1310
|
-
else result.push(path.call(print, "
|
|
1455
|
+
else result.push(path.call(print, "nodes", i));
|
|
1311
1456
|
}
|
|
1312
1457
|
return result;
|
|
1313
1458
|
}
|
|
1314
1459
|
function printChildren(path, print, options) {
|
|
1315
|
-
|
|
1316
|
-
const
|
|
1317
|
-
path.
|
|
1318
|
-
|
|
1460
|
+
var _a;
|
|
1461
|
+
const current_value = path.node;
|
|
1462
|
+
if (isPreTagContent(path)) return path.map(print, "nodes");
|
|
1463
|
+
const prepared_children = prepareChildren((_a = current_value.nodes) !== null && _a !== void 0 ? _a : []);
|
|
1464
|
+
if (prepared_children.length === 0) return "";
|
|
1319
1465
|
const childDocs = [];
|
|
1320
1466
|
let handleWhitespaceOfPrevTextNode = false;
|
|
1321
|
-
for (let i = 0; i <
|
|
1322
|
-
const childNode =
|
|
1467
|
+
for (let i = 0; i < prepared_children.length; i++) {
|
|
1468
|
+
const childNode = prepared_children[i].node;
|
|
1323
1469
|
if (childNode.type === "Text") handleTextChild(i, childNode);
|
|
1324
1470
|
else if (isBlockElement(childNode, options)) handleBlockChild(i);
|
|
1325
1471
|
else if (isInlineElement(path, options, childNode)) handleInlineChild(i);
|
|
@@ -1328,10 +1474,10 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1328
1474
|
handleWhitespaceOfPrevTextNode = false;
|
|
1329
1475
|
}
|
|
1330
1476
|
}
|
|
1331
|
-
if (
|
|
1477
|
+
if (prepared_children.length > 1 && prepared_children.some((child) => isBlockElement(child.node, options))) childDocs.push(breakParent);
|
|
1332
1478
|
return childDocs;
|
|
1333
1479
|
function printChild(idx) {
|
|
1334
|
-
return path.call(print, "
|
|
1480
|
+
return path.call(print, "nodes", prepared_children[idx].index);
|
|
1335
1481
|
}
|
|
1336
1482
|
/**
|
|
1337
1483
|
* Print inline child. Hug whitespace of previous text child if there was one.
|
|
@@ -1348,11 +1494,12 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1348
1494
|
* kind of whitespace handling is done in the parent already.
|
|
1349
1495
|
*/
|
|
1350
1496
|
function handleBlockChild(idx) {
|
|
1351
|
-
|
|
1497
|
+
var _a, _b;
|
|
1498
|
+
const prevChild = (_a = prepared_children[idx - 1]) === null || _a === void 0 ? void 0 : _a.node;
|
|
1352
1499
|
if (prevChild && !isBlockElement(prevChild, options) && (prevChild.type !== "Text" || handleWhitespaceOfPrevTextNode || !isTextNodeEndingWithWhitespace(prevChild))) childDocs.push(softline);
|
|
1353
1500
|
childDocs.push(printChild(idx));
|
|
1354
|
-
const nextChild =
|
|
1355
|
-
if (nextChild && (nextChild.type !== "Text" || (!isEmptyTextNode(nextChild) ||
|
|
1501
|
+
const nextChild = (_b = prepared_children[idx + 1]) === null || _b === void 0 ? void 0 : _b.node;
|
|
1502
|
+
if (nextChild && (nextChild.type !== "Text" || (!isEmptyTextNode(nextChild) || prepared_children[idx + 2] && isInlineElement(path, options, prepared_children[idx + 2].node)) && !isTextNodeStartingWithLinebreak(nextChild))) childDocs.push(softline);
|
|
1356
1503
|
handleWhitespaceOfPrevTextNode = false;
|
|
1357
1504
|
}
|
|
1358
1505
|
/**
|
|
@@ -1366,12 +1513,12 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1366
1513
|
*/
|
|
1367
1514
|
function handleTextChild(idx, childNode) {
|
|
1368
1515
|
handleWhitespaceOfPrevTextNode = false;
|
|
1369
|
-
if (idx === 0 || idx ===
|
|
1516
|
+
if (idx === 0 || idx === prepared_children.length - 1) {
|
|
1370
1517
|
childDocs.push(printChild(idx));
|
|
1371
1518
|
return;
|
|
1372
1519
|
}
|
|
1373
|
-
const prevNode =
|
|
1374
|
-
const nextNode =
|
|
1520
|
+
const prevNode = prepared_children[idx - 1].node;
|
|
1521
|
+
const nextNode = prepared_children[idx + 1].node;
|
|
1375
1522
|
if (isTextNodeStartingWithWhitespace(childNode) && !isEmptyTextNode(childNode)) {
|
|
1376
1523
|
if (isInlineElement(path, options, prevNode) && !isTextNodeStartingWithLinebreak(childNode)) {
|
|
1377
1524
|
trimTextNodeLeft(childNode);
|
|
@@ -1393,70 +1540,17 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1393
1540
|
childDocs.push(printChild(idx));
|
|
1394
1541
|
}
|
|
1395
1542
|
}
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
* separately to reorder it as configured. The comment above it should be moved with it.
|
|
1399
|
-
* Do that here.
|
|
1400
|
-
*/
|
|
1401
|
-
function prepareChildren(children, path, print, options) {
|
|
1402
|
-
let svelteOptionsComment;
|
|
1403
|
-
const childrenWithoutOptions = [];
|
|
1404
|
-
const bracketSameLine = isBracketSameLine(options);
|
|
1543
|
+
function prepareChildren(children, path) {
|
|
1544
|
+
const prepared = [];
|
|
1405
1545
|
for (let idx = 0; idx < children.length; idx++) {
|
|
1406
1546
|
const currentChild = children[idx];
|
|
1407
1547
|
if (currentChild.type === "Text" && getUnencodedText(currentChild) === "") continue;
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
const nextChild = children[idx + 1];
|
|
1413
|
-
idx += nextChild && isEmptyTextNode(nextChild) ? 1 : 0;
|
|
1414
|
-
continue;
|
|
1415
|
-
}
|
|
1416
|
-
if (currentChild.type === "Options") {
|
|
1417
|
-
printSvelteOptions(currentChild, idx, path, print);
|
|
1418
|
-
continue;
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
childrenWithoutOptions.push(currentChild);
|
|
1422
|
-
}
|
|
1423
|
-
const mergedChildrenWithoutOptions = [];
|
|
1424
|
-
for (let idx = 0; idx < childrenWithoutOptions.length; idx++) {
|
|
1425
|
-
const currentChild = childrenWithoutOptions[idx];
|
|
1426
|
-
const nextChild = childrenWithoutOptions[idx + 1];
|
|
1427
|
-
if (currentChild.type === "Text" && nextChild && nextChild.type === "Text") {
|
|
1428
|
-
currentChild.raw += nextChild.raw;
|
|
1429
|
-
currentChild.data += nextChild.data;
|
|
1430
|
-
idx++;
|
|
1431
|
-
}
|
|
1432
|
-
mergedChildrenWithoutOptions.push(currentChild);
|
|
1433
|
-
}
|
|
1434
|
-
return mergedChildrenWithoutOptions;
|
|
1435
|
-
function printSvelteOptions(node, idx, path, print) {
|
|
1436
|
-
svelteOptionsDoc = group([[
|
|
1437
|
-
"<",
|
|
1438
|
-
node.name,
|
|
1439
|
-
indent(group([...path.map(printWithPrependedAttributeLine(node, options, print), "children", idx, "attributes"), bracketSameLine ? "" : dedent(line)])),
|
|
1440
|
-
...[bracketSameLine ? " " : "", "/>"]
|
|
1441
|
-
], hardline]);
|
|
1442
|
-
if (svelteOptionsComment) svelteOptionsDoc = group([
|
|
1443
|
-
svelteOptionsComment,
|
|
1444
|
-
hardline,
|
|
1445
|
-
svelteOptionsDoc
|
|
1446
|
-
]);
|
|
1447
|
-
}
|
|
1448
|
-
function isCommentFollowedByOptions(node, idx) {
|
|
1449
|
-
if (node.type !== "Comment" || isIgnoreEndDirective(node) || isIgnoreStartDirective(node)) return false;
|
|
1450
|
-
const nextChild = children[idx + 1];
|
|
1451
|
-
if (nextChild) {
|
|
1452
|
-
if (isEmptyTextNode(nextChild)) {
|
|
1453
|
-
const afterNext = children[idx + 2];
|
|
1454
|
-
return afterNext && afterNext.type === "Options";
|
|
1455
|
-
}
|
|
1456
|
-
return nextChild.type === "Options";
|
|
1457
|
-
}
|
|
1458
|
-
return false;
|
|
1548
|
+
prepared.push({
|
|
1549
|
+
node: currentChild,
|
|
1550
|
+
index: idx
|
|
1551
|
+
});
|
|
1459
1552
|
}
|
|
1553
|
+
return prepared;
|
|
1460
1554
|
}
|
|
1461
1555
|
/**
|
|
1462
1556
|
* Split the text into words separated by whitespace. Replace the whitespaces by lines,
|
|
@@ -1514,48 +1608,24 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1514
1608
|
"-->"
|
|
1515
1609
|
]);
|
|
1516
1610
|
}
|
|
1611
|
+
function printWhitespace(text) {
|
|
1612
|
+
const hasWhiteSpace = text.length > 0;
|
|
1613
|
+
const hasOneOrMoreNewlines = /\n/.test(text);
|
|
1614
|
+
if (/\n\r?[\t\n\f\r ]*\n\r?/.test(text)) return [hardline, hardline];
|
|
1615
|
+
if (hasOneOrMoreNewlines) return hardline;
|
|
1616
|
+
if (hasWhiteSpace) return line;
|
|
1617
|
+
return "";
|
|
1618
|
+
}
|
|
1517
1619
|
function getText(node, options, unsnip = false) {
|
|
1518
1620
|
const leadingComments = node.leadingComments;
|
|
1519
1621
|
const text = options.originalText.slice(options.locStart(leadingComments && leadingComments[0] || node), options.locEnd(node));
|
|
1520
1622
|
if (!unsnip || !hasSnippedContent(text)) return text;
|
|
1521
1623
|
return unsnipContent(text);
|
|
1522
1624
|
}
|
|
1523
|
-
const extractAttributesRegex = /<[a-z]+((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)>/im;
|
|
1524
|
-
const attributeRegex = /([^\s=]+)(?:=(?:(?:("|')([\s\S]*?)\2)|(?:([^>\s]+?)(?:\s|>|$))))?/gim;
|
|
1525
|
-
function extractAttributes(html) {
|
|
1526
|
-
const [, attributesString] = html.match(extractAttributesRegex);
|
|
1527
|
-
const attrs = [];
|
|
1528
|
-
let match;
|
|
1529
|
-
while (match = attributeRegex.exec(attributesString)) {
|
|
1530
|
-
const [all, name, quotes, valueQuoted, valueUnquoted] = match;
|
|
1531
|
-
const value = valueQuoted || valueUnquoted;
|
|
1532
|
-
const attrStart = match.index;
|
|
1533
|
-
let valueNode;
|
|
1534
|
-
if (!value) valueNode = true;
|
|
1535
|
-
else {
|
|
1536
|
-
let valueStart = attrStart + name.length;
|
|
1537
|
-
if (quotes) valueStart += 2;
|
|
1538
|
-
valueNode = [{
|
|
1539
|
-
type: "Text",
|
|
1540
|
-
data: value,
|
|
1541
|
-
start: valueStart,
|
|
1542
|
-
end: valueStart + value.length
|
|
1543
|
-
}];
|
|
1544
|
-
}
|
|
1545
|
-
attrs.push({
|
|
1546
|
-
type: "Attribute",
|
|
1547
|
-
name,
|
|
1548
|
-
value: valueNode,
|
|
1549
|
-
start: attrStart,
|
|
1550
|
-
end: attrStart + all.length
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
return attrs;
|
|
1554
|
-
}
|
|
1555
1625
|
const { builders: { group: group$1, hardline: hardline$1, softline: softline$1, indent: indent$1, dedent: dedent$1, literalline: literalline$1 }, utils: { removeLines } } = prettier.doc;
|
|
1556
1626
|
const leaveAlone = new Set([
|
|
1557
1627
|
"Script",
|
|
1558
|
-
"
|
|
1628
|
+
"StyleSheet",
|
|
1559
1629
|
"Identifier",
|
|
1560
1630
|
"MemberExpression",
|
|
1561
1631
|
"CallExpression",
|
|
@@ -1572,36 +1642,22 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1572
1642
|
});
|
|
1573
1643
|
}
|
|
1574
1644
|
function embed(path, _options) {
|
|
1575
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
1645
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1576
1646
|
const node = path.getNode();
|
|
1577
1647
|
const options = _options;
|
|
1578
1648
|
if (!options.locStart || !options.locEnd || !options.originalText) throw new Error("Missing required options");
|
|
1579
1649
|
if (isASTNode(node)) {
|
|
1580
1650
|
assignCommentsToNodes(node);
|
|
1581
1651
|
attachAttributeComments(node, options.originalText);
|
|
1582
|
-
if (node.module) {
|
|
1583
|
-
node.module.type = "Script";
|
|
1584
|
-
node.module.attributes = extractAttributes(getText(node.module, options));
|
|
1585
|
-
}
|
|
1586
|
-
if (node.instance) {
|
|
1587
|
-
node.instance.type = "Script";
|
|
1588
|
-
node.instance.attributes = extractAttributes(getText(node.instance, options));
|
|
1589
|
-
}
|
|
1590
|
-
if (node.css) {
|
|
1591
|
-
node.css.type = "Style";
|
|
1592
|
-
node.css.content.type = "StyleProgram";
|
|
1593
|
-
}
|
|
1594
1652
|
return null;
|
|
1595
1653
|
}
|
|
1596
1654
|
const parent = path.getParentNode();
|
|
1597
|
-
const printJsExpression = () => {
|
|
1598
|
-
var _a;
|
|
1599
|
-
return parent.expression ? printJS$1(parent, "expression", { forceSingleQuote: (_a = options.svelteStrictMode && !options._svelte_is5Plus) !== null && _a !== void 0 ? _a : false }) : void 0;
|
|
1600
|
-
};
|
|
1655
|
+
const printJsExpression = () => parent.expression ? printJS$1(parent, "expression", {}) : void 0;
|
|
1601
1656
|
const printSvelteBlockJS = (name) => printJS$1(parent, name, { forceSingleLine: true });
|
|
1602
1657
|
switch (parent.type) {
|
|
1603
1658
|
case "IfBlock":
|
|
1604
|
-
|
|
1659
|
+
printSvelteBlockJS("test");
|
|
1660
|
+
break;
|
|
1605
1661
|
case "AwaitBlock":
|
|
1606
1662
|
case "KeyBlock":
|
|
1607
1663
|
printSvelteBlockJS("expression");
|
|
@@ -1618,48 +1674,48 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1618
1674
|
node.asFunction = true;
|
|
1619
1675
|
}
|
|
1620
1676
|
break;
|
|
1621
|
-
case "
|
|
1622
|
-
|
|
1677
|
+
case "RegularElement":
|
|
1678
|
+
case "SvelteElement":
|
|
1679
|
+
printJS$1(parent, "tag", {});
|
|
1623
1680
|
break;
|
|
1624
|
-
case "
|
|
1625
|
-
printJS$1(parent, "expression", { forceSingleQuote: isInsideQuotedAttribute(path
|
|
1681
|
+
case "ExpressionTag":
|
|
1682
|
+
printJS$1(parent, "expression", { forceSingleQuote: isInsideQuotedAttribute(path) });
|
|
1626
1683
|
break;
|
|
1627
|
-
case "
|
|
1684
|
+
case "HtmlTag":
|
|
1628
1685
|
printJS$1(parent, "expression", {});
|
|
1629
1686
|
break;
|
|
1630
|
-
case "
|
|
1687
|
+
case "SpreadAttribute":
|
|
1631
1688
|
printJS$1(parent, "expression", {});
|
|
1632
1689
|
break;
|
|
1633
1690
|
case "AttachTag":
|
|
1634
1691
|
printJS$1(parent, "expression", {});
|
|
1635
1692
|
break;
|
|
1636
|
-
case "
|
|
1637
|
-
|
|
1693
|
+
case "VariableDeclarator": {
|
|
1694
|
+
const declaration = path.getParentNode(1);
|
|
1695
|
+
const constTag = path.getParentNode(2);
|
|
1696
|
+
if ((declaration === null || declaration === void 0 ? void 0 : declaration.type) === "VariableDeclaration" && (constTag === null || constTag === void 0 ? void 0 : constTag.type) === "ConstTag") {
|
|
1697
|
+
constTag.declaration = parent;
|
|
1698
|
+
printJS$1(constTag, "declaration", { removeParentheses: true });
|
|
1699
|
+
}
|
|
1638
1700
|
break;
|
|
1639
|
-
|
|
1701
|
+
}
|
|
1702
|
+
case "BindDirective":
|
|
1640
1703
|
printJS$1(parent, "expression", {
|
|
1641
1704
|
removeParentheses: parent.expression.type === "SequenceExpression",
|
|
1642
1705
|
surroundWithSoftline: true
|
|
1643
1706
|
});
|
|
1644
1707
|
break;
|
|
1645
1708
|
case "RenderTag":
|
|
1646
|
-
if (node === parent.expression) {
|
|
1647
|
-
if ("argument" in parent || "arguments" in parent) {
|
|
1648
|
-
parent.expression.end = options.originalText.indexOf(")", (_o = (_k = (_j = parent.argument) === null || _j === void 0 ? void 0 : _j.end) !== null && _k !== void 0 ? _k : (_m = (_l = parent.arguments) === null || _l === void 0 ? void 0 : _l[parent.arguments.length - 1]) === null || _m === void 0 ? void 0 : _m.end) !== null && _o !== void 0 ? _o : parent.expression.end) + 1;
|
|
1649
|
-
parent.argument = null;
|
|
1650
|
-
parent.arguments = null;
|
|
1651
|
-
}
|
|
1652
|
-
printJS$1(parent, "expression", {});
|
|
1653
|
-
}
|
|
1709
|
+
if (node === parent.expression) printJS$1(parent, "expression", {});
|
|
1654
1710
|
break;
|
|
1655
|
-
case "
|
|
1656
|
-
case "
|
|
1657
|
-
case "
|
|
1658
|
-
case "
|
|
1659
|
-
case "
|
|
1660
|
-
case "
|
|
1661
|
-
case "
|
|
1662
|
-
case "
|
|
1711
|
+
case "OnDirective":
|
|
1712
|
+
case "BindDirective":
|
|
1713
|
+
case "ClassDirective":
|
|
1714
|
+
case "LetDirective":
|
|
1715
|
+
case "TransitionDirective":
|
|
1716
|
+
case "UseDirective":
|
|
1717
|
+
case "AnimateDirective":
|
|
1718
|
+
case "SvelteComponent":
|
|
1663
1719
|
printJsExpression();
|
|
1664
1720
|
break;
|
|
1665
1721
|
}
|
|
@@ -1698,8 +1754,8 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1698
1754
|
const embedPug = () => embedType("template", "pug", false);
|
|
1699
1755
|
switch (node.type) {
|
|
1700
1756
|
case "Script": return embedScript(true);
|
|
1701
|
-
case "
|
|
1702
|
-
case "
|
|
1757
|
+
case "StyleSheet": return embedStyle(true);
|
|
1758
|
+
case "RegularElement": if (node.name === "script") return embedScript(false);
|
|
1703
1759
|
else if (node.name === "style") return embedStyle(false);
|
|
1704
1760
|
else if (isPugTemplate(node)) return embedPug();
|
|
1705
1761
|
}
|
|
@@ -1743,15 +1799,15 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1743
1799
|
});
|
|
1744
1800
|
}
|
|
1745
1801
|
function embedTag(tag, text, path, formatBodyContent, print, isTopLevel, options) {
|
|
1746
|
-
var _a;
|
|
1802
|
+
var _a, _b;
|
|
1747
1803
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1748
1804
|
const node = path.getNode();
|
|
1749
1805
|
const content = tag === "template" ? printRaw(node, text) : getSnippedContent(node);
|
|
1750
|
-
const previousComments = node.type === "Script" || node.type === "
|
|
1806
|
+
const previousComments = node.type === "Script" || node.type === "StyleSheet" ? (_a = node.comments) !== null && _a !== void 0 ? _a : [] : [getLeadingComment(path)].filter(Boolean).map((comment) => ({
|
|
1751
1807
|
comment,
|
|
1752
1808
|
emptyLineAfter: false
|
|
1753
1809
|
}));
|
|
1754
|
-
const body = isNodeSupportedLanguage(node) && !isIgnoreDirective((
|
|
1810
|
+
const body = isNodeSupportedLanguage(node) && !isIgnoreDirective((_b = previousComments[previousComments.length - 1]) === null || _b === void 0 ? void 0 : _b.comment) && (tag !== "template" || options.plugins.some((plugin) => typeof plugin !== "string" && !(plugin instanceof URL) && plugin.name === "prettier-plugin-svelte" && plugin.parsers && plugin.parsers.pug)) ? content.trim() !== "" ? yield formatBodyContent(content) : content === "" ? "" : hardline$1 : preformattedBody(content);
|
|
1755
1811
|
let result = group$1([
|
|
1756
1812
|
group$1([
|
|
1757
1813
|
"<",
|
|
@@ -1797,7 +1853,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1797
1853
|
if (!comments || comments.length === 0) return;
|
|
1798
1854
|
const commentsByStart = /* @__PURE__ */ new Map();
|
|
1799
1855
|
for (const c of comments) commentsByStart.set(c.start, c);
|
|
1800
|
-
walkAndAttach(ast.
|
|
1856
|
+
walkAndAttach(ast.fragment, commentsByStart, original_text);
|
|
1801
1857
|
}
|
|
1802
1858
|
function walkAndAttach(node, commentsByStart, original_text) {
|
|
1803
1859
|
if (!node || typeof node !== "object") return;
|
|
@@ -1809,13 +1865,17 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1809
1865
|
const opening_tag_end = original_text && typeof node.end === "number" ? original_text.indexOf(">", last_attr.end) : -1;
|
|
1810
1866
|
if (opening_tag_end >= 0 && opening_tag_end <= node.end) attachCommentsInRange(last_attr.end, opening_tag_end, last_attr, null, commentsByStart);
|
|
1811
1867
|
}
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1868
|
+
if (node.type === "IfBlock") {
|
|
1869
|
+
if (node.consequent) walkAndAttach(node.consequent, commentsByStart, original_text);
|
|
1870
|
+
if (node.alternate) walkAndAttach(node.alternate, commentsByStart, original_text);
|
|
1871
|
+
} else if (node.type === "EachBlock") {
|
|
1872
|
+
if (node.body) walkAndAttach(node.body, commentsByStart, original_text);
|
|
1873
|
+
if (node.fallback) walkAndAttach(node.fallback, commentsByStart, original_text);
|
|
1874
|
+
} else if (node.type === "AwaitBlock") {
|
|
1815
1875
|
if (node.pending) walkAndAttach(node.pending, commentsByStart, original_text);
|
|
1816
1876
|
if (node.then) walkAndAttach(node.then, commentsByStart, original_text);
|
|
1817
1877
|
if (node.catch) walkAndAttach(node.catch, commentsByStart, original_text);
|
|
1818
|
-
}
|
|
1878
|
+
} else for (const child of getChildren(node)) walkAndAttach(child, commentsByStart, original_text);
|
|
1819
1879
|
}
|
|
1820
1880
|
function attachCommentsInRange(rangeStart, rangeEnd, precedingAttr, followingAttr, commentsByStart) {
|
|
1821
1881
|
for (const [start, comment] of commentsByStart) if (start >= rangeStart && comment.end <= rangeEnd) {
|
|
@@ -1826,7 +1886,6 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1826
1886
|
}
|
|
1827
1887
|
const babelParser = prettierPluginBabel.parsers.babel;
|
|
1828
1888
|
const typescriptParser = prettierPluginBabel.parsers["babel-ts"];
|
|
1829
|
-
const isSvelte5Plus = Number(compiler.VERSION.split(".")[0]) >= 5;
|
|
1830
1889
|
function locStart(node) {
|
|
1831
1890
|
return node.start;
|
|
1832
1891
|
}
|
|
@@ -1854,8 +1913,10 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1854
1913
|
console.warn(e);
|
|
1855
1914
|
options.svelte5CompilerPath = void 0;
|
|
1856
1915
|
}
|
|
1857
|
-
const root = _parse(text);
|
|
1916
|
+
const root = _parse(text, { modern: true });
|
|
1858
1917
|
root.__isRoot = true;
|
|
1918
|
+
root._comments = root.comments;
|
|
1919
|
+
delete root.comments;
|
|
1859
1920
|
return root;
|
|
1860
1921
|
} catch (err) {
|
|
1861
1922
|
if (err.start != null && err.end != null) err.loc = {
|
|
@@ -1869,9 +1930,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1869
1930
|
const result = snipScriptAndStyleTagContent(text);
|
|
1870
1931
|
text = result.text.trim();
|
|
1871
1932
|
options.originalText = text;
|
|
1872
|
-
|
|
1873
|
-
options._svelte_ts = is && result.isTypescript;
|
|
1874
|
-
options._svelte_is5Plus = is;
|
|
1933
|
+
options._svelte_ts = result.isTypescript;
|
|
1875
1934
|
return text;
|
|
1876
1935
|
},
|
|
1877
1936
|
locStart,
|