@decimalturn/toml-patch 3.1.1-dev → 3.1.2-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 (43) hide show
  1. package/dist/dev/comment-alignment.js +1 -1
  2. package/dist/dev/comment-ownership.js +1 -1
  3. package/dist/dev/cst-source.js +12 -2
  4. package/dist/dev/cst-source.js.map +1 -1
  5. package/dist/dev/cst.js +1 -1
  6. package/dist/dev/cursor.js +1 -1
  7. package/dist/dev/date-format.js +1 -1
  8. package/dist/dev/decode-utf8.js +1 -1
  9. package/dist/dev/diff.js +1 -1
  10. package/dist/dev/escape-preference.js +1 -1
  11. package/dist/dev/find-by-path.js +1 -1
  12. package/dist/dev/formatter.js +5 -2
  13. package/dist/dev/formatter.js.map +1 -1
  14. package/dist/dev/generate.js +1 -1
  15. package/dist/dev/inline-comma-space.js +1 -1
  16. package/dist/dev/inline-format.js +1 -1
  17. package/dist/dev/inline-layout.js +1 -1
  18. package/dist/dev/line-ending-backslash.js +1 -1
  19. package/dist/dev/location.js +1 -1
  20. package/dist/dev/parse-error.js +1 -1
  21. package/dist/dev/parse-js.js +8 -4
  22. package/dist/dev/parse-js.js.map +1 -1
  23. package/dist/dev/parse-string.js +1 -1
  24. package/dist/dev/parse-toml.js +47 -10
  25. package/dist/dev/parse-toml.js.map +1 -1
  26. package/dist/dev/patch.js +5 -2
  27. package/dist/dev/patch.js.map +1 -1
  28. package/dist/dev/to-js.js +1 -1
  29. package/dist/dev/to-toml.js +308 -3
  30. package/dist/dev/to-toml.js.map +1 -1
  31. package/dist/dev/tokenizer.js +1 -1
  32. package/dist/dev/toml-document.js +7 -2
  33. package/dist/dev/toml-document.js.map +1 -1
  34. package/dist/dev/toml-format.js +1 -1
  35. package/dist/dev/toml-patch.js +14 -4
  36. package/dist/dev/toml-patch.js.map +1 -1
  37. package/dist/dev/traverse.js +1 -1
  38. package/dist/dev/truncate.js +1 -1
  39. package/dist/dev/update-order.js +1 -1
  40. package/dist/dev/utils.js +1 -1
  41. package/dist/dev/writer.js +5 -5
  42. package/dist/dev/writer.js.map +1 -1
  43. package/package.json +1 -1
package/dist/dev/to-js.js CHANGED
@@ -1,4 +1,4 @@
1
- //! @decimalturn/toml-patch v3.1.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
1
+ //! @decimalturn/toml-patch v3.1.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
2
  import ParseError from "./parse-error.js";
3
3
  import { LocalDate, LocalDateTime, LocalTime, OffsetDateTime } from "./date-format.js";
4
4
  import { blank, has, isDate, last } from "./utils.js";
@@ -1,8 +1,8 @@
1
- //! @decimalturn/toml-patch v3.1.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
1
+ //! @decimalturn/toml-patch v3.1.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
2
  import { hasItem, hasItems, isInlineArray, isInlineItem, isInlineTable, isKeyValue, isTable, isTableArray } from "./cst.js";
3
3
  import { getCommaSpace } from "./inline-comma-space.js";
4
- import { getNodeSource, originalFirstChildStartedAfterOpener, sourceStructureUnchanged } from "./cst-source.js";
5
4
  import { isIterable } from "./utils.js";
5
+ import { getNodeSource, originalFirstChildStartedAfterOpener, sourceStructureUnchanged } from "./cst-source.js";
6
6
  import { isGeneratedNestedTable, isGeneratedNestedTableHost, isPreservedMultilineEmpty } from "./inline-format.js";
7
7
 
8
8
  //#region src/to-toml.ts
@@ -478,6 +478,311 @@ function toTOMLCursor(cst, format) {
478
478
  return chunks.join("").replace(/\r\n|\n/g, format.newLine) + format.newLine.repeat(format.trailingNewline);
479
479
  }
