@decimalturn/toml-patch 3.2.0-lite → 3.2.1-dev

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 (81) hide show
  1. package/dist/dev/comment-alignment.js +372 -0
  2. package/dist/dev/comment-alignment.js.map +1 -0
  3. package/dist/dev/comment-ownership.js +660 -0
  4. package/dist/dev/comment-ownership.js.map +1 -0
  5. package/dist/dev/cst-source.js +118 -0
  6. package/dist/dev/cst-source.js.map +1 -0
  7. package/dist/dev/cst.js +68 -0
  8. package/dist/dev/cst.js.map +1 -0
  9. package/dist/dev/cursor.js +66 -0
  10. package/dist/dev/cursor.js.map +1 -0
  11. package/dist/dev/date-format.js +196 -0
  12. package/dist/dev/date-format.js.map +1 -0
  13. package/dist/dev/decode-utf8.js +27 -0
  14. package/dist/dev/decode-utf8.js.map +1 -0
  15. package/dist/dev/diff-lite.js +123 -0
  16. package/dist/dev/diff-lite.js.map +1 -0
  17. package/dist/dev/diff.js +265 -0
  18. package/dist/dev/diff.js.map +1 -0
  19. package/dist/dev/encode-lite.js +193 -0
  20. package/dist/dev/encode-lite.js.map +1 -0
  21. package/dist/dev/escape-preference.js +166 -0
  22. package/dist/dev/escape-preference.js.map +1 -0
  23. package/dist/dev/find-by-path.js +111 -0
  24. package/dist/dev/find-by-path.js.map +1 -0
  25. package/dist/dev/formatter.js +298 -0
  26. package/dist/dev/formatter.js.map +1 -0
  27. package/dist/dev/generate.js +465 -0
  28. package/dist/dev/generate.js.map +1 -0
  29. package/dist/dev/inline-comma-space.js +13 -0
  30. package/dist/dev/inline-comma-space.js.map +1 -0
  31. package/dist/dev/inline-format.js +106 -0
  32. package/dist/dev/inline-format.js.map +1 -0
  33. package/dist/dev/inline-layout.js +107 -0
  34. package/dist/dev/inline-layout.js.map +1 -0
  35. package/dist/dev/line-ending-backslash.js +320 -0
  36. package/dist/dev/line-ending-backslash.js.map +1 -0
  37. package/dist/dev/literal-string.js +46 -0
  38. package/dist/dev/literal-string.js.map +1 -0
  39. package/dist/dev/location.js +104 -0
  40. package/dist/dev/location.js.map +1 -0
  41. package/dist/dev/parse-error.js +27 -0
  42. package/dist/dev/parse-error.js.map +1 -0
  43. package/dist/dev/parse-js.js +150 -0
  44. package/dist/dev/parse-js.js.map +1 -0
  45. package/dist/dev/parse-string.js +122 -0
  46. package/dist/dev/parse-string.js.map +1 -0
  47. package/dist/dev/parse-toml.js +714 -0
  48. package/dist/dev/parse-toml.js.map +1 -0
  49. package/dist/dev/patch-lite.js +4 -0
  50. package/dist/dev/patch-lite2.js +96 -0
  51. package/dist/dev/patch-lite2.js.map +1 -0
  52. package/dist/dev/patch.js +2652 -0
  53. package/dist/dev/patch.js.map +1 -0
  54. package/dist/dev/smol-toml-date.js +61 -0
  55. package/dist/dev/smol-toml-date.js.map +1 -0
  56. package/dist/dev/to-js.js +303 -0
  57. package/dist/dev/to-js.js.map +1 -0
  58. package/dist/dev/to-toml.js +874 -0
  59. package/dist/dev/to-toml.js.map +1 -0
  60. package/dist/dev/tokenizer.js +225 -0
  61. package/dist/dev/tokenizer.js.map +1 -0
  62. package/dist/dev/toml-document.js +220 -0
  63. package/dist/dev/toml-document.js.map +1 -0
  64. package/dist/dev/toml-format.js +528 -0
  65. package/dist/dev/toml-format.js.map +1 -0
  66. package/dist/dev/toml-patch.js +94 -0
  67. package/dist/dev/toml-patch.js.map +1 -0
  68. package/dist/dev/traverse.js +61 -0
  69. package/dist/dev/traverse.js.map +1 -0
  70. package/dist/dev/truncate.js +64 -0
  71. package/dist/dev/truncate.js.map +1 -0
  72. package/dist/dev/update-order.js +235 -0
  73. package/dist/dev/update-order.js.map +1 -0
  74. package/dist/dev/utils.js +244 -0
  75. package/dist/dev/utils.js.map +1 -0
  76. package/dist/dev/writer.js +758 -0
  77. package/dist/dev/writer.js.map +1 -0
  78. package/dist/toml-patch.d.ts +547 -0
  79. package/package.json +11 -6
  80. package/dist/patch.js +0 -20
  81. /package/dist/{patch.d.ts → patch-lite.d.ts} +0 -0