480
480
  /**
481
+ * Sequential emitter for generated CSTs. Generated nodes carry no source and
482
+ * already have consistent positions, so text can be appended in structural
483
+ * order and gaps filled with newlines and indentation instead of painting text
484
+ * at recorded coordinates. Produces byte-identical output to `toTOML` for CSTs
485
+ * produced by `parseJS`.
486
+ */
487
+ function toTOMLSequential(cst, format) {
488
+ const roots = Array.isArray(cst) ? cst : isIterable(cst) ? Array.from(cst) : [cst];
489
+ const chunks = [];
490
+ let line = 1;
491
+ let column = 0;
492
+ const indentation = (width) => (format.useTabsForIndentation ? " " : " ").repeat(width);
493
+ const append = (text) => {
494
+ if (text.length === 0) return;
495
+ chunks.push(text);
496
+ let count = 0;
497
+ let lastIndex = -1;
498
+ let index = text.indexOf("\n");
499
+ while (index !== -1) {
500
+ count++;
501
+ lastIndex = index;
502
+ index = text.indexOf("\n", index + 1);
503
+ }
504
+ if (count === 0) {
505
+ column += text.length;
506
+ return;
507
+ }
508
+ line += count;
509
+ column = text.length - lastIndex - 1;
510
+ };
511
+ const advanceTo = (targetLine, targetColumn) => {
512
+ if (targetLine > line) {
513
+ append(format.newLine.repeat(targetLine - line));
514
+ if (targetColumn > 0) append(indentation(targetColumn));
515
+ } else if (targetLine === line && targetColumn > column) append(column === 0 ? indentation(targetColumn) : " ".repeat(targetColumn - column));
516
+ else if (chunks.length > 0 && (targetLine < line || targetLine === line && targetColumn < column)) {
517
+ append(format.newLine);
518
+ if (targetColumn > 0) append(indentation(targetColumn));
519
+ }
520
+ };
521
+ const leafRaw = (node) => {
522
+ switch (node.type) {
523
+ case "Key": return node.raw;
524
+ case "String": return node.raw;
525
+ case "Integer": return node.raw;
526
+ case "Float": return node.raw;
527
+ case "Boolean": return node.value.toString();
528
+ case "DateTime": return node.raw;
529
+ case "Comment": return node.raw;
530
+ default: return "";
531
+ }
532
+ };
533
+ const stack = [];
534
+ const pushNode = (node, place) => {
535
+ switch (node.type) {
536
+ case "Document": {
537
+ const items = node.items;
538
+ for (let i = items.length - 1; i >= 0; i--) stack.push([
539
+ 0,
540
+ items[i],
541
+ true
542
+ ]);
543
+ break;
544
+ }
545
+ case "Table": {
546
+ const table = node;
547
+ const items = table.items;
548
+ for (let i = items.length - 1; i >= 0; i--) stack.push([
549
+ 0,
550
+ items[i],
551
+ true
552
+ ]);
553
+ stack.push([
554
+ 0,
555
+ table.key,
556
+ place
557
+ ]);
558
+ break;
559
+ }
560
+ case "TableKey": {
561
+ const tableKey = node;
562
+ stack.push([1, `[${tableKey.item.raw}]`]);
563
+ if (place) stack.push([
564
+ 3,
565
+ tableKey.loc.start.line,
566
+ tableKey.loc.start.column
567
+ ]);
568
+ break;
569
+ }
570
+ case "TableArray": {
571
+ const tableArray = node;
572
+ const items = tableArray.items;
573
+ for (let i = items.length - 1; i >= 0; i--) stack.push([
574
+ 0,
575
+ items[i],
576
+ true
577
+ ]);
578
+ stack.push([
579
+ 0,
580
+ tableArray.key,
581
+ place
582
+ ]);
583
+ break;
584
+ }
585
+ case "TableArrayKey": {
586
+ const tableArrayKey = node;
587
+ stack.push([1, `[[${tableArrayKey.item.raw}]]`]);
588
+ if (place) stack.push([
589
+ 3,
590
+ tableArrayKey.loc.start.line,
591
+ tableArrayKey.loc.start.column
592
+ ]);
593
+ break;
594
+ }
595
+ case "KeyValue": {
596
+ const keyValue = node;
597
+ stack.push([
598
+ 0,
599
+ keyValue.value,
600
+ false
601
+ ]);
602
+ stack.push([
603
+ 2,
604
+ keyValue.loc.start.line,
605
+ keyValue.equals + 1,
606
+ keyValue.value.loc.start.line,
607
+ keyValue.value.loc.start.column,
608
+ false
609
+ ]);
610
+ stack.push([1, "="]);
611
+ stack.push([
612
+ 2,
613
+ keyValue.key.loc.end.line,
614
+ keyValue.key.loc.end.column,
615
+ keyValue.loc.start.line,
616
+ keyValue.equals,
617
+ false
618
+ ]);
619
+ stack.push([
620
+ 0,
621
+ keyValue.key,
622
+ false
623
+ ]);
624
+ if (place) stack.push([
625
+ 3,
626
+ keyValue.loc.start.line,
627
+ keyValue.loc.start.column
628
+ ]);
629
+ break;
630
+ }
631
+ case "Key":
632
+ case "String":
633
+ case "Integer":
634
+ case "Float":
635
+ case "Boolean":
636
+ case "DateTime":
637
+ case "Comment":
638
+ stack.push([1, leafRaw(node)]);
639
+ if (place) stack.push([
640
+ 3,
641
+ node.loc.start.line,
642
+ node.loc.start.column
643
+ ]);
644
+ break;
645
+ case "InlineArray": {
646
+ const array = node;
647
+ const items = array.items;
648
+ stack.push([1, "]"]);
649
+ if (items.length > 0) {
650
+ const last = items[items.length - 1];
651
+ stack.push([
652
+ 2,
653
+ last.loc.end.line,
654
+ last.loc.end.column + (last.comma ? 1 : 0),
655
+ array.loc.end.line,
656
+ array.loc.end.column - 1,
657
+ false
658
+ ]);
659
+ }
660
+ for (let i = items.length - 1; i >= 0; i--) {
661
+ const current = items[i];
662
+ const previous = i > 0 ? items[i - 1] : void 0;
663
+ stack.push([
664
+ 0,
665
+ current,
666
+ false
667
+ ]);
668
+ stack.push(previous ? [
669
+ 2,
670
+ previous.loc.end.line,
671
+ previous.loc.end.column + (previous.comma ? 1 : 0),
672
+ current.loc.start.line,
673
+ current.loc.start.column,
674
+ false
675
+ ] : [
676
+ 2,
677
+ array.loc.start.line,
678
+ array.loc.start.column + 1,
679
+ current.loc.start.line,
680
+ current.loc.start.column,
681
+ false
682
+ ]);
683
+ }
684
+ stack.push([1, "["]);
685
+ if (place) stack.push([
686
+ 3,
687
+ array.loc.start.line,
688
+ array.loc.start.column
689
+ ]);
690
+ break;
691
+ }
692
+ case "InlineTable": {
693
+ const table = node;
694
+ const items = table.items;
695
+ const generatedMultilineTable = isGeneratedNestedTable(table);
696
+ stack.push([1, "}"]);
697
+ if (items.length > 0) {
698
+ const last = items[items.length - 1];
699
+ if (generatedMultilineTable && last.comma) stack.push([1, " "]);
700
+ stack.push([
701
+ 2,
702
+ last.loc.end.line,
703
+ last.loc.end.column + (last.comma ? 1 : 0),
704
+ table.loc.end.line,
705
+ table.loc.end.column - 1,
706
+ generatedMultilineTable
707
+ ]);
708
+ }
709
+ for (let i = items.length - 1; i >= 0; i--) {
710
+ const current = items[i];
711
+ const previous = i > 0 ? items[i - 1] : void 0;
712
+ stack.push([
713
+ 0,
714
+ current,
715
+ false
716
+ ]);
717
+ stack.push(previous ? [
718
+ 2,
719
+ previous.loc.end.line,
720
+ previous.loc.end.column + (previous.comma ? 1 : 0),
721
+ current.loc.start.line,
722
+ current.loc.start.column,
723
+ generatedMultilineTable
724
+ ] : [
725
+ 2,
726
+ table.loc.start.line,
727
+ table.loc.start.column + 1,
728
+ current.loc.start.line,
729
+ current.loc.start.column,
730
+ generatedMultilineTable
731
+ ]);
732
+ }
733
+ stack.push([1, "{"]);
734
+ if (place) stack.push([
735
+ 3,
736
+ table.loc.start.line,
737
+ table.loc.start.column
738
+ ]);
739
+ break;
740
+ }
741
+ case "InlineItem": {
742
+ const item = node;
743
+ if (item.comma) stack.push([1, ","]);
744
+ stack.push([
745
+ 0,
746
+ item.item,
747
+ false
748
+ ]);
749
+ break;
750
+ }
751
+ default: throw new Error(`toTOMLSequential: Unrecognized node type: ${String(node.type)}`);
752
+ }
753
+ };
754
+ for (let i = roots.length - 1; i >= 0; i--) stack.push([
755
+ 0,
756
+ roots[i],
757
+ true
758
+ ]);
759
+ while (stack.length > 0) {
760
+ const command = stack.pop();
761
+ switch (command[0]) {
762
+ case 0:
763
+ pushNode(command[1], command[2]);
764
+ break;
765
+ case 1:
766
+ append(command[1]);
767
+ break;
768
+ case 2: {
769
+ const fromLine = command[1];
770
+ const fromColumn = command[2];
771
+ const toLine = command[3];
772
+ const toColumn = command[4];
773
+ const absoluteIndent = command[5];
774
+ if (toLine > fromLine) {
775
+ append(format.newLine.repeat(toLine - fromLine));
776
+ if (toColumn > 0) append(absoluteIndent ? " ".repeat(toColumn) : indentation(toColumn));
777
+ } else if (toLine === fromLine && toColumn > fromColumn) append(" ".repeat(toColumn - fromColumn));
778
+ break;
779
+ }
780
+ case 3: advanceTo(command[1], command[2]);
781
+ }
782
+ }
783
+ return chunks.join("").replace(/\r\n|\n/g, format.newLine) + format.newLine.repeat(format.trailingNewline);
784
+ }
785
+ /**
481
786
  * Writes raw string content to specific location coordinates within a lines array.
482
787
  *
483
788
  * This function is responsible for placing TOML content at precise positions within
@@ -565,5 +870,5 @@ function getLine(lines, index) {
565
870
  }
566
871
 
567
872
  //#endregion
568
- export { toTOML as default, toTOMLCursor };
873
+ export { toTOML as default, toTOMLCursor, toTOMLSequential };
569
874
  //# sourceMappingURL=to-toml.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"to-toml.js","names":[],"sources":["../../src/to-toml.ts"],"sourcesContent":["import {\n getNodeSource,\n originalFirstChildStartedAfterOpener,\n sourceStructureUnchanged\n} from './cst-source';\nimport {\n NodeType,\n CST,\n TreeNode,\n Document,\n Table,\n TableKey,\n TableArray,\n TableArrayKey,\n KeyValue,\n Key,\n String as StringNode,\n Integer,\n Float,\n Boolean as BooleanNode,\n DateTime,\n InlineArray,\n InlineTable,\n InlineItem,\n Comment,\n hasItems,\n hasItem,\n isKeyValue,\n isInlineItem,\n isTable,\n isTableArray,\n isInlineTable,\n isInlineArray\n} from './cst';\nimport { Location } from './location';\nimport { SPACE } from './tokenizer';\nimport { TomlFormat } from './toml-format';\nimport { isIterable } from './utils';\nimport { getCommaSpace } from './inline-comma-space';\nimport { isGeneratedNestedTable, isGeneratedNestedTableHost, isPreservedMultilineEmpty } from './inline-format';\n\nconst BY_NEW_LINE = /(\\r\\n|\\n)/g;\n\n/**\n * Converts a Concrete Syntax Tree (CST) back to TOML format string.\n * \n * This function traverses the CST and reconstructs the original TOML document\n * by writing each node's raw content to the appropriate location coordinates.\n * It preserves the original formatting, spacing, and structure of the TOML file.\n * \n * @param cst - The Concrete Syntax Tree representing the parsed TOML document\n * @param format - The formatting options to use for the output\n * @returns The reconstructed TOML document as a string\n * \n * @example\n * ```typescript\n * const tomlString = toTOML(cst, TomlFormat.default());\n * ```\n */\nexport default function toTOML(cst: CST, format: TomlFormat): string {\n\n const lines: string[] = [];\n\n // Inline traversal for monomorphic property access (avoids generic traverse\n // visitor dispatch which causes megamorphic inline cache misses in V8)\n const closingPosition = (container: InlineArray | InlineTable): { line: number; column: number } => {\n const position = {\n line: container.loc.end.line,\n column: container.loc.end.column - 1\n };\n const last = container.items[container.items.length - 1];\n if (last && (last.loc.end.line > position.line ||\n (last.loc.end.line === position.line && last.loc.end.column > position.column))) {\n position.line = last.loc.end.line;\n position.column = last.loc.end.column + (last.comma ? 1 : 0);\n }\n return position;\n };\n\n function emitNode(node: TreeNode) {\n switch (node.type) {\n case NodeType.Document:\n for (let i = 0; i < (node as Document).items.length; i++)\n emitNode((node as Document).items[i]);\n break;\n\n case NodeType.Table: {\n const tbl = node as Table;\n emitNode(tbl.key);\n for (let i = 0; i < tbl.items.length; i++) emitNode(tbl.items[i]);\n break;\n }\n case NodeType.TableKey: {\n const tk = node as TableKey;\n // Emit \"[key]\" in one write instead of three (bracket, key, bracket).\n write(lines, tk.loc, '[' + tk.item.raw + ']');\n break;\n }\n\n case NodeType.TableArray: {\n const ta = node as TableArray;\n emitNode(ta.key);\n for (let i = 0; i < ta.items.length; i++) emitNode(ta.items[i]);\n break;\n }\n case NodeType.TableArrayKey: {\n const tak = node as TableArrayKey;\n // Emit \"[[key]]\" in one write instead of three.\n write(lines, tak.loc, '[[' + tak.item.raw + ']]');\n break;\n }\n\n case NodeType.KeyValue: {\n const kv = node as KeyValue;\n const line = kv.loc.start.line;\n writeSingle(lines, line, kv.equals, '=');\n emitNode(kv.key);\n emitNode(kv.value);\n break;\n }\n\n case NodeType.Key:\n write(lines, node.loc, (node as Key).raw);\n break;\n\n case NodeType.String:\n write(lines, node.loc, (node as StringNode).raw);\n break;\n case NodeType.Integer:\n write(lines, node.loc, (node as Integer).raw);\n break;\n case NodeType.Float:\n write(lines, node.loc, (node as Float).raw);\n break;\n case NodeType.Boolean:\n write(lines, node.loc, (node as BooleanNode).value.toString());\n break;\n case NodeType.DateTime:\n write(lines, node.loc, (node as DateTime).raw);\n break;\n\n case NodeType.InlineArray: {\n const ia = node as InlineArray;\n const { start } = ia.loc;\n const closing = closingPosition(ia);\n writeSingle(lines, start.line, start.column, '[');\n writeSingle(lines, closing.line, closing.column, ']');\n for (let i = 0; i < ia.items.length; i++) emitNode(ia.items[i]);\n break;\n }\n case NodeType.InlineTable: {\n const it = node as InlineTable;\n const { start } = it.loc;\n const closing = closingPosition(it);\n writeSingle(lines, start.line, start.column, '{');\n writeSingle(lines, closing.line, closing.column, '}');\n for (let i = 0; i < it.items.length; i++) emitNode(it.items[i]);\n break;\n }\n case NodeType.InlineItem: {\n const ii = node as InlineItem;\n emitNode(ii.item);\n if (ii.comma) {\n const end = ii.loc.end;\n writeSingle(lines, end.line, end.column, ',');\n }\n break;\n }\n\n case NodeType.Comment:\n write(lines, node.loc, (node as Comment).raw);\n break;\n default: {\n // Preserve original behavior: throw on unrecognized node types\n // to catch bugs when new node types are added or invalid nodes appear.\n const type = (node as any).type;\n throw new Error(`toTOML: Unrecognized node type: ${String(type)}`);\n }\n }\n }\n\n // Handle both Document nodes and bare iterables (document.items)\n if (isIterable(cst)) {\n for (const item of cst) emitNode(item as TreeNode);\n } else {\n emitNode(cst as unknown as TreeNode);\n }\n\n // Post-process: convert leading spaces to tabs if useTabsForIndentation is enabled\n if (format.useTabsForIndentation) {\n // Lines belonging to multiline string literals are VALUE content — the\n // indentation there is part of the string and must not be converted\n // (fuzz seed 70). The opening-delimiter line may carry structural\n // indentation, but every line from the first content line through the\n // closing delimiter is untouchable.\n const contentLines = new Set<number>();\n const collectStringLines = (node: TreeNode) => {\n if (node.type === NodeType.String && node.loc.end.line > node.loc.start.line) {\n for (let l = node.loc.start.line + 1; l <= node.loc.end.line; l++) {\n contentLines.add(l);\n }\n }\n if (hasItems(node)) {\n for (const item of node.items as TreeNode[]) collectStringLines(item);\n }\n if (isKeyValue(node)) collectStringLines(node.value);\n if (isInlineItem(node)) collectStringLines(node.item);\n };\n if (isIterable(cst)) {\n for (const item of cst) collectStringLines(item as TreeNode);\n } else {\n collectStringLines(cst as unknown as TreeNode);\n }\n\n for (let i = 0; i < lines.length; i++) {\n if (contentLines.has(i + 1)) continue;\n const line = lines[i];\n // Find the leading whitespace\n const match = line.match(/^( +)/);\n if (match) {\n const leadingSpaces = match[1];\n // Replace entire leading space sequence with equivalent tabs\n // Each space becomes a tab (preserving the visual width)\n const leadingTabs = '\\t'.repeat(leadingSpaces.length);\n lines[i] = leadingTabs + line.substring(leadingSpaces.length);\n }\n }\n }\n\n return lines.join(format.newLine) + format.newLine.repeat(format.trailingNewline);\n}\n\n/**\n * Source-aware emitter used while CST ranges replace coordinate painting.\n * Clean nodes copy their original text. Dirty nodes emit in structural order,\n * so a stale coordinate can add whitespace but cannot overwrite later text.\n */\nexport function toTOMLCursor(cst: CST, format: TomlFormat): string {\n const roots = isIterable(cst)\n ? Array.from(cst as Iterable<TreeNode>)\n : [cst as unknown as TreeNode];\n const chunks: string[] = [];\n const copiedRanges: Array<{ source: string; start: number; end: number }> = [];\n const hostedComments: Comment[] = [];\n const consumedComments = new WeakSet<Comment>();\n let line = 1;\n let column = 0;\n\n const collectComments = (node: TreeNode): void => {\n if (node.type === NodeType.Comment) hostedComments.push(node as Comment);\n if (isKeyValue(node)) collectComments(node.value);\n else if (isInlineItem(node)) collectComments(node.item);\n else if (node.type === NodeType.Table || node.type === NodeType.TableArray) {\n for (const item of (node as Table | TableArray).items) collectComments(item);\n } else if (hasItems(node)) {\n for (const item of node.items as TreeNode[]) collectComments(item);\n }\n };\n for (const root of roots) collectComments(root);\n\n // Inline containers that are direct values of block-level key-values\n // (Document, Table or TableArray). When such a container is emptied, its\n // multiline closing bracket is preserved. Nested containers keep it too when\n // writer.remove() marked them as emptied from an interior row\n // (markPreservedMultilineEmpty); any other emptied container tightens to a\n // single line.\n const blockLevelInlineContainers = new WeakSet<InlineTable | InlineArray>();\n const markBlockLevelInlineContainers = (items: TreeNode[]): void => {\n for (const item of items) {\n if (isKeyValue(item)) {\n const value = item.value;\n if (isInlineTable(value) || isInlineArray(value)) {\n blockLevelInlineContainers.add(value);\n }\n } else if (isTable(item) || isTableArray(item)) {\n markBlockLevelInlineContainers((item as Table | TableArray).items as TreeNode[]);\n }\n }\n };\n markBlockLevelInlineContainers(roots);\n\n const indentation = (width: number): string =>\n (format.useTabsForIndentation ? '\\t' : SPACE).repeat(width);\n\n const append = (text: string): void => {\n if (text.length === 0) return;\n chunks.push(text);\n const parts = text.split(/\\r\\n|\\n/);\n if (parts.length === 1) {\n column += text.length;\n } else {\n line += parts.length - 1;\n column = parts[parts.length - 1].length;\n }\n };\n\n const advanceTo = (targetLine: number, targetColumn: number): void => {\n if (targetLine > line) {\n append(format.newLine.repeat(targetLine - line));\n if (targetColumn > 0) append(indentation(targetColumn));\n } else if (targetLine === line && targetColumn > column) {\n // At the start of a line the gap up to the node is leading indentation,\n // so it must follow the document's tab/spaces preference rather than\n // always padding with spaces (a tab-indented first line would otherwise\n // be re-emitted with a space).\n append(column === 0 ? indentation(targetColumn) : SPACE.repeat(targetColumn - column));\n } else if (chunks.length > 0 &&\n (targetLine < line || (targetLine === line && targetColumn < column))) {\n append(format.newLine);\n if (targetColumn > 0) append(indentation(targetColumn));\n }\n };\n\n const leafText = (node: TreeNode): string | undefined => {\n switch (node.type) {\n case NodeType.Key: return (node as Key).raw;\n case NodeType.String: return (node as StringNode).raw;\n case NodeType.Integer: return (node as Integer).raw;\n case NodeType.Float: return (node as Float).raw;\n case NodeType.Boolean: return (node as BooleanNode).value.toString();\n case NodeType.DateTime: return (node as DateTime).raw;\n case NodeType.Comment: return (node as Comment).raw;\n default: return undefined;\n }\n };\n\n const directChildren = (node: TreeNode): TreeNode[] => {\n if (isKeyValue(node)) return [node.key, node.value];\n if (isInlineItem(node)) return [node.item];\n if (hasItem(node)) return [node.item];\n if (node.type === NodeType.Table || node.type === NodeType.TableArray) {\n const table = node as Table | TableArray;\n return [table.key, ...table.items];\n }\n return hasItems(node) ? node.items as TreeNode[] : [];\n };\n\n const sourceSubtreeReusable = (node: TreeNode): boolean => {\n const pending = [node];\n while (pending.length > 0) {\n const current = pending.pop()!;\n if (current.dirty) return false;\n const text = leafText(current);\n if (text !== undefined) {\n const source = getNodeSource(current);\n if (!source || !current.range || source.slice(current.range[0], current.range[1]) !== text) {\n return false;\n }\n } else if (!sourceStructureUnchanged(current)) {\n return false;\n }\n pending.push(...directChildren(current));\n }\n return true;\n };\n\n const canCopyWholeNode = (node: TreeNode): boolean =>\n node.type !== NodeType.Document &&\n node.type !== NodeType.InlineItem &&\n node.type !== NodeType.TableKey &&\n node.type !== NodeType.TableArrayKey &&\n (leafText(node) !== undefined || sourceStructureUnchanged(node));\n\n const appendRelativeGap = (\n from: { line: number; column: number },\n to: { line: number; column: number },\n absoluteIndent = false\n ): void => {\n if (to.line > from.line) {\n append(format.newLine.repeat(to.line - from.line));\n if (to.column > 0) append(absoluteIndent ? SPACE.repeat(to.column) : indentation(to.column));\n } else if (to.line === from.line && to.column > from.column) {\n append(SPACE.repeat(to.column - from.column));\n }\n };\n\n const sourceGap = (\n container: InlineArray | InlineTable,\n previous: InlineItem | undefined,\n current: InlineItem | undefined\n ): string | undefined => {\n const source = getNodeSource(container);\n if (!source || !container.range) return undefined;\n if (isInlineArray(container) && isGeneratedNestedTableHost(container) &&\n (!current || (previous && !previous.range) || (current && !current.range))) return undefined;\n if (previous && getNodeSource(previous) !== source) return undefined;\n if (current && getNodeSource(current) !== source) return undefined;\n const start = previous?.range?.[1] ?? container.range[0] + 1;\n const end = current?.range?.[0] ?? container.range[1] - 1;\n if (start === undefined || end === undefined || end < start) return undefined;\n\n let gap = source.slice(start, end);\n if (previous?.comma && gap.startsWith(',')) gap = gap.slice(1);\n if (!/^[\\t \\r\\n]*$/.test(gap)) return undefined;\n return gap;\n };\n\n const commentBelongsTo = (comment: Comment, container: InlineArray | InlineTable): boolean => {\n const source = getNodeSource(container);\n return source !== undefined &&\n getNodeSource(comment) === source &&\n container.range !== undefined &&\n comment.range !== undefined &&\n comment.range[0] >= container.range[0] &&\n comment.range[1] <= container.range[1];\n };\n\n const emitInlineItems = (container: InlineArray | InlineTable): void => {\n const generatedMultilineTable = isInlineTable(container) && isGeneratedNestedTable(container);\n let previous: InlineItem | undefined;\n for (const current of container.items as InlineItem[]) {\n let from = previous\n ? {\n line: previous.loc.end.line,\n column: previous.loc.end.column + (previous.comma ? 1 : 0)\n }\n : {\n line: container.loc.start.line,\n column: container.loc.start.column + 1\n };\n const commentsBefore = hostedComments\n .filter(comment => !consumedComments.has(comment) && commentBelongsTo(comment, container) &&\n comment.loc.start.line >= from.line &&\n comment.loc.end.line <= current.loc.start.line &&\n (comment.loc.start.line > from.line || comment.loc.start.column >= from.column) &&\n (comment.loc.end.line < current.loc.start.line || comment.loc.end.column <= current.loc.start.column) &&\n comment.loc.start.line >= container.loc.start.line &&\n comment.loc.end.line <= container.loc.end.line)\n .sort((left, right) =>\n left.loc.start.line - right.loc.start.line ||\n left.loc.start.column - right.loc.start.column);\n\n if (commentsBefore.length > 0) {\n for (const comment of commentsBefore) {\n appendRelativeGap(from, comment.loc.start);\n append(comment.raw);\n consumedComments.add(comment);\n from = comment.loc.end;\n }\n appendRelativeGap(from, current.loc.start);\n } else {\n const gap = sourceGap(container, previous, current);\n if (gap !== undefined) {\n append(gap);\n } else {\n const crossSource = getNodeSource(current) !== getNodeSource(container);\n if (previous && crossSource && current.loc.start.line === previous.loc.end.line) {\n const commaGap = getCommaSpace(container) ?? 2;\n const wantedSpaces = Math.max(0, commaGap - 1);\n if (wantedSpaces > 0) append(SPACE.repeat(wantedSpaces));\n } else {\n appendRelativeGap(from, current.loc.start, generatedMultilineTable);\n }\n }\n }\n emitNode(current, false);\n for (const comment of hostedComments) {\n if (consumedComments.has(comment)) continue;\n if (!commentBelongsTo(comment, container)) continue;\n if (comment.loc.start.line !== current.loc.end.line) continue;\n if (comment.loc.start.column < current.loc.end.column) continue;\n if (comment.loc.start.line < container.loc.start.line ||\n comment.loc.end.line > container.loc.end.line) continue;\n const separatorEnd = current.loc.end.column + (current.comma ? 1 : 0);\n if (comment.loc.start.column > separatorEnd) {\n append(SPACE.repeat(comment.loc.start.column - separatorEnd));\n }\n append(comment.raw);\n consumedComments.add(comment);\n }\n previous = current;\n }\n\n let trailingFrom = previous\n ? {\n line: previous.loc.end.line,\n column: previous.loc.end.column + (previous.comma ? 1 : 0)\n }\n : { line: container.loc.start.line, column: container.loc.start.column + 1 };\n const trailingComments = hostedComments\n .filter(comment => !consumedComments.has(comment) && commentBelongsTo(comment, container) &&\n comment.loc.start.line >= trailingFrom.line &&\n comment.loc.end.line <= container.loc.end.line)\n .sort((left, right) =>\n left.loc.start.line - right.loc.start.line ||\n left.loc.start.column - right.loc.start.column);\n if (trailingComments.length > 0) {\n for (const comment of trailingComments) {\n appendRelativeGap(trailingFrom, comment.loc.start);\n append(comment.raw);\n consumedComments.add(comment);\n trailingFrom = comment.loc.end;\n }\n appendRelativeGap(trailingFrom, {\n line: container.loc.end.line,\n column: container.loc.end.column - 1\n });\n } else {\n const trailingGap = sourceGap(container, previous, undefined);\n if (trailingGap !== undefined) append(trailingGap);\n else if (previous) {\n if (generatedMultilineTable && previous.comma) append(SPACE);\n appendRelativeGap(trailingFrom, {\n line: container.loc.end.line,\n column: container.loc.end.column - 1\n }, generatedMultilineTable);\n }\n else {\n const source = getNodeSource(container);\n if (source && container.range) {\n const original = source.slice(container.range[0], container.range[1]);\n const lastNewline = Math.max(original.lastIndexOf('\\n'), original.lastIndexOf('\\r'));\n const keepClosingRow = blockLevelInlineContainers.has(container) ||\n isPreservedMultilineEmpty(container);\n if (lastNewline !== -1 && keepClosingRow && originalFirstChildStartedAfterOpener(container)) {\n const closingIndent = original.slice(lastNewline + 1, -1).match(/^[\\t ]*/)?.[0] ?? '';\n append(format.newLine + closingIndent);\n }\n }\n }\n }\n };\n\n const emitNode = (node: TreeNode, place = true): void => {\n if (node.type === NodeType.Comment && consumedComments.has(node as Comment)) return;\n const source = getNodeSource(node);\n if (source !== undefined && node.range && copiedRanges.some(copied =>\n copied.source === source && copied.start <= node.range![0] && copied.end >= node.range![1]\n )) {\n return;\n }\n if (canCopyWholeNode(node) && sourceSubtreeReusable(node) && node.range && source !== undefined) {\n const slice = source.slice(node.range[0], node.range[1]);\n const expectedLeaf = leafText(node);\n if (expectedLeaf === undefined || expectedLeaf === slice) {\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append(slice);\n copiedRanges.push({ source, start: node.range[0], end: node.range[1] });\n return;\n }\n }\n\n switch (node.type) {\n case NodeType.Document:\n for (const item of (node as Document).items) emitNode(item);\n break;\n case NodeType.Table: {\n const table = node as Table;\n emitNode(table.key, place);\n for (const item of table.items) emitNode(item);\n break;\n }\n case NodeType.TableKey: {\n const tableKey = node as TableKey;\n if (place) advanceTo(tableKey.loc.start.line, tableKey.loc.start.column);\n append(`[${tableKey.item.raw}]`);\n break;\n }\n case NodeType.TableArray: {\n const tableArray = node as TableArray;\n emitNode(tableArray.key, place);\n for (const item of tableArray.items) emitNode(item);\n break;\n }\n case NodeType.TableArrayKey: {\n const tableArrayKey = node as TableArrayKey;\n if (place) advanceTo(tableArrayKey.loc.start.line, tableArrayKey.loc.start.column);\n append(`[[${tableArrayKey.item.raw}]]`);\n break;\n }\n case NodeType.KeyValue: {\n const keyValue = node as KeyValue;\n if (place) advanceTo(keyValue.loc.start.line, keyValue.loc.start.column);\n emitNode(keyValue.key, false);\n appendRelativeGap(keyValue.key.loc.end, {\n line: keyValue.loc.start.line,\n column: keyValue.equals\n });\n append('=');\n appendRelativeGap({ line: keyValue.loc.start.line, column: keyValue.equals + 1 }, keyValue.value.loc.start);\n emitNode(keyValue.value, false);\n break;\n }\n case NodeType.Key:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as Key).raw);\n break;\n case NodeType.String:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as StringNode).raw);\n break;\n case NodeType.Integer:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as Integer).raw);\n break;\n case NodeType.Float:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as Float).raw);\n break;\n case NodeType.Boolean:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as BooleanNode).value.toString());\n break;\n case NodeType.DateTime:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as DateTime).raw);\n break;\n case NodeType.InlineArray: {\n const array = node as InlineArray;\n if (place) advanceTo(array.loc.start.line, array.loc.start.column);\n append('[');\n emitInlineItems(array);\n append(']');\n break;\n }\n case NodeType.InlineTable: {\n const table = node as InlineTable;\n if (place) advanceTo(table.loc.start.line, table.loc.start.column);\n append('{');\n emitInlineItems(table);\n append('}');\n break;\n }\n case NodeType.InlineItem: {\n const item = node as InlineItem;\n emitNode(item.item, false);\n if (item.comma) {\n const source = getNodeSource(item);\n if (source && item.range && item.item.range && getNodeSource(item.item) === source) {\n const beforeComma = source.slice(item.item.range[1], item.range[1]);\n if (/^[\\t ]*$/.test(beforeComma)) append(beforeComma);\n }\n append(',');\n }\n break;\n }\n case NodeType.Comment:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as Comment).raw);\n break;\n default:\n throw new Error(`toTOMLCursor: Unrecognized node type: ${String((node as any).type)}`);\n }\n };\n\n for (const root of roots) emitNode(root);\n\n const output = chunks.join('').replace(/\\r\\n|\\n/g, format.newLine);\n return output + format.newLine.repeat(format.trailingNewline);\n}\n\n/**\n * Writes raw string content to specific location coordinates within a lines array.\n * \n * This function is responsible for placing TOML content at precise positions within\n * the output lines, handling multi-line content and preserving existing content\n * around the target location.\n * \n * @param lines - Array of string lines representing the TOML document being built.\n * Lines are 1-indexed but stored in 0-indexed array.\n * @param loc - Location object specifying where to write the content, containing:\n * - start: { line: number, column: number } - Starting position (1-indexed line, 0-indexed column)\n * - end: { line: number, column: number } - Ending position (1-indexed line, 0-indexed column)\n * @param raw - The raw string content to write at the specified location.\n * Can contain multiple lines separated by \\n or \\r\\n.\n * \n * @throws {Error} When there's a mismatch between location span and raw string line count\n * @throws {Error} When attempting to write to an uninitialized line\n * \n * @example\n * ```typescript\n * const lines = ['', ''];\n * const location = { start: { line: 1, column: 0 }, end: { line: 1, column: 3 } };\n * write(lines, location, 'key');\n * // Result: lines[0] becomes 'key'\n * ```\n */\nfunction write(lines: string[], loc: Location, raw: string) {\n // Fast path for single-line content (the vast majority of nodes).\n // Avoids the regex split + filter that allocates two temporary arrays.\n if (loc.start.line === loc.end.line) {\n const line = getLine(lines, loc.start.line);\n\n const existingBefore = line.substring(0, loc.start.column);\n const before = existingBefore.length < loc.start.column\n ? existingBefore.padEnd(loc.start.column, SPACE)\n : existingBefore;\n const after = line.substring(loc.end.column);\n\n lines[loc.start.line - 1] = before + raw + after;\n return;\n }\n\n // Multi-line path: split and filter newline separators\n const raw_lines = raw.split(BY_NEW_LINE).filter(line => line !== '\\n' && line !== '\\r\\n');\n const expected_lines = loc.end.line - loc.start.line + 1;\n\n if (raw_lines.length !== expected_lines) {\n throw new Error(\n `Mismatch between location and raw string, expected ${expected_lines} lines for \"${raw}\"`\n );\n }\n\n for (let i = loc.start.line; i <= loc.end.line; i++) {\n const line = getLine(lines, i);\n\n const is_start_line = i === loc.start.line;\n const is_end_line = i === loc.end.line;\n\n let before = '';\n if (is_start_line) {\n const existingBefore = line.substring(0, loc.start.column);\n if (existingBefore.length < loc.start.column) {\n // Need to pad - always use spaces during write phase\n // Tab conversion happens in post-processing for leading indentation only\n before = existingBefore.padEnd(loc.start.column, SPACE);\n } else {\n before = existingBefore;\n }\n }\n const after = is_end_line ? line.substring(loc.end.column) : '';\n\n lines[i - 1] = before + raw_lines[i - loc.start.line] + after;\n }\n}\n\n/**\n * Fast path for writing a single character at a specific position.\n * Avoids creating temporary Location objects.\n */\nfunction writeSingle(lines: string[], lineNum: number, column: number, char: string) {\n const line = getLine(lines, lineNum);\n const before = line.length < column\n ? line.padEnd(column, SPACE)\n : line.substring(0, column);\n const after = line.substring(column + 1);\n lines[lineNum - 1] = before + char + after;\n}\n\n/**\n * Safely retrieves a line from the lines array, initializing empty lines as needed.\n * \n * This helper function handles the conversion between 1-indexed line numbers (used in locations)\n * and 0-indexed array positions. It ensures that accessing a line that doesn't exist yet\n * will initialize all preceding lines with empty strings.\n * \n * @param lines - Array of string lines representing the document\n * @param index - 1-indexed line number to retrieve\n * @returns The line content as a string, or empty string for new lines\n * \n * @example\n * ```typescript\n * const lines = ['first line'];\n * const line = getLine(lines, 3); // Initializes lines[1] and lines[2] as empty strings\n * // lines becomes ['first line', '', '']\n * ```\n */\nfunction getLine(lines: string[], index: number): string {\n if (!lines[index - 1]) {\n for (let i = 0; i < index; i++) {\n if (!lines[i]) lines[i] = '';\n }\n }\n\n return lines[index - 1];\n}\n"],"mappings":";;;;;;;;AAyCA,MAAM,cAAc;;;;;;;;;;;;;;;;;AAkBpB,SAAwB,OAAO,KAAU,QAA4B;CAEnE,MAAM,QAAkB,CAAC;CAIzB,MAAM,mBAAmB,cAA2E;EAClG,MAAM,WAAW;GACf,MAAM,UAAU,IAAI,IAAI;GACxB,QAAQ,UAAU,IAAI,IAAI,SAAS;EACrC;EACA,MAAM,OAAO,UAAU,MAAM,UAAU,MAAM,SAAS;EACtD,IAAI,SAAS,KAAK,IAAI,IAAI,OAAO,SAAS,QACrC,KAAK,IAAI,IAAI,SAAS,SAAS,QAAQ,KAAK,IAAI,IAAI,SAAS,SAAS,SAAU;GACnF,SAAS,OAAO,KAAK,IAAI,IAAI;GAC7B,SAAS,SAAS,KAAK,IAAI,IAAI,UAAU,KAAK,QAAQ,IAAI;EAC5D;EACA,OAAO;CACT;CAEA,SAAS,SAAS,MAAgB;EAChC,QAAQ,KAAK,MAAb;GACE;IACE,KAAK,IAAI,IAAI,GAAG,IAAK,KAAkB,MAAM,QAAQ,KACnD,SAAU,KAAkB,MAAM,EAAE;IACtC;GAEF,cAAqB;IACnB,MAAM,MAAM;IACZ,SAAS,IAAI,GAAG;IAChB,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,MAAM,QAAQ,KAAK,SAAS,IAAI,MAAM,EAAE;IAChE;GACF;GACA,iBAAwB;IACtB,MAAM,KAAK;IAEX,MAAM,OAAO,GAAG,KAAK,MAAM,GAAG,KAAK,MAAM,GAAG;IAC5C;GACF;GAEA,mBAA0B;IACxB,MAAM,KAAK;IACX,SAAS,GAAG,GAAG;IACf,KAAK,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AI,IAAI;EAElC,IAAI,SAAS;EACb,IAAI,eAAe;GACjB,MAAM,iBAAiB,KAAK,UAAU,GAAG,IAAI,MAAM,MAAM;GACzD,IAAI,eAAe,SAAS,IAAI,MAAM,QAGpC,SAAS,eAAe,OAAO,IAAI,MAAM,WAAa;QAEtD,SAAS;EAEb;EACA,MAAM,QAAQ,cAAc,KAAK,UAAU,IAAI,IAAI,MAAM,IAAI;EAE7D,MAAM,IAAI,KAAK,SAAS,UAAU,IAAI,IAAI,MAAM,QAAQ;CAC1D;AACF;;;;;AAMA,SAAS,YAAY,OAAiB,SAAiB,QAAgB,MAAc;CACnF,MAAM,OAAO,QAAQ,OAAO,OAAO;CACnC,MAAM,SAAS,KAAK,SAAS,SACzB,KAAK,OAAO,WAAa,IACzB,KAAK,UAAU,GAAG,MAAM;CAC5B,MAAM,QAAQ,KAAK,UAAU,SAAS,CAAC;CACvC,MAAM,UAAU,KAAK,SAAS,OAAO;AACvC;;;;;;;;;;;;;;;;;;;AAoBA,SAAS,QAAQ,OAAiB,OAAuB;CACvD,IAAI,CAAC,MAAM,QAAQ,IACjB;OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KACzB,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK;CAC5B;CAGF,OAAO,MAAM,QAAQ;AACvB"}
1
+ {"version":3,"file":"to-toml.js","names":[],"sources":["../../src/to-toml.ts"],"sourcesContent":["import {\n getNodeSource,\n originalFirstChildStartedAfterOpener,\n sourceStructureUnchanged\n} from './cst-source';\nimport {\n NodeType,\n CST,\n TreeNode,\n Document,\n Table,\n TableKey,\n TableArray,\n TableArrayKey,\n KeyValue,\n Key,\n String as StringNode,\n Integer,\n Float,\n Boolean as BooleanNode,\n DateTime,\n InlineArray,\n InlineTable,\n InlineItem,\n Comment,\n hasItems,\n hasItem,\n isKeyValue,\n isInlineItem,\n isTable,\n isTableArray,\n isInlineTable,\n isInlineArray\n} from './cst';\nimport { Location } from './location';\nimport { SPACE } from './tokenizer';\nimport { TomlFormat } from './toml-format';\nimport { isIterable } from './utils';\nimport { getCommaSpace } from './inline-comma-space';\nimport { isGeneratedNestedTable, isGeneratedNestedTableHost, isPreservedMultilineEmpty } from './inline-format';\n\nconst BY_NEW_LINE = /(\\r\\n|\\n)/g;\n\n/**\n * Converts a Concrete Syntax Tree (CST) back to TOML format string.\n * \n * This function traverses the CST and reconstructs the original TOML document\n * by writing each node's raw content to the appropriate location coordinates.\n * It preserves the original formatting, spacing, and structure of the TOML file.\n * \n * @param cst - The Concrete Syntax Tree representing the parsed TOML document\n * @param format - The formatting options to use for the output\n * @returns The reconstructed TOML document as a string\n * \n * @example\n * ```typescript\n * const tomlString = toTOML(cst, TomlFormat.default());\n * ```\n */\nexport default function toTOML(cst: CST, format: TomlFormat): string {\n\n const lines: string[] = [];\n\n // Inline traversal for monomorphic property access (avoids generic traverse\n // visitor dispatch which causes megamorphic inline cache misses in V8)\n const closingPosition = (container: InlineArray | InlineTable): { line: number; column: number } => {\n const position = {\n line: container.loc.end.line,\n column: container.loc.end.column - 1\n };\n const last = container.items[container.items.length - 1];\n if (last && (last.loc.end.line > position.line ||\n (last.loc.end.line === position.line && last.loc.end.column > position.column))) {\n position.line = last.loc.end.line;\n position.column = last.loc.end.column + (last.comma ? 1 : 0);\n }\n return position;\n };\n\n function emitNode(node: TreeNode) {\n switch (node.type) {\n case NodeType.Document:\n for (let i = 0; i < (node as Document).items.length; i++)\n emitNode((node as Document).items[i]);\n break;\n\n case NodeType.Table: {\n const tbl = node as Table;\n emitNode(tbl.key);\n for (let i = 0; i < tbl.items.length; i++) emitNode(tbl.items[i]);\n break;\n }\n case NodeType.TableKey: {\n const tk = node as TableKey;\n // Emit \"[key]\" in one write instead of three (bracket, key, bracket).\n write(lines, tk.loc, '[' + tk.item.raw + ']');\n break;\n }\n\n case NodeType.TableArray: {\n const ta = node as TableArray;\n emitNode(ta.key);\n for (let i = 0; i < ta.items.length; i++) emitNode(ta.items[i]);\n break;\n }\n case NodeType.TableArrayKey: {\n const tak = node as TableArrayKey;\n // Emit \"[[key]]\" in one write instead of three.\n write(lines, tak.loc, '[[' + tak.item.raw + ']]');\n break;\n }\n\n case NodeType.KeyValue: {\n const kv = node as KeyValue;\n const line = kv.loc.start.line;\n writeSingle(lines, line, kv.equals, '=');\n emitNode(kv.key);\n emitNode(kv.value);\n break;\n }\n\n case NodeType.Key:\n write(lines, node.loc, (node as Key).raw);\n break;\n\n case NodeType.String:\n write(lines, node.loc, (node as StringNode).raw);\n break;\n case NodeType.Integer:\n write(lines, node.loc, (node as Integer).raw);\n break;\n case NodeType.Float:\n write(lines, node.loc, (node as Float).raw);\n break;\n case NodeType.Boolean:\n write(lines, node.loc, (node as BooleanNode).value.toString());\n break;\n case NodeType.DateTime:\n write(lines, node.loc, (node as DateTime).raw);\n break;\n\n case NodeType.InlineArray: {\n const ia = node as InlineArray;\n const { start } = ia.loc;\n const closing = closingPosition(ia);\n writeSingle(lines, start.line, start.column, '[');\n writeSingle(lines, closing.line, closing.column, ']');\n for (let i = 0; i < ia.items.length; i++) emitNode(ia.items[i]);\n break;\n }\n case NodeType.InlineTable: {\n const it = node as InlineTable;\n const { start } = it.loc;\n const closing = closingPosition(it);\n writeSingle(lines, start.line, start.column, '{');\n writeSingle(lines, closing.line, closing.column, '}');\n for (let i = 0; i < it.items.length; i++) emitNode(it.items[i]);\n break;\n }\n case NodeType.InlineItem: {\n const ii = node as InlineItem;\n emitNode(ii.item);\n if (ii.comma) {\n const end = ii.loc.end;\n writeSingle(lines, end.line, end.column, ',');\n }\n break;\n }\n\n case NodeType.Comment:\n write(lines, node.loc, (node as Comment).raw);\n break;\n default: {\n // Preserve original behavior: throw on unrecognized node types\n // to catch bugs when new node types are added or invalid nodes appear.\n const type = (node as any).type;\n throw new Error(`toTOML: Unrecognized node type: ${String(type)}`);\n }\n }\n }\n\n // Handle both Document nodes and bare iterables (document.items)\n if (isIterable(cst)) {\n for (const item of cst) emitNode(item as TreeNode);\n } else {\n emitNode(cst as unknown as TreeNode);\n }\n\n // Post-process: convert leading spaces to tabs if useTabsForIndentation is enabled\n if (format.useTabsForIndentation) {\n // Lines belonging to multiline string literals are VALUE content — the\n // indentation there is part of the string and must not be converted\n // (fuzz seed 70). The opening-delimiter line may carry structural\n // indentation, but every line from the first content line through the\n // closing delimiter is untouchable.\n const contentLines = new Set<number>();\n const collectStringLines = (node: TreeNode) => {\n if (node.type === NodeType.String && node.loc.end.line > node.loc.start.line) {\n for (let l = node.loc.start.line + 1; l <= node.loc.end.line; l++) {\n contentLines.add(l);\n }\n }\n if (hasItems(node)) {\n for (const item of node.items as TreeNode[]) collectStringLines(item);\n }\n if (isKeyValue(node)) collectStringLines(node.value);\n if (isInlineItem(node)) collectStringLines(node.item);\n };\n if (isIterable(cst)) {\n for (const item of cst) collectStringLines(item as TreeNode);\n } else {\n collectStringLines(cst as unknown as TreeNode);\n }\n\n for (let i = 0; i < lines.length; i++) {\n if (contentLines.has(i + 1)) continue;\n const line = lines[i];\n // Find the leading whitespace\n const match = line.match(/^( +)/);\n if (match) {\n const leadingSpaces = match[1];\n // Replace entire leading space sequence with equivalent tabs\n // Each space becomes a tab (preserving the visual width)\n const leadingTabs = '\\t'.repeat(leadingSpaces.length);\n lines[i] = leadingTabs + line.substring(leadingSpaces.length);\n }\n }\n }\n\n return lines.join(format.newLine) + format.newLine.repeat(format.trailingNewline);\n}\n\n/**\n * Source-aware emitter used while CST ranges replace coordinate painting.\n * Clean nodes copy their original text. Dirty nodes emit in structural order,\n * so a stale coordinate can add whitespace but cannot overwrite later text.\n */\nexport function toTOMLCursor(cst: CST, format: TomlFormat): string {\n const roots = isIterable(cst)\n ? Array.from(cst as Iterable<TreeNode>)\n : [cst as unknown as TreeNode];\n const chunks: string[] = [];\n const copiedRanges: Array<{ source: string; start: number; end: number }> = [];\n const hostedComments: Comment[] = [];\n const consumedComments = new WeakSet<Comment>();\n let line = 1;\n let column = 0;\n\n const collectComments = (node: TreeNode): void => {\n if (node.type === NodeType.Comment) hostedComments.push(node as Comment);\n if (isKeyValue(node)) collectComments(node.value);\n else if (isInlineItem(node)) collectComments(node.item);\n else if (node.type === NodeType.Table || node.type === NodeType.TableArray) {\n for (const item of (node as Table | TableArray).items) collectComments(item);\n } else if (hasItems(node)) {\n for (const item of node.items as TreeNode[]) collectComments(item);\n }\n };\n for (const root of roots) collectComments(root);\n\n // Inline containers that are direct values of block-level key-values\n // (Document, Table or TableArray). When such a container is emptied, its\n // multiline closing bracket is preserved. Nested containers keep it too when\n // writer.remove() marked them as emptied from an interior row\n // (markPreservedMultilineEmpty); any other emptied container tightens to a\n // single line.\n const blockLevelInlineContainers = new WeakSet<InlineTable | InlineArray>();\n const markBlockLevelInlineContainers = (items: TreeNode[]): void => {\n for (const item of items) {\n if (isKeyValue(item)) {\n const value = item.value;\n if (isInlineTable(value) || isInlineArray(value)) {\n blockLevelInlineContainers.add(value);\n }\n } else if (isTable(item) || isTableArray(item)) {\n markBlockLevelInlineContainers((item as Table | TableArray).items as TreeNode[]);\n }\n }\n };\n markBlockLevelInlineContainers(roots);\n\n const indentation = (width: number): string =>\n (format.useTabsForIndentation ? '\\t' : SPACE).repeat(width);\n\n const append = (text: string): void => {\n if (text.length === 0) return;\n chunks.push(text);\n const parts = text.split(/\\r\\n|\\n/);\n if (parts.length === 1) {\n column += text.length;\n } else {\n line += parts.length - 1;\n column = parts[parts.length - 1].length;\n }\n };\n\n const advanceTo = (targetLine: number, targetColumn: number): void => {\n if (targetLine > line) {\n append(format.newLine.repeat(targetLine - line));\n if (targetColumn > 0) append(indentation(targetColumn));\n } else if (targetLine === line && targetColumn > column) {\n // At the start of a line the gap up to the node is leading indentation,\n // so it must follow the document's tab/spaces preference rather than\n // always padding with spaces (a tab-indented first line would otherwise\n // be re-emitted with a space).\n append(column === 0 ? indentation(targetColumn) : SPACE.repeat(targetColumn - column));\n } else if (chunks.length > 0 &&\n (targetLine < line || (targetLine === line && targetColumn < column))) {\n append(format.newLine);\n if (targetColumn > 0) append(indentation(targetColumn));\n }\n };\n\n const leafText = (node: TreeNode): string | undefined => {\n switch (node.type) {\n case NodeType.Key: return (node as Key).raw;\n case NodeType.String: return (node as StringNode).raw;\n case NodeType.Integer: return (node as Integer).raw;\n case NodeType.Float: return (node as Float).raw;\n case NodeType.Boolean: return (node as BooleanNode).value.toString();\n case NodeType.DateTime: return (node as DateTime).raw;\n case NodeType.Comment: return (node as Comment).raw;\n default: return undefined;\n }\n };\n\n const directChildren = (node: TreeNode): TreeNode[] => {\n if (isKeyValue(node)) return [node.key, node.value];\n if (isInlineItem(node)) return [node.item];\n if (hasItem(node)) return [node.item];\n if (node.type === NodeType.Table || node.type === NodeType.TableArray) {\n const table = node as Table | TableArray;\n return [table.key, ...table.items];\n }\n return hasItems(node) ? node.items as TreeNode[] : [];\n };\n\n const sourceSubtreeReusable = (node: TreeNode): boolean => {\n const pending = [node];\n while (pending.length > 0) {\n const current = pending.pop()!;\n if (current.dirty) return false;\n const text = leafText(current);\n if (text !== undefined) {\n const source = getNodeSource(current);\n if (!source || !current.range || source.slice(current.range[0], current.range[1]) !== text) {\n return false;\n }\n } else if (!sourceStructureUnchanged(current)) {\n return false;\n }\n pending.push(...directChildren(current));\n }\n return true;\n };\n\n const canCopyWholeNode = (node: TreeNode): boolean =>\n node.type !== NodeType.Document &&\n node.type !== NodeType.InlineItem &&\n node.type !== NodeType.TableKey &&\n node.type !== NodeType.TableArrayKey &&\n (leafText(node) !== undefined || sourceStructureUnchanged(node));\n\n const appendRelativeGap = (\n from: { line: number; column: number },\n to: { line: number; column: number },\n absoluteIndent = false\n ): void => {\n if (to.line > from.line) {\n append(format.newLine.repeat(to.line - from.line));\n if (to.column > 0) append(absoluteIndent ? SPACE.repeat(to.column) : indentation(to.column));\n } else if (to.line === from.line && to.column > from.column) {\n append(SPACE.repeat(to.column - from.column));\n }\n };\n\n const sourceGap = (\n container: InlineArray | InlineTable,\n previous: InlineItem | undefined,\n current: InlineItem | undefined\n ): string | undefined => {\n const source = getNodeSource(container);\n if (!source || !container.range) return undefined;\n if (isInlineArray(container) && isGeneratedNestedTableHost(container) &&\n (!current || (previous && !previous.range) || (current && !current.range))) return undefined;\n if (previous && getNodeSource(previous) !== source) return undefined;\n if (current && getNodeSource(current) !== source) return undefined;\n const start = previous?.range?.[1] ?? container.range[0] + 1;\n const end = current?.range?.[0] ?? container.range[1] - 1;\n if (start === undefined || end === undefined || end < start) return undefined;\n\n let gap = source.slice(start, end);\n if (previous?.comma && gap.startsWith(',')) gap = gap.slice(1);\n if (!/^[\\t \\r\\n]*$/.test(gap)) return undefined;\n return gap;\n };\n\n const commentBelongsTo = (comment: Comment, container: InlineArray | InlineTable): boolean => {\n const source = getNodeSource(container);\n return source !== undefined &&\n getNodeSource(comment) === source &&\n container.range !== undefined &&\n comment.range !== undefined &&\n comment.range[0] >= container.range[0] &&\n comment.range[1] <= container.range[1];\n };\n\n const emitInlineItems = (container: InlineArray | InlineTable): void => {\n const generatedMultilineTable = isInlineTable(container) && isGeneratedNestedTable(container);\n let previous: InlineItem | undefined;\n for (const current of container.items as InlineItem[]) {\n let from = previous\n ? {\n line: previous.loc.end.line,\n column: previous.loc.end.column + (previous.comma ? 1 : 0)\n }\n : {\n line: container.loc.start.line,\n column: container.loc.start.column + 1\n };\n const commentsBefore = hostedComments\n .filter(comment => !consumedComments.has(comment) && commentBelongsTo(comment, container) &&\n comment.loc.start.line >= from.line &&\n comment.loc.end.line <= current.loc.start.line &&\n (comment.loc.start.line > from.line || comment.loc.start.column >= from.column) &&\n (comment.loc.end.line < current.loc.start.line || comment.loc.end.column <= current.loc.start.column) &&\n comment.loc.start.line >= container.loc.start.line &&\n comment.loc.end.line <= container.loc.end.line)\n .sort((left, right) =>\n left.loc.start.line - right.loc.start.line ||\n left.loc.start.column - right.loc.start.column);\n\n if (commentsBefore.length > 0) {\n for (const comment of commentsBefore) {\n appendRelativeGap(from, comment.loc.start);\n append(comment.raw);\n consumedComments.add(comment);\n from = comment.loc.end;\n }\n appendRelativeGap(from, current.loc.start);\n } else {\n const gap = sourceGap(container, previous, current);\n if (gap !== undefined) {\n append(gap);\n } else {\n const crossSource = getNodeSource(current) !== getNodeSource(container);\n if (previous && crossSource && current.loc.start.line === previous.loc.end.line) {\n const commaGap = getCommaSpace(container) ?? 2;\n const wantedSpaces = Math.max(0, commaGap - 1);\n if (wantedSpaces > 0) append(SPACE.repeat(wantedSpaces));\n } else {\n appendRelativeGap(from, current.loc.start, generatedMultilineTable);\n }\n }\n }\n emitNode(current, false);\n for (const comment of hostedComments) {\n if (consumedComments.has(comment)) continue;\n if (!commentBelongsTo(comment, container)) continue;\n if (comment.loc.start.line !== current.loc.end.line) continue;\n if (comment.loc.start.column < current.loc.end.column) continue;\n if (comment.loc.start.line < container.loc.start.line ||\n comment.loc.end.line > container.loc.end.line) continue;\n const separatorEnd = current.loc.end.column + (current.comma ? 1 : 0);\n if (comment.loc.start.column > separatorEnd) {\n append(SPACE.repeat(comment.loc.start.column - separatorEnd));\n }\n append(comment.raw);\n consumedComments.add(comment);\n }\n previous = current;\n }\n\n let trailingFrom = previous\n ? {\n line: previous.loc.end.line,\n column: previous.loc.end.column + (previous.comma ? 1 : 0)\n }\n : { line: container.loc.start.line, column: container.loc.start.column + 1 };\n const trailingComments = hostedComments\n .filter(comment => !consumedComments.has(comment) && commentBelongsTo(comment, container) &&\n comment.loc.start.line >= trailingFrom.line &&\n comment.loc.end.line <= container.loc.end.line)\n .sort((left, right) =>\n left.loc.start.line - right.loc.start.line ||\n left.loc.start.column - right.loc.start.column);\n if (trailingComments.length > 0) {\n for (const comment of trailingComments) {\n appendRelativeGap(trailingFrom, comment.loc.start);\n append(comment.raw);\n consumedComments.add(comment);\n trailingFrom = comment.loc.end;\n }\n appendRelativeGap(trailingFrom, {\n line: container.loc.end.line,\n column: container.loc.end.column - 1\n });\n } else {\n const trailingGap = sourceGap(container, previous, undefined);\n if (trailingGap !== undefined) append(trailingGap);\n else if (previous) {\n if (generatedMultilineTable && previous.comma) append(SPACE);\n appendRelativeGap(trailingFrom, {\n line: container.loc.end.line,\n column: container.loc.end.column - 1\n }, generatedMultilineTable);\n }\n else {\n const source = getNodeSource(container);\n if (source && container.range) {\n const original = source.slice(container.range[0], container.range[1]);\n const lastNewline = Math.max(original.lastIndexOf('\\n'), original.lastIndexOf('\\r'));\n const keepClosingRow = blockLevelInlineContainers.has(container) ||\n isPreservedMultilineEmpty(container);\n if (lastNewline !== -1 && keepClosingRow && originalFirstChildStartedAfterOpener(container)) {\n const closingIndent = original.slice(lastNewline + 1, -1).match(/^[\\t ]*/)?.[0] ?? '';\n append(format.newLine + closingIndent);\n }\n }\n }\n }\n };\n\n const emitNode = (node: TreeNode, place = true): void => {\n if (node.type === NodeType.Comment && consumedComments.has(node as Comment)) return;\n const source = getNodeSource(node);\n if (source !== undefined && node.range && copiedRanges.some(copied =>\n copied.source === source && copied.start <= node.range![0] && copied.end >= node.range![1]\n )) {\n return;\n }\n if (canCopyWholeNode(node) && sourceSubtreeReusable(node) && node.range && source !== undefined) {\n const slice = source.slice(node.range[0], node.range[1]);\n const expectedLeaf = leafText(node);\n if (expectedLeaf === undefined || expectedLeaf === slice) {\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append(slice);\n copiedRanges.push({ source, start: node.range[0], end: node.range[1] });\n return;\n }\n }\n\n switch (node.type) {\n case NodeType.Document:\n for (const item of (node as Document).items) emitNode(item);\n break;\n case NodeType.Table: {\n const table = node as Table;\n emitNode(table.key, place);\n for (const item of table.items) emitNode(item);\n break;\n }\n case NodeType.TableKey: {\n const tableKey = node as TableKey;\n if (place) advanceTo(tableKey.loc.start.line, tableKey.loc.start.column);\n append(`[${tableKey.item.raw}]`);\n break;\n }\n case NodeType.TableArray: {\n const tableArray = node as TableArray;\n emitNode(tableArray.key, place);\n for (const item of tableArray.items) emitNode(item);\n break;\n }\n case NodeType.TableArrayKey: {\n const tableArrayKey = node as TableArrayKey;\n if (place) advanceTo(tableArrayKey.loc.start.line, tableArrayKey.loc.start.column);\n append(`[[${tableArrayKey.item.raw}]]`);\n break;\n }\n case NodeType.KeyValue: {\n const keyValue = node as KeyValue;\n if (place) advanceTo(keyValue.loc.start.line, keyValue.loc.start.column);\n emitNode(keyValue.key, false);\n appendRelativeGap(keyValue.key.loc.end, {\n line: keyValue.loc.start.line,\n column: keyValue.equals\n });\n append('=');\n appendRelativeGap({ line: keyValue.loc.start.line, column: keyValue.equals + 1 }, keyValue.value.loc.start);\n emitNode(keyValue.value, false);\n break;\n }\n case NodeType.Key:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as Key).raw);\n break;\n case NodeType.String:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as StringNode).raw);\n break;\n case NodeType.Integer:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as Integer).raw);\n break;\n case NodeType.Float:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as Float).raw);\n break;\n case NodeType.Boolean:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as BooleanNode).value.toString());\n break;\n case NodeType.DateTime:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as DateTime).raw);\n break;\n case NodeType.InlineArray: {\n const array = node as InlineArray;\n if (place) advanceTo(array.loc.start.line, array.loc.start.column);\n append('[');\n emitInlineItems(array);\n append(']');\n break;\n }\n case NodeType.InlineTable: {\n const table = node as InlineTable;\n if (place) advanceTo(table.loc.start.line, table.loc.start.column);\n append('{');\n emitInlineItems(table);\n append('}');\n break;\n }\n case NodeType.InlineItem: {\n const item = node as InlineItem;\n emitNode(item.item, false);\n if (item.comma) {\n const source = getNodeSource(item);\n if (source && item.range && item.item.range && getNodeSource(item.item) === source) {\n const beforeComma = source.slice(item.item.range[1], item.range[1]);\n if (/^[\\t ]*$/.test(beforeComma)) append(beforeComma);\n }\n append(',');\n }\n break;\n }\n case NodeType.Comment:\n if (place) advanceTo(node.loc.start.line, node.loc.start.column);\n append((node as Comment).raw);\n break;\n default:\n throw new Error(`toTOMLCursor: Unrecognized node type: ${String((node as any).type)}`);\n }\n };\n\n for (const root of roots) emitNode(root);\n\n const output = chunks.join('').replace(/\\r\\n|\\n/g, format.newLine);\n return output + format.newLine.repeat(format.trailingNewline);\n}\n\n/**\n * Sequential emitter for generated CSTs. Generated nodes carry no source and\n * already have consistent positions, so text can be appended in structural\n * order and gaps filled with newlines and indentation instead of painting text\n * at recorded coordinates. Produces byte-identical output to `toTOML` for CSTs\n * produced by `parseJS`.\n */\nexport function toTOMLSequential(cst: CST, format: TomlFormat): string {\n // `stringify()` passes `document.items` (an array), so avoid Array.from's\n // eager copy of an array that is already indexable.\n const roots: TreeNode[] = Array.isArray(cst)\n ? cst\n : isIterable(cst)\n ? Array.from(cst as Iterable<TreeNode>)\n : [cst as unknown as TreeNode];\n const chunks: string[] = [];\n let line = 1;\n let column = 0;\n\n const indentation = (width: number): string =>\n (format.useTabsForIndentation ? '\\t' : SPACE).repeat(width);\n\n const append = (text: string): void => {\n if (text.length === 0) return;\n chunks.push(text);\n let count = 0;\n let lastIndex = -1;\n let index = text.indexOf('\\n');\n while (index !== -1) {\n count++;\n lastIndex = index;\n index = text.indexOf('\\n', index + 1);\n }\n if (count === 0) {\n column += text.length;\n return;\n }\n line += count;\n column = text.length - lastIndex - 1;\n };\n\n const advanceTo = (targetLine: number, targetColumn: number): void => {\n if (targetLine > line) {\n append(format.newLine.repeat(targetLine - line));\n if (targetColumn > 0) append(indentation(targetColumn));\n } else if (targetLine === line && targetColumn > column) {\n append(column === 0 ? indentation(targetColumn) : SPACE.repeat(targetColumn - column));\n } else if (chunks.length > 0 &&\n (targetLine < line || (targetLine === line && targetColumn < column))) {\n append(format.newLine);\n if (targetColumn > 0) append(indentation(targetColumn));\n }\n };\n\n const leafRaw = (node: TreeNode): string => {\n switch (node.type) {\n case NodeType.Key: return (node as Key).raw;\n case NodeType.String: return (node as StringNode).raw;\n case NodeType.Integer: return (node as Integer).raw;\n case NodeType.Float: return (node as Float).raw;\n case NodeType.Boolean: return (node as BooleanNode).value.toString();\n case NodeType.DateTime: return (node as DateTime).raw;\n case NodeType.Comment: return (node as Comment).raw;\n default: return '';\n }\n };\n\n // Iterative command stack: emits in structural order without recursion, so\n // arbitrarily deep nesting (the toml-test \"scaling\" fixtures) cannot overflow\n // the call stack. Command encoding:\n // [0, node, place] emit a node\n // [1, text] append raw text\n // [2, fl, fc, tl, tc, absolute] append a relative gap from (fl, fc) to (tl, tc)\n // [3, line, column] advance the cursor\n const stack: any[] = [];\n\n const pushNode = (node: TreeNode, place: boolean): void => {\n switch (node.type) {\n case NodeType.Document: {\n const items = (node as Document).items;\n for (let i = items.length - 1; i >= 0; i--) stack.push([0, items[i], true]);\n break;\n }\n case NodeType.Table: {\n const table = node as Table;\n const items = table.items;\n for (let i = items.length - 1; i >= 0; i--) stack.push([0, items[i], true]);\n stack.push([0, table.key, place]);\n break;\n }\n case NodeType.TableKey: {\n const tableKey = node as TableKey;\n stack.push([1, `[${tableKey.item.raw}]`]);\n if (place) stack.push([3, tableKey.loc.start.line, tableKey.loc.start.column]);\n break;\n }\n case NodeType.TableArray: {\n const tableArray = node as TableArray;\n const items = tableArray.items;\n for (let i = items.length - 1; i >= 0; i--) stack.push([0, items[i], true]);\n stack.push([0, tableArray.key, place]);\n break;\n }\n case NodeType.TableArrayKey: {\n const tableArrayKey = node as TableArrayKey;\n stack.push([1, `[[${tableArrayKey.item.raw}]]`]);\n if (place) stack.push([3, tableArrayKey.loc.start.line, tableArrayKey.loc.start.column]);\n break;\n }\n case NodeType.KeyValue: {\n const keyValue = node as KeyValue;\n stack.push([0, keyValue.value, false]);\n stack.push([2, keyValue.loc.start.line, keyValue.equals + 1, keyValue.value.loc.start.line, keyValue.value.loc.start.column, false]);\n stack.push([1, '=']);\n stack.push([2, keyValue.key.loc.end.line, keyValue.key.loc.end.column, keyValue.loc.start.line, keyValue.equals, false]);\n stack.push([0, keyValue.key, false]);\n if (place) stack.push([3, keyValue.loc.start.line, keyValue.loc.start.column]);\n break;\n }\n case NodeType.Key:\n case NodeType.String:\n case NodeType.Integer:\n case NodeType.Float:\n case NodeType.Boolean:\n case NodeType.DateTime:\n case NodeType.Comment: {\n stack.push([1, leafRaw(node)]);\n if (place) stack.push([3, node.loc.start.line, node.loc.start.column]);\n break;\n }\n case NodeType.InlineArray: {\n const array = node as InlineArray;\n const items = array.items as InlineItem[];\n stack.push([1, ']']);\n if (items.length > 0) {\n const last = items[items.length - 1];\n stack.push([2, last.loc.end.line, last.loc.end.column + (last.comma ? 1 : 0), array.loc.end.line, array.loc.end.column - 1, false]);\n }\n for (let i = items.length - 1; i >= 0; i--) {\n const current = items[i];\n const previous = i > 0 ? items[i - 1] : undefined;\n stack.push([0, current, false]);\n stack.push(previous\n ? [2, previous.loc.end.line, previous.loc.end.column + (previous.comma ? 1 : 0), current.loc.start.line, current.loc.start.column, false]\n : [2, array.loc.start.line, array.loc.start.column + 1, current.loc.start.line, current.loc.start.column, false]);\n }\n stack.push([1, '[']);\n if (place) stack.push([3, array.loc.start.line, array.loc.start.column]);\n break;\n }\n case NodeType.InlineTable: {\n const table = node as InlineTable;\n const items = table.items as InlineItem[];\n const generatedMultilineTable = isGeneratedNestedTable(table);\n stack.push([1, '}']);\n if (items.length > 0) {\n const last = items[items.length - 1];\n if (generatedMultilineTable && last.comma) stack.push([1, SPACE]);\n stack.push([2, last.loc.end.line, last.loc.end.column + (last.comma ? 1 : 0), table.loc.end.line, table.loc.end.column - 1, generatedMultilineTable]);\n }\n for (let i = items.length - 1; i >= 0; i--) {\n const current = items[i];\n const previous = i > 0 ? items[i - 1] : undefined;\n stack.push([0, current, false]);\n stack.push(previous\n ? [2, previous.loc.end.line, previous.loc.end.column + (previous.comma ? 1 : 0), current.loc.start.line, current.loc.start.column, generatedMultilineTable]\n : [2, table.loc.start.line, table.loc.start.column + 1, current.loc.start.line, current.loc.start.column, generatedMultilineTable]);\n }\n stack.push([1, '{']);\n if (place) stack.push([3, table.loc.start.line, table.loc.start.column]);\n break;\n }\n case NodeType.InlineItem: {\n const item = node as InlineItem;\n if (item.comma) stack.push([1, ',']);\n stack.push([0, item.item, false]);\n break;\n }\n default:\n throw new Error(`toTOMLSequential: Unrecognized node type: ${String((node as any).type)}`);\n }\n };\n\n for (let i = roots.length - 1; i >= 0; i--) stack.push([0, roots[i], true]);\n\n while (stack.length > 0) {\n const command = stack.pop()!;\n switch (command[0]) {\n case 0:\n pushNode(command[1], command[2]);\n break;\n case 1:\n append(command[1]);\n break;\n case 2: {\n const fromLine = command[1];\n const fromColumn = command[2];\n const toLine = command[3];\n const toColumn = command[4];\n const absoluteIndent = command[5];\n if (toLine > fromLine) {\n append(format.newLine.repeat(toLine - fromLine));\n if (toColumn > 0) append(absoluteIndent ? SPACE.repeat(toColumn) : indentation(toColumn));\n } else if (toLine === fromLine && toColumn > fromColumn) {\n append(SPACE.repeat(toColumn - fromColumn));\n }\n break;\n }\n case 3:\n advanceTo(command[1], command[2]);\n break;\n }\n }\n\n return chunks.join('').replace(/\\r\\n|\\n/g, format.newLine) + format.newLine.repeat(format.trailingNewline);\n}\n\n/**\n * Writes raw string content to specific location coordinates within a lines array.\n * \n * This function is responsible for placing TOML content at precise positions within\n * the output lines, handling multi-line content and preserving existing content\n * around the target location.\n * \n * @param lines - Array of string lines representing the TOML document being built.\n * Lines are 1-indexed but stored in 0-indexed array.\n * @param loc - Location object specifying where to write the content, containing:\n * - start: { line: number, column: number } - Starting position (1-indexed line, 0-indexed column)\n * - end: { line: number, column: number } - Ending position (1-indexed line, 0-indexed column)\n * @param raw - The raw string content to write at the specified location.\n * Can contain multiple lines separated by \\n or \\r\\n.\n * \n * @throws {Error} When there's a mismatch between location span and raw string line count\n * @throws {Error} When attempting to write to an uninitialized line\n * \n * @example\n * ```typescript\n * const lines = ['', ''];\n * const location = { start: { line: 1, column: 0 }, end: { line: 1, column: 3 } };\n * write(lines, location, 'key');\n * // Result: lines[0] becomes 'key'\n * ```\n */\nfunction write(lines: string[], loc: Location, raw: string) {\n // Fast path for single-line content (the vast majority of nodes).\n // Avoids the regex split + filter that allocates two temporary arrays.\n if (loc.start.line === loc.end.line) {\n const line = getLine(lines, loc.start.line);\n\n const existingBefore = line.substring(0, loc.start.column);\n const before = existingBefore.length < loc.start.column\n ? existingBefore.padEnd(loc.start.column, SPACE)\n : existingBefore;\n const after = line.substring(loc.end.column);\n\n lines[loc.start.line - 1] = before + raw + after;\n return;\n }\n\n // Multi-line path: split and filter newline separators\n const raw_lines = raw.split(BY_NEW_LINE).filter(line => line !== '\\n' && line !== '\\r\\n');\n const expected_lines = loc.end.line - loc.start.line + 1;\n\n if (raw_lines.length !== expected_lines) {\n throw new Error(\n `Mismatch between location and raw string, expected ${expected_lines} lines for \"${raw}\"`\n );\n }\n\n for (let i = loc.start.line; i <= loc.end.line; i++) {\n const line = getLine(lines, i);\n\n const is_start_line = i === loc.start.line;\n const is_end_line = i === loc.end.line;\n\n let before = '';\n if (is_start_line) {\n const existingBefore = line.substring(0, loc.start.column);\n if (existingBefore.length < loc.start.column) {\n // Need to pad - always use spaces during write phase\n // Tab conversion happens in post-processing for leading indentation only\n before = existingBefore.padEnd(loc.start.column, SPACE);\n } else {\n before = existingBefore;\n }\n }\n const after = is_end_line ? line.substring(loc.end.column) : '';\n\n lines[i - 1] = before + raw_lines[i - loc.start.line] + after;\n }\n}\n\n/**\n * Fast path for writing a single character at a specific position.\n * Avoids creating temporary Location objects.\n */\nfunction writeSingle(lines: string[], lineNum: number, column: number, char: string) {\n const line = getLine(lines, lineNum);\n const before = line.length < column\n ? line.padEnd(column, SPACE)\n : line.substring(0, column);\n const after = line.substring(column + 1);\n lines[lineNum - 1] = before + char + after;\n}\n\n/**\n * Safely retrieves a line from the lines array, initializing empty lines as needed.\n * \n * This helper function handles the conversion between 1-indexed line numbers (used in locations)\n * and 0-indexed array positions. It ensures that accessing a line that doesn't exist yet\n * will initialize all preceding lines with empty strings.\n * \n * @param lines - Array of string lines representing the document\n * @param index - 1-indexed line number to retrieve\n * @returns The line content as a string, or empty string for new lines\n * \n * @example\n * ```typescript\n * const lines = ['first line'];\n * const line = getLine(lines, 3); // Initializes lines[1] and lines[2] as empty strings\n * // lines becomes ['first line', '', '']\n * ```\n */\nfunction getLine(lines: string[], index: number): string {\n if (!lines[index - 1]) {\n for (let i = 0; i < index; i++) {\n if (!lines[i]) lines[i] = '';\n }\n }\n\n return lines[index - 1];\n}\n"],"mappings":";;;;;;;;AAyCA,MAAM,cAAc;;;;;;;;;;;;;;;;;AAkBpB,SAAwB,OAAO,KAAU,QAA4B;CAEnE,MAAM,QAAkB,CAAC;CAIzB,MAAM,mBAAmB,cAA2E;EAClG,MAAM,WAAW;GACf,MAAM,UAAU,IAAI,IAAI;GACxB,QAAQ,UAAU,IAAI,IAAI,SAAS;EACrC;EACA,MAAM,OAAO,UAAU,MAAM,UAAU,MAAM,SAAS;EACtD,IAAI,SAAS,KAAK,IAAI,IAAI,OAAO,SAAS,QACrC,KAAK,IAAI,IAAI,SAAS,SAAS,QAAQ,KAAK,IAAI,IAAI,SAAS,SAAS,SAAU;GACnF,SAAS,OAAO,KAAK,IAAI,IAAI;GAC7B,SAAS,SAAS,KAAK,IAAI,IAAI,UAAU,KAAK,QAAQ,IAAI;EAC5D;EACA,OAAO;CACT;CAEA,SAAS,SAAS,MAAgB;EAChC,QAAQ,KAAK,MAAb;GACE;IACE,KAAK,IAAI,IAAI,GAAG,IAAK,KAAkB,MAAM,QAAQ,KACnD,SAAU,KAAkB,MAAM,EAAE;IACtC;GAEF,cAAqB;IACnB,MAAM,MAAM;IACZ,SAAS,IAAI,GAAG;IAChB,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,MAAM,QAAQ,KAAK,SAAS,IAAI,MAAM,EAAE;IAChE;GACF;GACA,iBAAwB;IACtB,MAAM,KAAK;IAEX,MAAM,OAAO,GAAG,KAAK,MAAM,GAAG,KAAK,MAAM,GAAG;IAC5C;GACF;GAEA,mBAA0B;IACxB,MAAM,KAAK;IACX,SAAS,GAAG,GAAG;IACf,K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cAAc,IAAI,EACzF;CAGF,KAAK,IAAI,IAAI,IAAI,MAAM,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK;EACnD,MAAM,OAAO,QAAQ,OAAO,CAAC;EAE7B,MAAM,gBAAgB,MAAM,IAAI,MAAM;EACtC,MAAM,cAAc,MAAM,IAAI,IAAI;EAElC,IAAI,SAAS;EACb,IAAI,eAAe;GACjB,MAAM,iBAAiB,KAAK,UAAU,GAAG,IAAI,MAAM,MAAM;GACzD,IAAI,eAAe,SAAS,IAAI,MAAM,QAGpC,SAAS,eAAe,OAAO,IAAI,MAAM,WAAa;QAEtD,SAAS;EAEb;EACA,MAAM,QAAQ,cAAc,KAAK,UAAU,IAAI,IAAI,MAAM,IAAI;EAE7D,MAAM,IAAI,KAAK,SAAS,UAAU,IAAI,IAAI,MAAM,QAAQ;CAC1D;AACF;;;;;AAMA,SAAS,YAAY,OAAiB,SAAiB,QAAgB,MAAc;CACnF,MAAM,OAAO,QAAQ,OAAO,OAAO;CACnC,MAAM,SAAS,KAAK,SAAS,SACzB,KAAK,OAAO,WAAa,IACzB,KAAK,UAAU,GAAG,MAAM;CAC5B,MAAM,QAAQ,KAAK,UAAU,SAAS,CAAC;CACvC,MAAM,UAAU,KAAK,SAAS,OAAO;AACvC;;;;;;;;;;;;;;;;;;;AAoBA,SAAS,QAAQ,OAAiB,OAAuB;CACvD,IAAI,CAAC,MAAM,QAAQ,IACjB;OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KACzB,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK;CAC5B;CAGF,OAAO,MAAM,QAAQ;AACvB"}
@@ -1,4 +1,4 @@
1
- //! @decimalturn/toml-patch v3.1.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
1
+ //! @decimalturn/toml-patch v3.1.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
2
  import { findPosition } from "./location.js";
3
3
  import ParseError from "./parse-error.js";
4
4
 
@@ -1,8 +1,9 @@
1
- //! @decimalturn/toml-patch v3.1.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
1
+ //! @decimalturn/toml-patch v3.1.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
2
  import parseTOML, { continueParsingTOML } from "./parse-toml.js";
3
3
  import { isObject } from "./utils.js";
4
4
  import { decodeUtf8Bytes, hasLeadingBom, stripLeadingBom } from "./decode-utf8.js";
5
5
  import { TomlFormat, detectNewline, resolveTomlFormat } from "./toml-format.js";
6
+ import { attachSources } from "./cst-source.js";
6
7
  import toJS from "./to-js.js";
7
8
  import { patchCst } from "./patch.js";
8
9
  import { truncateCst } from "./truncate.js";
@@ -77,6 +78,7 @@ var TomlDocument = class {
77
78
  }
78
79
  const indentWidthExplicit = format instanceof TomlFormat || format != null && Object.prototype.hasOwnProperty.call(format, "indentWidth");
79
80
  const trailingCommaExplicit = format instanceof TomlFormat || format != null && Object.prototype.hasOwnProperty.call(format, "trailingComma");
81
+ attachSources(this._cst, sourceBefore);
80
82
  const result = patchCst(this._cst, updatedObject, fmt, indentWidthExplicit, trailingCommaExplicit);
81
83
  this._cst = Array.from(parseTOML(result.tomlString));
82
84
  this._format = fmt;
@@ -114,7 +116,10 @@ var TomlDocument = class {
114
116
  const remainingLines = newTextLines.slice(continueFromLine - 1);
115
117
  if (remainingLines.length > 0 && continueFromColumn > 0) remainingLines[0] = remainingLines[0].substring(continueFromColumn);
116
118
  const remainingToml = remainingLines.join(this._format.newLine);
117
- this._cst = Array.from(continueParsingTOML(truncatedCst, remainingToml));
119
+ this._cst = Array.from(continueParsingTOML(truncatedCst, remainingToml, {
120
+ line: continueFromLine,
121
+ column: continueFromColumn
122
+ }));
118
123
  this._currentTomlString = tomlContent;
119
124
  this._format = TomlFormat.autoDetectFormatWithCst(tomlString, this._cst);
120
125
  }