@@ -0,0 +1,106 @@
1
+ //! @decimalturn/toml-patch v3.2.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
+ import { hasItems, isInlineArray, isInlineItem, isInlineTable, isKeyValue } from "./cst.js";
3
+
4
+ //#region src/inline-format.ts
5
+ const multilineDecisions = /* @__PURE__ */ new WeakMap();
6
+ const positionedContainers = /* @__PURE__ */ new WeakSet();
7
+ const generatedNestedTables = /* @__PURE__ */ new WeakSet();
8
+ const generatedNestedTableHosts = /* @__PURE__ */ new WeakSet();
9
+ const preservedMultilineEmptyContainers = /* @__PURE__ */ new WeakSet();
10
+ function resolveInlineContainerLayout(kind, depth, parentIsMultiline, format) {
11
+ const mode = kind === "array" ? format.multilineArray : format.multilineTable;
12
+ if (typeof mode === "boolean") return mode;
13
+ if (typeof mode === "number") return depth >= mode;
14
+ if (mode === "parent") return parentIsMultiline;
15
+ return false;
16
+ }
17
+ function setInlineContainerLayout(container, multiline) {
18
+ multilineDecisions.set(container, multiline);
19
+ if (multiline && container.items.length === 0) {
20
+ container.loc.end.line = container.loc.start.line + 1;
21
+ container.loc.end.column = container.loc.start.column + 1;
22
+ }
23
+ }
24
+ function getInlineContainerLayout(container) {
25
+ return multilineDecisions.get(container);
26
+ }
27
+ function markInlineContainerPositioned(container) {
28
+ positionedContainers.add(container);
29
+ }
30
+ function isInlineContainerPositioned(container) {
31
+ return positionedContainers.has(container);
32
+ }
33
+ function markGeneratedNestedTable(table) {
34
+ generatedNestedTables.add(table);
35
+ }
36
+ function isGeneratedNestedTable(table) {
37
+ return generatedNestedTables.has(table);
38
+ }
39
+ function markGeneratedNestedTableHost(array) {
40
+ generatedNestedTableHosts.add(array);
41
+ }
42
+ function isGeneratedNestedTableHost(array) {
43
+ return generatedNestedTableHosts.has(array);
44
+ }
45
+ /**
46
+ * Records that `container` held its only item on an interior row and that row
47
+ * was removed. The opening and closing delimiters stay on separate rows so the
48
+ * source layout survives the removal, mirroring the behavior already used for
49
+ * block-level containers. Nested containers are otherwise tightened to a single
50
+ * line because their closing bracket has no source row of its own to keep.
51
+ */
52
+ function markPreservedMultilineEmpty(container) {
53
+ preservedMultilineEmptyContainers.add(container);
54
+ }
55
+ function isPreservedMultilineEmpty(container) {
56
+ return preservedMultilineEmptyContainers.has(container);
57
+ }
58
+ function hasStructuralMultilineRows(container) {
59
+ if (!container.items.length) return container.loc.end.line > container.loc.start.line;
60
+ return container.items.some((item, index) => {
61
+ const previous = container.items[index - 1];
62
+ return item.loc.start.line > ((previous === null || previous === void 0 ? void 0 : previous.loc.end.line) ?? container.loc.start.line);
63
+ });
64
+ }
65
+ function findInlineContainerDepth(root, target) {
66
+ const visit = (node, depth) => {
67
+ if (node === target) return depth;
68
+ if (isKeyValue(node)) return visit(node.value, depth);
69
+ if (isInlineItem(node)) return visit(node.item, depth);
70
+ if (isInlineArray(node) || isInlineTable(node)) {
71
+ for (const item of node.items) {
72
+ const result = visit(item, depth + 1);
73
+ if (result !== void 0) return result;
74
+ }
75
+ return;
76
+ }
77
+ if (hasItems(node)) for (const item of node.items) {
78
+ const result = visit(item, depth);
79
+ if (result !== void 0) return result;
80
+ }
81
+ };
82
+ return visit(root, 0);
83
+ }
84
+ function findInlineContainerParent(root, target) {
85
+ const visit = (node, parent) => {
86
+ if (node === target) return parent;
87
+ if (isKeyValue(node)) return visit(node.value, parent);
88
+ if (isInlineItem(node)) return visit(node.item, parent);
89
+ if (isInlineArray(node) || isInlineTable(node)) {
90
+ for (const item of node.items) {
91
+ const result = visit(item, node);
92
+ if (result) return result;
93
+ }
94
+ return;
95
+ }
96
+ if (hasItems(node)) for (const item of node.items) {
97
+ const result = visit(item, parent);
98
+ if (result) return result;
99
+ }
100
+ };
101
+ return visit(root, void 0);
102
+ }
103
+
104
+ //#endregion
105
+ export { findInlineContainerDepth, findInlineContainerParent, getInlineContainerLayout, hasStructuralMultilineRows, isGeneratedNestedTable, isGeneratedNestedTableHost, isInlineContainerPositioned, isPreservedMultilineEmpty, markGeneratedNestedTable, markGeneratedNestedTableHost, markInlineContainerPositioned, markPreservedMultilineEmpty, resolveInlineContainerLayout, setInlineContainerLayout };
106
+ //# sourceMappingURL=inline-format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-format.js","names":[],"sources":["../../src/inline-format.ts"],"sourcesContent":["import {\n InlineArray,\n InlineTable,\n TreeNode,\n hasItems,\n isInlineArray,\n isInlineItem,\n isInlineTable,\n isKeyValue\n} from './cst';\nimport type { TomlFormat } from './toml-format';\n\nexport type InlineContainerKind = 'array' | 'table';\n\nconst multilineDecisions = new WeakMap<InlineArray | InlineTable, boolean>();\nconst positionedContainers = new WeakSet<InlineArray | InlineTable>();\nconst generatedNestedTables = new WeakSet<InlineTable>();\nconst generatedNestedTableHosts = new WeakSet<InlineArray>();\nconst preservedMultilineEmptyContainers = new WeakSet<InlineArray | InlineTable>();\n\nexport function resolveInlineContainerLayout(\n kind: InlineContainerKind,\n depth: number,\n parentIsMultiline: boolean,\n format: TomlFormat\n): boolean {\n const mode = kind === 'array' ? format.multilineArray : format.multilineTable;\n if (typeof mode === 'boolean') return mode;\n if (typeof mode === 'number') return depth >= mode;\n if (mode === 'parent') return parentIsMultiline;\n return false;\n}\n\nexport function setInlineContainerLayout(\n container: InlineArray | InlineTable,\n multiline: boolean\n): void {\n multilineDecisions.set(container, multiline);\n if (multiline && container.items.length === 0) {\n container.loc.end.line = container.loc.start.line + 1;\n container.loc.end.column = container.loc.start.column + 1;\n }\n}\n\nexport function getInlineContainerLayout(\n container: InlineArray | InlineTable\n): boolean | undefined {\n return multilineDecisions.get(container);\n}\n\nexport function markInlineContainerPositioned(container: InlineArray | InlineTable): void {\n positionedContainers.add(container);\n}\n\nexport function isInlineContainerPositioned(container: InlineArray | InlineTable): boolean {\n return positionedContainers.has(container);\n}\n\nexport function markGeneratedNestedTable(table: InlineTable): void {\n generatedNestedTables.add(table);\n}\n\nexport function isGeneratedNestedTable(table: InlineTable): boolean {\n return generatedNestedTables.has(table);\n}\n\nexport function markGeneratedNestedTableHost(array: InlineArray): void {\n generatedNestedTableHosts.add(array);\n}\n\nexport function isGeneratedNestedTableHost(array: InlineArray): boolean {\n return generatedNestedTableHosts.has(array);\n}\n\n/**\n * Records that `container` held its only item on an interior row and that row\n * was removed. The opening and closing delimiters stay on separate rows so the\n * source layout survives the removal, mirroring the behavior already used for\n * block-level containers. Nested containers are otherwise tightened to a single\n * line because their closing bracket has no source row of its own to keep.\n */\nexport function markPreservedMultilineEmpty(container: InlineArray | InlineTable): void {\n preservedMultilineEmptyContainers.add(container);\n}\n\nexport function isPreservedMultilineEmpty(container: InlineArray | InlineTable): boolean {\n return preservedMultilineEmptyContainers.has(container);\n}\n\nexport function hasStructuralMultilineRows(container: InlineArray | InlineTable): boolean {\n if (!container.items.length) return container.loc.end.line > container.loc.start.line;\n return container.items.some((item, index) => {\n const previous = container.items[index - 1];\n return item.loc.start.line > (previous?.loc.end.line ?? container.loc.start.line);\n });\n}\n\nexport function findInlineContainerDepth(root: TreeNode, target: InlineArray | InlineTable): number | undefined {\n const visit = (node: TreeNode, depth: number): number | undefined => {\n if (node === target) return depth;\n if (isKeyValue(node)) return visit(node.value, depth);\n if (isInlineItem(node)) return visit(node.item, depth);\n if (isInlineArray(node) || isInlineTable(node)) {\n for (const item of node.items) {\n const result = visit(item, depth + 1);\n if (result !== undefined) return result;\n }\n return undefined;\n }\n if (hasItems(node)) {\n for (const item of node.items) {\n const result = visit(item, depth);\n if (result !== undefined) return result;\n }\n }\n return undefined;\n };\n\n return visit(root, 0);\n}\n\nexport function findInlineContainerParent(\n root: TreeNode,\n target: TreeNode\n): InlineArray | InlineTable | undefined {\n const visit = (\n node: TreeNode,\n parent: InlineArray | InlineTable | undefined\n ): InlineArray | InlineTable | undefined => {\n if (node === target) return parent;\n if (isKeyValue(node)) return visit(node.value, parent);\n if (isInlineItem(node)) return visit(node.item, parent);\n if (isInlineArray(node) || isInlineTable(node)) {\n for (const item of node.items) {\n const result = visit(item, node);\n if (result) return result;\n }\n return undefined;\n }\n if (hasItems(node)) {\n for (const item of node.items) {\n const result = visit(item, parent);\n if (result) return result;\n }\n }\n return undefined;\n };\n\n return visit(root, undefined);\n}"],"mappings":";;;;AAcA,MAAM,qCAAqB,IAAI,QAA4C;AAC3E,MAAM,uCAAuB,IAAI,QAAmC;AACpE,MAAM,wCAAwB,IAAI,QAAqB;AACvD,MAAM,4CAA4B,IAAI,QAAqB;AAC3D,MAAM,oDAAoC,IAAI,QAAmC;AAEjF,SAAgB,6BACd,MACA,OACA,mBACA,QACS;CACT,MAAM,OAAO,SAAS,UAAU,OAAO,iBAAiB,OAAO;CAC/D,IAAI,OAAO,SAAS,WAAW,OAAO;CACtC,IAAI,OAAO,SAAS,UAAU,OAAO,SAAS;CAC9C,IAAI,SAAS,UAAU,OAAO;CAC9B,OAAO;AACT;AAEA,SAAgB,yBACd,WACA,WACM;CACN,mBAAmB,IAAI,WAAW,SAAS;CAC3C,IAAI,aAAa,UAAU,MAAM,WAAW,GAAG;EAC7C,UAAU,IAAI,IAAI,OAAO,UAAU,IAAI,MAAM,OAAO;EACpD,UAAU,IAAI,IAAI,SAAS,UAAU,IAAI,MAAM,SAAS;CAC1D;AACF;AAEA,SAAgB,yBACd,WACqB;CACrB,OAAO,mBAAmB,IAAI,SAAS;AACzC;AAEA,SAAgB,8BAA8B,WAA4C;CACxF,qBAAqB,IAAI,SAAS;AACpC;AAEA,SAAgB,4BAA4B,WAA+C;CACzF,OAAO,qBAAqB,IAAI,SAAS;AAC3C;AAEA,SAAgB,yBAAyB,OAA0B;CACjE,sBAAsB,IAAI,KAAK;AACjC;AAEA,SAAgB,uBAAuB,OAA6B;CAClE,OAAO,sBAAsB,IAAI,KAAK;AACxC;AAEA,SAAgB,6BAA6B,OAA0B;CACrE,0BAA0B,IAAI,KAAK;AACrC;AAEA,SAAgB,2BAA2B,OAA6B;CACtE,OAAO,0BAA0B,IAAI,KAAK;AAC5C;;;;;;;;AASA,SAAgB,4BAA4B,WAA4C;CACtF,kCAAkC,IAAI,SAAS;AACjD;AAEA,SAAgB,0BAA0B,WAA+C;CACvF,OAAO,kCAAkC,IAAI,SAAS;AACxD;AAEA,SAAgB,2BAA2B,WAA+C;CACxF,IAAI,CAAC,UAAU,MAAM,QAAQ,OAAO,UAAU,IAAI,IAAI,OAAO,UAAU,IAAI,MAAM;CACjF,OAAO,UAAU,MAAM,MAAM,MAAM,UAAU;EAC3C,MAAM,WAAW,UAAU,MAAM,QAAQ;EACzC,OAAO,KAAK,IAAI,MAAM,6DAAQ,SAAU,IAAI,IAAI,SAAQ,UAAU,IAAI,MAAM;CAC9E,CAAC;AACH;AAEA,SAAgB,yBAAyB,MAAgB,QAAuD;CAC9G,MAAM,SAAS,MAAgB,UAAsC;EACnE,IAAI,SAAS,QAAQ,OAAO;EAC5B,IAAI,WAAW,IAAI,GAAG,OAAO,MAAM,KAAK,OAAO,KAAK;EACpD,IAAI,aAAa,IAAI,GAAG,OAAO,MAAM,KAAK,MAAM,KAAK;EACrD,IAAI,cAAc,IAAI,KAAK,cAAc,IAAI,GAAG;GAC9C,KAAK,MAAM,QAAQ,KAAK,OAAO;IAC7B,MAAM,SAAS,MAAM,MAAM,QAAQ,CAAC;IACpC,IAAI,WAAW,QAAW,OAAO;GACnC;GACA;EACF;EACA,IAAI,SAAS,IAAI,GACf,KAAK,MAAM,QAAQ,KAAK,OAAO;GAC7B,MAAM,SAAS,MAAM,MAAM,KAAK;GAChC,IAAI,WAAW,QAAW,OAAO;EACnC;CAGJ;CAEA,OAAO,MAAM,MAAM,CAAC;AACtB;AAEA,SAAgB,0BACd,MACA,QACuC;CACvC,MAAM,SACJ,MACA,WAC0C;EAC1C,IAAI,SAAS,QAAQ,OAAO;EAC5B,IAAI,WAAW,IAAI,GAAG,OAAO,MAAM,KAAK,OAAO,MAAM;EACrD,IAAI,aAAa,IAAI,GAAG,OAAO,MAAM,KAAK,MAAM,MAAM;EACtD,IAAI,cAAc,IAAI,KAAK,cAAc,IAAI,GAAG;GAC9C,KAAK,MAAM,QAAQ,KAAK,OAAO;IAC7B,MAAM,SAAS,MAAM,MAAM,IAAI;IAC/B,IAAI,QAAQ,OAAO;GACrB;GACA;EACF;EACA,IAAI,SAAS,IAAI,GACf,KAAK,MAAM,QAAQ,KAAK,OAAO;GAC7B,MAAM,SAAS,MAAM,MAAM,MAAM;GACjC,IAAI,QAAQ,OAAO;EACrB;CAGJ;CAEA,OAAO,MAAM,MAAM,MAAS;AAC9B"}
@@ -0,0 +1,107 @@
1
+ //! @decimalturn/toml-patch v3.2.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
+ import { isInlineArray, isInlineItem, isInlineTable } from "./cst.js";
3
+ import { clonePosition } from "./location.js";
4
+ import { hasStructuralMultilineRows, markGeneratedNestedTable, markGeneratedNestedTableHost, markInlineContainerPositioned } from "./inline-format.js";
5
+ import { shiftNode } from "./writer.js";
6
+
7
+ //#region src/inline-layout.ts
8
+ function hasOneItemPerLine(container) {
9
+ return container.items.length > 0 && container.loc.end.line - container.loc.start.line + 1 > container.items.length;
10
+ }
11
+ function isInlineContainer(node) {
12
+ return isInlineArray(node) || isInlineTable(node);
13
+ }
14
+ function prepareInsertedNestedInlineContainer(parent, child, indentWidth) {
15
+ if (!isInlineItem(child) || !isInlineContainer(child.item) || !hasOneItemPerLine(parent)) return;
16
+ const template = parent.items.find((item) => isInlineContainer(item.item) && item.item.type === child.item.type && hasOneItemPerLine(item.item));
17
+ if (!template || !isInlineContainer(template.item)) return;
18
+ const childContainer = child.item;
19
+ const templateContainer = template.item;
20
+ const rowIndent = templateContainer.items.length > 0 ? templateContainer.items[0].loc.start.column - templateContainer.loc.start.column : indentWidth;
21
+ const firstRow = templateContainer.items.length > 0 ? templateContainer.items[0].loc.start.line - templateContainer.loc.start.line : 1;
22
+ const closingRows = templateContainer.items.length > 0 ? templateContainer.loc.end.line - templateContainer.items[templateContainer.items.length - 1].loc.end.line : 1;
23
+ const startLine = childContainer.loc.start.line;
24
+ const startColumn = childContainer.loc.start.column;
25
+ let nextLine = startLine + firstRow;
26
+ for (const item of childContainer.items) {
27
+ shiftNode(item, {
28
+ lines: nextLine - item.loc.start.line,
29
+ columns: startColumn + rowIndent - item.loc.start.column
30
+ });
31
+ nextLine = item.loc.end.line + 1;
32
+ }
33
+ childContainer.loc.end = {
34
+ line: nextLine - 1 + closingRows,
35
+ column: templateContainer.loc.end.column
36
+ };
37
+ markInlineContainerPositioned(childContainer);
38
+ child.loc = {
39
+ start: clonePosition(childContainer.loc.start),
40
+ end: clonePosition(childContainer.loc.end)
41
+ };
42
+ }
43
+ function positionGeneratedNestedInlineTables(container, indentWidth) {
44
+ const visit = (current) => {
45
+ let changed = false;
46
+ for (const item of current.items) {
47
+ if (!isInlineItem(item) || !isInlineContainer(item.item)) continue;
48
+ const child = item.item;
49
+ if (isInlineTable(child) && hasStructuralMultilineRows(child)) {
50
+ delete item.range;
51
+ delete child.range;
52
+ const rowColumn = child.loc.start.column + Math.max(indentWidth, 2);
53
+ for (const row of child.items) shiftNode(row, {
54
+ lines: 0,
55
+ columns: rowColumn - row.loc.start.column
56
+ });
57
+ child.loc.end.column = child.loc.start.column + 1;
58
+ markGeneratedNestedTable(child);
59
+ markInlineContainerPositioned(child);
60
+ changed = true;
61
+ markGeneratedNestedTableHost(current);
62
+ item.comma = true;
63
+ item.loc.end = {
64
+ line: child.loc.end.line,
65
+ column: child.loc.end.column
66
+ };
67
+ current.loc.end = {
68
+ line: child.loc.end.line,
69
+ column: child.loc.end.column + (item.comma ? 2 : 1)
70
+ };
71
+ }
72
+ if (isInlineArray(child) && visit(child)) {
73
+ delete child.range;
74
+ delete item.range;
75
+ item.loc.end = {
76
+ line: child.loc.end.line,
77
+ column: child.loc.end.column
78
+ };
79
+ changed = true;
80
+ markGeneratedNestedTableHost(current);
81
+ }
82
+ }
83
+ if (changed) {
84
+ for (let index = 1; index < current.items.length; index++) {
85
+ const previous = current.items[index - 1];
86
+ const next = current.items[index];
87
+ if (previous.loc.end.line !== next.loc.start.line) continue;
88
+ const targetColumn = previous.loc.end.column + (previous.comma ? 2 : 1);
89
+ shiftNode(next, {
90
+ lines: 0,
91
+ columns: targetColumn - next.loc.start.column
92
+ });
93
+ }
94
+ const last = current.items[current.items.length - 1];
95
+ if (last) current.loc.end = {
96
+ line: Math.max(current.loc.end.line, last.loc.end.line),
97
+ column: last.loc.end.column + (last.comma ? 2 : 1)
98
+ };
99
+ }
100
+ return changed;
101
+ };
102
+ visit(container);
103
+ }
104
+
105
+ //#endregion
106
+ export { positionGeneratedNestedInlineTables, prepareInsertedNestedInlineContainer };
107
+ //# sourceMappingURL=inline-layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-layout.js","names":[],"sources":["../../src/inline-layout.ts"],"sourcesContent":["import {\n InlineArray,\n InlineTable,\n InlineItem,\n TreeNode,\n isInlineArray,\n isInlineTable,\n isInlineItem\n} from './cst';\nimport { clonePosition } from './location';\nimport { shiftNode } from './writer';\nimport { hasStructuralMultilineRows, markGeneratedNestedTable, markGeneratedNestedTableHost, markInlineContainerPositioned } from './inline-format';\n\nfunction hasOneItemPerLine(container: InlineArray | InlineTable): boolean {\n return container.items.length > 0\n && container.loc.end.line - container.loc.start.line + 1 > container.items.length;\n}\n\nfunction isInlineContainer(node: TreeNode): node is InlineArray | InlineTable {\n return isInlineArray(node) || isInlineTable(node);\n}\n\nexport function prepareInsertedNestedInlineContainer(\n parent: InlineArray | InlineTable,\n child: TreeNode,\n indentWidth: number\n): void {\n if (!isInlineItem(child) || !isInlineContainer(child.item) || !hasOneItemPerLine(parent)) return;\n\n const template = (parent.items as InlineItem[]).find(item =>\n isInlineContainer(item.item)\n && item.item.type === child.item.type\n && hasOneItemPerLine(item.item)\n );\n if (!template || !isInlineContainer(template.item)) return;\n\n const childContainer = child.item;\n const templateContainer = template.item;\n const rowIndent = templateContainer.items.length > 0\n ? templateContainer.items[0].loc.start.column - templateContainer.loc.start.column\n : indentWidth;\n const firstRow = templateContainer.items.length > 0\n ? templateContainer.items[0].loc.start.line - templateContainer.loc.start.line\n : 1;\n const closingRows = templateContainer.items.length > 0\n ? templateContainer.loc.end.line - templateContainer.items[templateContainer.items.length - 1].loc.end.line\n : 1;\n const startLine = childContainer.loc.start.line;\n const startColumn = childContainer.loc.start.column;\n\n let nextLine = startLine + firstRow;\n for (const item of childContainer.items) {\n shiftNode(item, {\n lines: nextLine - item.loc.start.line,\n columns: startColumn + rowIndent - item.loc.start.column\n });\n nextLine = item.loc.end.line + 1;\n }\n\n childContainer.loc.end = {\n line: nextLine - 1 + closingRows,\n column: templateContainer.loc.end.column\n };\n markInlineContainerPositioned(childContainer);\n child.loc = { start: clonePosition(childContainer.loc.start), end: clonePosition(childContainer.loc.end) };\n}\n\nexport function positionGeneratedNestedInlineTables(\n container: InlineArray,\n indentWidth: number\n): void {\n const visit = (current: InlineArray): boolean => {\n let changed = false;\n for (const item of current.items) {\n if (!isInlineItem(item) || !isInlineContainer(item.item)) continue;\n\n const child = item.item;\n if (isInlineTable(child) && hasStructuralMultilineRows(child)) {\n delete (item as { range?: [number, number] }).range;\n delete (child as { range?: [number, number] }).range;\n const rowColumn = child.loc.start.column + Math.max(indentWidth, 2);\n for (const row of child.items) {\n shiftNode(row, { lines: 0, columns: rowColumn - row.loc.start.column });\n }\n child.loc.end.column = child.loc.start.column + 1;\n markGeneratedNestedTable(child);\n markInlineContainerPositioned(child);\n changed = true;\n markGeneratedNestedTableHost(current);\n\n item.comma = true;\n item.loc.end = {\n line: child.loc.end.line,\n column: child.loc.end.column\n };\n current.loc.end = {\n line: child.loc.end.line,\n column: child.loc.end.column + (item.comma ? 2 : 1)\n };\n }\n\n if (isInlineArray(child) && visit(child)) {\n delete (child as { range?: [number, number] }).range;\n delete (item as { range?: [number, number] }).range;\n item.loc.end = {\n line: child.loc.end.line,\n column: child.loc.end.column\n };\n changed = true;\n markGeneratedNestedTableHost(current);\n }\n }\n if (changed) {\n for (let index = 1; index < current.items.length; index++) {\n const previous = current.items[index - 1];\n const next = current.items[index];\n if (previous.loc.end.line !== next.loc.start.line) continue;\n const targetColumn = previous.loc.end.column + (previous.comma ? 2 : 1);\n shiftNode(next, { lines: 0, columns: targetColumn - next.loc.start.column });\n }\n const last = current.items[current.items.length - 1];\n if (last) {\n current.loc.end = {\n line: Math.max(current.loc.end.line, last.loc.end.line),\n column: last.loc.end.column + (last.comma ? 2 : 1)\n };\n }\n }\n return changed;\n };\n\n visit(container);\n}"],"mappings":"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"}
@@ -0,0 +1,320 @@
1
+ //! @decimalturn/toml-patch v3.2.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
+ //#region src/line-ending-backslash.ts
3
+ function detectFirstStructuralNewline(value) {
4
+ const match = value.match(/\r\n|\n/);
5
+ return (match === null || match === void 0 ? void 0 : match[0]) === "\r\n" ? "\r\n" : "\n";
6
+ }
7
+ /**
8
+ * Rebuilds a basic multiline string (`"""`) that uses line ending backslash
9
+ * (line-continuation) formatting.
10
+ *
11
+ * Handles all three opening formats:
12
+ * - `"""\<NL>content\<NL>indent"""` (leading line-continuation)
13
+ * - `"""<NL>content\<NL>..."""` (leading newline)
14
+ * - `"""content\<NL>..."""` (no leading newline)
15
+ *
16
+ * Strategy:
17
+ * 1. Detect the opening format and where the body starts.
18
+ * 2. Parse body lines into segments (indent, content, trailing whitespace,
19
+ * backslash flag), preserving blank lines.
20
+ * 3. Measure the max content length from content lines.
21
+ * 4. Detect "blank-line paragraph style": if the original uses blank lines to
22
+ * separate paragraphs (non-backslash content line followed by a blank line),
23
+ * split the new value on double-newlines and pack each paragraph separately,
24
+ * rejoined by blank lines.
25
+ * 5. Otherwise, encode newlines as `\n` escape sequences and pack as a single group.
26
+ * 6. Reassemble with the original opening format, per-line whitespace and
27
+ * backslash placement.
28
+ *
29
+ * @param existingRaw - The full raw TOML string including delimiters (`"""`).
30
+ * @param escaped - The new value already escaped for a basic multiline string
31
+ * (backslashes doubled, control characters replaced with escape sequences).
32
+ * May contain real newline characters; this function handles their encoding.
33
+ * @param newlineChar - The newline character to use (`'\n'` or `'\r\n'`).
34
+ * @returns The reconstructed raw TOML string, or `null` if the value cannot be
35
+ * represented in line-continuation format (e.g. values with leading spaces or
36
+ * a trailing space count that doesn't match the original layout).
37
+ */
38
+ function rebuildLineContinuation(existingRaw, escaped) {
39
+ var _escaped$match;
40
+ const newlineChar = detectFirstStructuralNewline(existingRaw);
41
+ existingRaw = existingRaw.replace(/\r\n/g, "\n").replace(/\n/g, newlineChar);
42
+ const delimiter = "\"\"\"";
43
+ let bodyStart;
44
+ let openingPrefix;
45
+ if (existingRaw.startsWith(`${delimiter}\\${newlineChar}`)) {
46
+ bodyStart = 4 + newlineChar.length;
47
+ openingPrefix = `${delimiter}\\${newlineChar}`;
48
+ } else if (existingRaw.startsWith(`${delimiter}${newlineChar}`)) {
49
+ bodyStart = 3 + newlineChar.length;
50
+ openingPrefix = `${delimiter}${newlineChar}`;
51
+ } else {
52
+ bodyStart = 3;
53
+ openingPrefix = delimiter;
54
+ }
55
+ const bodyEnd = existingRaw.length - 3;
56
+ const rawLines = existingRaw.slice(bodyStart, bodyEnd).split(newlineChar);
57
+ const lastLine = rawLines[rawLines.length - 1];
58
+ const hasClosingIndent = rawLines.length > 1 && /^[\t ]*$/.test(lastLine);
59
+ const closingIndent = hasClosingIndent ? lastLine : "";
60
+ const segments = (hasClosingIndent ? rawLines.slice(0, -1) : rawLines).map((line) => {
61
+ var _stripped$match;
62
+ if (/^[\t ]*$/.test(line)) return {
63
+ indent: line,
64
+ content: "",
65
+ trailingWs: "",
66
+ hasBackslash: false,
67
+ isBlank: true
68
+ };
69
+ let stripped = line;
70
+ let backslashCount = 0;
71
+ for (let i = stripped.length - 1; i >= 0 && stripped[i] === "\\"; i--) backslashCount++;
72
+ const hasBackslash = backslashCount % 2 === 1;
73
+ if (hasBackslash) stripped = stripped.slice(0, -1);
74
+ const indent = ((_stripped$match = stripped.match(/^[\t ]*/)) === null || _stripped$match === void 0 ? void 0 : _stripped$match[0]) ?? "";
75
+ const afterIndent = stripped.slice(indent.length);
76
+ const trailingMatch = afterIndent.match(/([\t ]+)$/);
77
+ const trailingWs = trailingMatch ? trailingMatch[1] : "";
78
+ return {
79
+ indent,
80
+ content: afterIndent.slice(0, afterIndent.length - trailingWs.length),
81
+ trailingWs,
82
+ hasBackslash,
83
+ isBlank: false
84
+ };
85
+ });
86
+ const contentSegments = segments.filter((s) => !s.isBlank);
87
+ const maxLength = Math.max(...contentSegments.map((s) => s.content.length + s.trailingWs.length), 1);
88
+ const continuationSegs = contentSegments.filter((s) => s.hasBackslash);
89
+ const contProto = continuationSegs[continuationSegs.length - 1] ?? contentSegments[contentSegments.length - 1] ?? {
90
+ indent: "",
91
+ trailingWs: "",
92
+ hasBackslash: false,
93
+ content: "",
94
+ isBlank: false
95
+ };
96
+ const tailProto = contentSegments[contentSegments.length - 1] ?? contProto;
97
+ const blankGroups = [];
98
+ {
99
+ let blanks = [];
100
+ let ci = 0;
101
+ for (const seg of segments) if (seg.isBlank) blanks.push(seg.indent);
102
+ else {
103
+ if (ci > 0) blankGroups.push(blanks);
104
+ blanks = [];
105
+ ci++;
106
+ }
107
+ }
108
+ const hasLiteralLineBreakStyle = contentSegments.some((seg, i) => !seg.hasBackslash && i < contentSegments.length - 1);
109
+ const isLeadingNewlineOpening = openingPrefix === `${delimiter}${newlineChar}`;
110
+ const newFirstIndent = isLeadingNewlineOpening && contentSegments.length > 0 ? ((_escaped$match = escaped.match(/^[\t ]*/)) === null || _escaped$match === void 0 ? void 0 : _escaped$match[0]) ?? "" : "";
111
+ const packContent = (input) => {
112
+ const tokens = input.match(/\S+| +/g) ?? [];
113
+ const lines = [];
114
+ let ti = 0;
115
+ while (ti < tokens.length) {
116
+ let line = tokens[ti++];
117
+ while (ti < tokens.length && tokens[ti][0] === " ") {
118
+ const spaceTok = tokens[ti];
119
+ const nextWord = tokens[ti + 1];
120
+ if (!nextWord) {
121
+ ti++;
122
+ break;
123
+ }
124
+ if (line.length + spaceTok.length + nextWord.length <= maxLength) {
125
+ line += spaceTok + nextWord;
126
+ ti += 2;
127
+ } else {
128
+ line += spaceTok;
129
+ ti++;
130
+ break;
131
+ }
132
+ }
133
+ lines.push(line);
134
+ }
135
+ if (lines.length === 0) lines.push("");
136
+ return lines;
137
+ };
138
+ const newContentLines = [];
139
+ const rebuiltLines = [];
140
+ const paraEndIndices = /* @__PURE__ */ new Set();
141
+ const logicalLineStartIndices = /* @__PURE__ */ new Set();
142
+ const logicalLineStartIndentByIndex = /* @__PURE__ */ new Map();
143
+ let isLiteralLineBreakPath = false;
144
+ if (hasLiteralLineBreakStyle && escaped.includes(newlineChar) && (newlineChar === "\r\n" || !escaped.includes("\r\n"))) {
145
+ isLiteralLineBreakPath = true;
146
+ const logicalLines = escaped.split(newlineChar);
147
+ const firstLineInput = logicalLines[0].slice(newFirstIndent.length);
148
+ if (firstLineInput.length > 0 && firstLineInput[0] === " ") return null;
149
+ const lastLineInput = logicalLines[logicalLines.length - 1];
150
+ if (lastLineInput.length > 0) {
151
+ if (lastLineInput.length - lastLineInput.trimEnd().length !== tailProto.trailingWs.length) return null;
152
+ }
153
+ for (let li = 0; li < logicalLines.length; li++) {
154
+ var _adjusted$match;
155
+ const rawLine = logicalLines[li];
156
+ const adjusted = li === 0 ? rawLine.slice(newFirstIndent.length) : rawLine;
157
+ const logicalLineIndent = ((_adjusted$match = adjusted.match(/^[\t ]*/)) === null || _adjusted$match === void 0 ? void 0 : _adjusted$match[0]) ?? "";
158
+ const packedLines = packContent(adjusted.slice(logicalLineIndent.length));
159
+ const startIdx = newContentLines.length;
160
+ logicalLineStartIndices.add(startIdx);
161
+ if (li > 0) logicalLineStartIndentByIndex.set(startIdx, logicalLineIndent);
162
+ for (const l of packedLines) newContentLines.push(l);
163
+ if (li < logicalLines.length - 1) paraEndIndices.add(startIdx + packedLines.length - 1);
164
+ }
165
+ } else {
166
+ const packInput = escaped.replace(/\r\n/g, "\\r\\n").replace(/\n/g, "\\n").slice(newFirstIndent.length);
167
+ if (packInput.length > 0) {
168
+ if (packInput[0] === " ") return null;
169
+ if (packInput.length - packInput.trimEnd().length !== tailProto.trailingWs.length) return null;
170
+ }
171
+ if (!hasLiteralLineBreakStyle) {
172
+ let preservedCount = 0;
173
+ let consumedChars = 0;
174
+ for (let k = 0; k < contentSegments.length - 1; k++) {
175
+ const seg = contentSegments[k];
176
+ if (!seg.hasBackslash) break;
177
+ const contrib = seg.content + seg.trailingWs;
178
+ if (packInput.slice(consumedChars, consumedChars + contrib.length) === contrib) {
179
+ preservedCount++;
180
+ consumedChars += contrib.length;
181
+ } else break;
182
+ }
183
+ let suffixCount = 0;
184
+ let suffixChars = 0;
185
+ for (let k = contentSegments.length - 1; k >= preservedCount; k--) {
186
+ const seg = contentSegments[k];
187
+ const contrib = seg.content + seg.trailingWs;
188
+ if (contrib.length === 0) break;
189
+ const start = packInput.length - suffixChars - contrib.length;
190
+ if (start >= consumedChars && packInput.slice(start, start + contrib.length) === contrib) {
191
+ suffixCount++;
192
+ suffixChars += contrib.length;
193
+ } else break;
194
+ }
195
+ if (suffixCount > 0) {
196
+ const middleInput = packInput.slice(consumedChars, packInput.length - suffixChars);
197
+ if (middleInput.length === 0 || middleInput[0] !== " ") {
198
+ for (let i = 0; i < preservedCount; i++) {
199
+ const seg = contentSegments[i];
200
+ rebuiltLines.push(`${seg.indent}${seg.content}${seg.trailingWs}\\`);
201
+ if (i < preservedCount - 1 && i < blankGroups.length && blankGroups[i].length > 0) for (const bl of blankGroups[i]) rebuiltLines.push(bl);
202
+ }
203
+ if (middleInput.length > 0) {
204
+ const midLines = packContent(middleInput);
205
+ const joinedMid = midLines.join("");
206
+ const hasEncodedNewlines = /(?<!\\)\\n/.test(joinedMid);
207
+ if (preservedCount > 0 && !hasEncodedNewlines) {
208
+ const bridgeIdx = preservedCount - 1;
209
+ if (bridgeIdx < blankGroups.length && blankGroups[bridgeIdx].length > 0) for (const bl of blankGroups[bridgeIdx]) rebuiltLines.push(bl);
210
+ }
211
+ for (let j = 0; j < midLines.length; j++) {
212
+ const newContent = midLines[j];
213
+ const origIdx = preservedCount + j;
214
+ const origSeg = origIdx < contentSegments.length ? contentSegments[origIdx] : null;
215
+ const indent = origSeg ? isLeadingNewlineOpening && origIdx === 0 ? newFirstIndent : origSeg.indent : contProto.indent;
216
+ const trailing = newContent.length > 0 && /\s$/.test(newContent) ? "" : middleInput.endsWith(" ") ? " " : "";
217
+ rebuiltLines.push(`${indent}${newContent}${trailing}\\`);
218
+ if (j < midLines.length - 1 && !hasEncodedNewlines) {
219
+ const bgIdx = preservedCount + j;
220
+ if (bgIdx < blankGroups.length && blankGroups[bgIdx].length > 0) for (const bl of blankGroups[bgIdx]) rebuiltLines.push(bl);
221
+ }
222
+ }
223
+ const midToSuffixBgIdx = contentSegments.length - suffixCount - 1;
224
+ if (!hasEncodedNewlines && midToSuffixBgIdx >= 0 && midToSuffixBgIdx < blankGroups.length && blankGroups[midToSuffixBgIdx].length > 0) for (const bl of blankGroups[midToSuffixBgIdx]) rebuiltLines.push(bl);
225
+ } else if (preservedCount > 0) {
226
+ const bridgeIdx = preservedCount - 1;
227
+ if (bridgeIdx < blankGroups.length && blankGroups[bridgeIdx].length > 0) for (const bl of blankGroups[bridgeIdx]) rebuiltLines.push(bl);
228
+ }
229
+ const suffixStart = contentSegments.length - suffixCount;
230
+ for (let i = suffixStart; i < contentSegments.length; i++) {
231
+ const seg = contentSegments[i];
232
+ const isTail = i === contentSegments.length - 1;
233
+ if (i > suffixStart) {
234
+ const bgIdx = i - 1;
235
+ if (bgIdx < blankGroups.length && blankGroups[bgIdx].length > 0) for (const bl of blankGroups[bgIdx]) rebuiltLines.push(bl);
236
+ }
237
+ rebuiltLines.push(isTail ? `${seg.indent}${seg.content}${seg.trailingWs}${seg.hasBackslash && seg.content !== "" ? "\\" : ""}` : `${seg.indent}${seg.content}${seg.trailingWs}\\`);
238
+ }
239
+ if (hasClosingIndent && !(tailProto.hasBackslash && tailProto.content === "")) return `${openingPrefix}${rebuiltLines.join(newlineChar)}${newlineChar}${closingIndent}${delimiter}`;
240
+ return `${openingPrefix}${rebuiltLines.join(newlineChar)}${delimiter}`;
241
+ }
242
+ }
243
+ const remainingInput = packInput.slice(consumedChars);
244
+ if (preservedCount > 0 && (consumedChars === packInput.length || remainingInput.length > 0 && remainingInput[0] !== " ")) {
245
+ for (let i = 0; i < preservedCount; i++) {
246
+ const seg = contentSegments[i];
247
+ rebuiltLines.push(`${seg.indent}${seg.content}${seg.trailingWs}\\`);
248
+ if (i < preservedCount - 1 && i < blankGroups.length && blankGroups[i].length > 0) for (const bl of blankGroups[i]) rebuiltLines.push(bl);
249
+ }
250
+ if (consumedChars === packInput.length) {
251
+ const lastSeg = contentSegments[preservedCount - 1];
252
+ const backslash = tailProto.hasBackslash && lastSeg.content !== "" ? "\\" : "";
253
+ rebuiltLines[rebuiltLines.length - 1] = `${lastSeg.indent}${lastSeg.content}${tailProto.trailingWs}${backslash}`;
254
+ } else {
255
+ const newPackedLines = packContent(remainingInput);
256
+ const joinedNew = newPackedLines.join("");
257
+ const hasEncodedNewlines = /(?<!\\)\\n/.test(joinedNew);
258
+ const bridgeIdx = preservedCount - 1;
259
+ if (!hasEncodedNewlines && bridgeIdx < blankGroups.length && blankGroups[bridgeIdx].length > 0) for (const bl of blankGroups[bridgeIdx]) rebuiltLines.push(bl);
260
+ for (let j = 0; j < newPackedLines.length; j++) {
261
+ const isLastNew = j === newPackedLines.length - 1;
262
+ const newContent = newPackedLines[j];
263
+ const origIdx = preservedCount + j;
264
+ const origSeg = origIdx < contentSegments.length ? contentSegments[origIdx] : null;
265
+ const indent = origSeg ? isLeadingNewlineOpening && origIdx === 0 ? newFirstIndent : origSeg.indent : isLastNew ? tailProto.indent : contProto.indent;
266
+ let trailing;
267
+ let backslash;
268
+ if (isLastNew) {
269
+ trailing = tailProto.trailingWs;
270
+ backslash = tailProto.hasBackslash && tailProto.content !== "" ? "\\" : "";
271
+ } else {
272
+ trailing = newContent.length > 0 && /\s$/.test(newContent) ? "" : " ";
273
+ backslash = "\\";
274
+ }
275
+ rebuiltLines.push(`${indent}${newContent}${trailing}${backslash}`);
276
+ if (!isLastNew) {
277
+ const bgIdx = preservedCount + j;
278
+ if (!hasEncodedNewlines && bgIdx < blankGroups.length && blankGroups[bgIdx].length > 0) for (const bl of blankGroups[bgIdx]) rebuiltLines.push(bl);
279
+ }
280
+ }
281
+ }
282
+ if (hasClosingIndent && !(tailProto.hasBackslash && tailProto.content === "")) return `${openingPrefix}${rebuiltLines.join(newlineChar)}${newlineChar}${closingIndent}${delimiter}`;
283
+ return `${openingPrefix}${rebuiltLines.join(newlineChar)}${delimiter}`;
284
+ }
285
+ }
286
+ const packed = packContent(packInput);
287
+ for (const l of packed) newContentLines.push(l);
288
+ }
289
+ for (let i = 0; i < newContentLines.length; i++) {
290
+ const isGlobalLast = i === newContentLines.length - 1;
291
+ const isParaEnd = paraEndIndices.has(i);
292
+ const isTailLike = isGlobalLast || isParaEnd;
293
+ const origSeg = i < contentSegments.length ? contentSegments[i] : null;
294
+ const indent = isLiteralLineBreakPath && logicalLineStartIndices.has(i) && i > 0 ? logicalLineStartIndentByIndex.get(i) ?? "" : origSeg ? isLeadingNewlineOpening && i === 0 ? newFirstIndent : origSeg.indent : isTailLike ? tailProto.indent : contProto.indent;
295
+ const newContent = newContentLines[i];
296
+ let trailing;
297
+ let backslash;
298
+ if (isTailLike && isGlobalLast) {
299
+ trailing = tailProto.trailingWs;
300
+ backslash = tailProto.hasBackslash && tailProto.content !== "" ? "\\" : "";
301
+ } else if (isTailLike) {
302
+ trailing = tailProto.trailingWs;
303
+ backslash = "";
304
+ } else {
305
+ trailing = newContent.length > 0 && /\s$/.test(newContent) ? "" : " ";
306
+ backslash = "\\";
307
+ }
308
+ rebuiltLines.push(`${indent}${newContent}${trailing}${backslash}`);
309
+ if (!isGlobalLast && !isParaEnd && !isLiteralLineBreakPath) {
310
+ const singleInput = newContentLines.join("");
311
+ if (!/(?<!\\)\\n/.test(singleInput) && i < blankGroups.length && blankGroups[i].length > 0) for (const blankLine of blankGroups[i]) rebuiltLines.push(blankLine);
312
+ }
313
+ }
314
+ if (hasClosingIndent && !(tailProto.hasBackslash && tailProto.content === "")) return `${openingPrefix}${rebuiltLines.join(newlineChar)}${newlineChar}${closingIndent}${delimiter}`;
315
+ return `${openingPrefix}${rebuiltLines.join(newlineChar)}${delimiter}`;
316
+ }
317
+
318
+ //#endregion
319
+ export { rebuildLineContinuation };
320
+ //# sourceMappingURL=line-ending-backslash.js.map