@decimalturn/toml-patch 3.1.1 → 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 (70) 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 +59 -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.js +269 -0
  16. package/dist/dev/diff.js.map +1 -0
  17. package/dist/dev/escape-preference.js +144 -0
  18. package/dist/dev/escape-preference.js.map +1 -0
  19. package/dist/dev/find-by-path.js +111 -0
  20. package/dist/dev/find-by-path.js.map +1 -0
  21. package/dist/dev/formatter.js +298 -0
  22. package/dist/dev/formatter.js.map +1 -0
  23. package/dist/dev/generate.js +451 -0
  24. package/dist/dev/generate.js.map +1 -0
  25. package/dist/dev/inline-comma-space.js +13 -0
  26. package/dist/dev/inline-comma-space.js.map +1 -0
  27. package/dist/dev/inline-format.js +106 -0
  28. package/dist/dev/inline-format.js.map +1 -0
  29. package/dist/dev/inline-layout.js +107 -0
  30. package/dist/dev/inline-layout.js.map +1 -0
  31. package/dist/dev/line-ending-backslash.js +320 -0
  32. package/dist/dev/line-ending-backslash.js.map +1 -0
  33. package/dist/dev/location.js +104 -0
  34. package/dist/dev/location.js.map +1 -0
  35. package/dist/dev/parse-error.js +27 -0
  36. package/dist/dev/parse-error.js.map +1 -0
  37. package/dist/dev/parse-js.js +107 -0
  38. package/dist/dev/parse-js.js.map +1 -0
  39. package/dist/dev/parse-string.js +122 -0
  40. package/dist/dev/parse-string.js.map +1 -0
  41. package/dist/dev/parse-toml.js +714 -0
  42. package/dist/dev/parse-toml.js.map +1 -0
  43. package/dist/dev/patch.js +2540 -0
  44. package/dist/dev/patch.js.map +1 -0
  45. package/dist/dev/to-js.js +303 -0
  46. package/dist/dev/to-js.js.map +1 -0
  47. package/dist/dev/to-toml.js +874 -0
  48. package/dist/dev/to-toml.js.map +1 -0
  49. package/dist/dev/tokenizer.js +225 -0
  50. package/dist/dev/tokenizer.js.map +1 -0
  51. package/dist/dev/toml-document.js +220 -0
  52. package/dist/dev/toml-document.js.map +1 -0
  53. package/dist/dev/toml-format.js +476 -0
  54. package/dist/dev/toml-format.js.map +1 -0
  55. package/dist/dev/toml-patch.js +94 -0
  56. package/dist/dev/toml-patch.js.map +1 -0
  57. package/dist/dev/traverse.js +61 -0
  58. package/dist/dev/traverse.js.map +1 -0
  59. package/dist/dev/truncate.js +64 -0
  60. package/dist/dev/truncate.js.map +1 -0
  61. package/dist/dev/update-order.js +235 -0
  62. package/dist/dev/update-order.js.map +1 -0
  63. package/dist/dev/utils.js +223 -0
  64. package/dist/dev/utils.js.map +1 -0
  65. package/dist/dev/writer.js +758 -0
  66. package/dist/dev/writer.js.map +1 -0
  67. package/package.json +11 -93
  68. package/LICENSE +0 -22
  69. package/README.md +0 -169
  70. package/dist/toml-patch.js +0 -54
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer.js","names":[],"sources":["../../src/writer.ts"],"sourcesContent":["import {\n NodeType,\n TreeNode,\n Document,\n Key,\n Value,\n InlineArray,\n InlineArrayItem,\n InlineTableItem,\n isKeyValue,\n isTable,\n isTableArray,\n isInlineTable,\n isInlineArray,\n hasItems,\n hasItem,\n isComment,\n isDocument,\n InlineTable,\n TableArray,\n TableKey,\n TableArrayKey,\n Table,\n KeyValue,\n Comment,\n InlineItem,\n isInlineItem,\n Block,\n isBlock,\n WithItems\n} from './cst';\nimport { Span, getSpan, clonePosition } from './location';\nimport { last } from './utils';\nimport traverse from './traverse';\nimport { getCommaSpace } from './inline-comma-space';\nimport { DEFAULT_INDENT_WIDTH } from './toml-format';\nimport { markMutation, markTreeDirty } from './cst-source';\nimport { getInlineContainerLayout, isInlineContainerPositioned, markPreservedMultilineEmpty } from './inline-format';\n\n////////////////////////////////////////\n// The purpose of this file is to provide a way to modify the CST\n////////////////////////////////////////\n\n\n// Root node of the CST\nexport type Root = Document | TreeNode;\n\n// Store line and column offsets per node\n//\n// Some offsets are applied on enter (e.g. shift child items and next items)\n// Others are applied on exit (e.g. shift next items)\ntype Offsets = WeakMap<TreeNode, Span>;\n\n// Track which roots have pending offsets to avoid unnecessary applyWrites traversals\nconst dirty_roots: WeakSet<Root> = new WeakSet();\n\n// Roots being built by parseJS (stringify path, not patch).\n// These never contain Comment nodes, never have items removed, and\n// inserts are always sequential — letting us skip patch-only code paths.\nconst stringifyRoots: WeakSet<Root> = new WeakSet();\n\nconst rootIndentWidths: WeakMap<Root, number> = new WeakMap();\nconst inlineIndentColumns: WeakMap<InlineArray | InlineTable, number> = new WeakMap();\n\nexport function setRootIndentWidth(root: Root, indentWidth: number): void {\n rootIndentWidths.set(root, indentWidth);\n}\n\nexport function setInlineIndentColumn(container: InlineArray | InlineTable, column: number): void {\n inlineIndentColumns.set(container, column);\n}\n\n/** Mark a root as being built by parseJS — enables stringify fast paths. */\nexport function markStringifyRoot(root: Root): void {\n stringifyRoots.add(root);\n}\n\n// Track Tables/TableArrays whose last item was removed via remove().\n// Also track whether a non-last removal occurred (multiple items removed).\nconst emptiedByRemove: WeakMap<TreeNode, boolean> = new WeakMap();\nconst hadNonLastRemoval: WeakSet<TreeNode> = new WeakSet();\n\n// Track single-line InlineTables and InlineArrays whose only item was\n// removed, so the caller can tighten the closing bracket and reapply\n// bracket spacing.\nconst inlineContainersNeedingTighten: WeakSet<TreeNode> = new WeakSet();\nexport function hasInlineContainerNeedingTighten(node: TreeNode): boolean {\n return inlineContainersNeedingTighten.has(node);\n}\nexport function deleteInlineContainerNeedingTighten(node: TreeNode): void {\n inlineContainersNeedingTighten.delete(node);\n}\n\n/**\n * Add an exit offset at `node` so that applyWrites shifts everything\n * after the node in depth-first order by `span`. Used by key-truncation\n * in the Edit handler to account for a shortened key without having to\n * manually adjust every downstream position.\n */\nexport function addExitOffset(root: Root, node: TreeNode, span: Span): void {\n addOffset(span, getExitOffsets(root), node);\n}\n\n/** Marks a root so the next applyWrites() walk actually processes it. */\nexport function markDirty(root: Root): void {\n markTreeDirty(root);\n dirty_roots.add(root);\n}\n\nconst enter_offsets: WeakMap<Root, Offsets> = new WeakMap();\nconst getEnterOffsets = (root: Root) => {\n if (!enter_offsets.has(root)) {\n enter_offsets.set(root, new WeakMap());\n }\n return enter_offsets.get(root)!;\n};\n/**\n * The pending enter-offset map for a root. Exposed so callers can detect a\n * block container that still carries a removal's enter offset before\n * inserting at index 0 (fuzz seed 11557: the new row was dragged above\n * line 1 by the unresolved removal shift).\n */\nexport function getPendingEnterOffsets(root: Root): Offsets {\n if (!enter_offsets.has(root)) {\n enter_offsets.set(root, new WeakMap());\n }\n return enter_offsets.get(root)!;\n}\n\nconst exit_offsets: WeakMap<Root, Offsets> = new WeakMap();\n/**\n * The pending exit-offset map for a root. Exposed so moveInlineElement can\n * cancel a removal's offset before it leaks past the container (fuzz seed 900).\n */\nexport function getExitOffsets(root: Root): Offsets {\n if (!exit_offsets.has(root)) {\n exit_offsets.set(root, new WeakMap());\n }\n return exit_offsets.get(root)!;\n}\n\n//TODO: Add getOffsets function to get all offsets contained in the tree\nexport function replace(root: Root, parent: TreeNode, existing: TreeNode, replacement: TreeNode) {\n \n // First, replace existing node\n // (by index for items, item, or key/value)\n if (hasItems(parent)) {\n\n const index = parent.items.indexOf(existing);\n if (index < 0) {\n throw new Error(`Item not found in parent for replace`);\n }\n\n parent.items.splice(index, 1, replacement);\n\n // This next case is a special case for Inline-Table item\n // however due to the fact that both replacement of the whole Inline-Table and Inline-Table element will have the same parent,\n // we need to make sure it's not an Inline-Table \n } else if (isKeyValue(parent) && isInlineTable(parent.value) && !isInlineTable(existing)) {\n \n const index = parent.value.items.indexOf(existing as InlineTableItem);\n if (index < 0) {\n throw new Error(`Item not found in parent for replace`);\n } \n parent.value.items.splice(index, 1, replacement as InlineTableItem);\n\n } else if (hasItem(parent)) {\n\n parent.item = replacement;\n\n } else if (isKeyValue(parent)) {\n\n if (parent.key === existing) {\n parent.key = replacement as Key;\n } else {\n parent.value = replacement as Value;\n }\n\n } else {\n throw new Error(`Unsupported parent type \"${parent.type}\" for replace`);\n }\n\n // Shift the replacement node into the same start position as existing\n const shift = {\n lines: existing.loc.start.line - replacement.loc.start.line,\n columns: existing.loc.start.column - replacement.loc.start.column\n };\n shiftNode(replacement, shift);\n\n // Apply offsets after replacement node\n const existing_span = getSpan(existing.loc);\n const replacement_span = getSpan(replacement.loc);\n const offset = {\n lines: replacement_span.lines - existing_span.lines,\n columns: replacement_span.columns - existing_span.columns\n };\n\n addOffset(offset, getExitOffsets(root), replacement, existing);\n if (!stringifyRoots.has(root)) {\n markMutation(root, parent, replacement);\n }\n dirty_roots.add(root);\n}\n/**\n * Inserts a child node into the CST.\n *\n * @param root - The root node of the CST\n * @param parent - The parent node to insert the child into\n * @param child - The child node to insert\n * @param index - The index at which to insert the child (optional)\n * @param forceInline - Whether to force inline positioning even for document-level insertions (optional)\n */\nexport function insert(root: Root, parent: TreeNode, child: TreeNode, index?: number, forceInline?: boolean, hostItems?: TreeNode[], leadingLines?: number, firstLineOnly = false) {\n if (!hasItems(parent)) {\n throw new Error(`Unsupported parent type \"${(parent as TreeNode).type}\" for insert`);\n }\n\n index = (index != null && typeof index === 'number') ? index : parent.items.length; \n\n let shift: Span;\n let offset: Span;\n if (isInlineArray(parent) || isInlineTable(parent)) {\n ({ shift, offset } = insertInline(parent, child as InlineItem, index, rootIndentWidths.get(root) ?? DEFAULT_INDENT_WIDTH));\n } else if (forceInline && isDocument(parent)) {\n ({ shift, offset } = insertInlineAtRoot(parent, child, index));\n } else {\n ({ shift, offset } = insertOnNewLine(\n root,\n parent as Document | Table | TableArray,\n child as KeyValue | Comment,\n index,\n leadingLines\n ));\n }\n\n shiftNode(child, shift, { first_line_only: firstLineOnly });\n\n // The child element is placed relative to the previous element,\n // if the previous element has an offset, need to position relative to that\n // -> Move previous offset to child's offset\n const previous = parent.items[index - 1];\n const previous_offset = previous && getExitOffsets(root).get(previous);\n if (previous_offset) {\n offset.lines += previous_offset.lines;\n offset.columns += previous_offset.columns;\n\n getExitOffsets(root).delete(previous!);\n }\n\n // Handle orphaned comments for multiline inline table/array inserts (analogous to the\n // remove case below). When a new item is added on a new line inside a multiline inline\n // table or array, the exit offset on the inserted child bleeds to comments that were\n // extracted from inside the container into the enclosing Document/Table's own\n // items (`hostItems` — defaults to `root.items`, correct only when the inline container\n // is itself root-level; pass the real enclosing container's `.items` otherwise).\n // Pre-compensate comments that appear before the insertion line so the bleedthrough\n // leaves them at their original position.\n //\n // Include comments on surviving inline ancestors in the same key's value. Host items\n // also contain comments belonging to other keys, which must remain outside this span.\n if ((isInlineTable(parent) || isInlineArray(parent)) && offset.lines !== 0 && (hostItems || hasItems(root)) && root !== parent) {\n const insertionLine = child.loc.start.line;\n const commentHostItems = hostItems ?? (root as WithItems).items;\n const commentContainer = enclosingInlineValue(parent, commentHostItems);\n for (let i = 0; i < commentHostItems.length; i++) {\n const item = commentHostItems[i];\n if (!isComment(item)) continue;\n const commentLine = (item as Comment).loc.start.line;\n if (commentLine < commentContainer.loc.start.line || commentLine > commentContainer.loc.end.line) continue;\n if (commentLine < insertionLine) {\n (item as Comment).loc.start.line -= offset.lines;\n (item as Comment).loc.end.line -= offset.lines;\n }\n }\n }\n\n const offsets = getExitOffsets(root);\n offsets.set(child, offset);\n // Stringify builds the tree from scratch: nothing ever reads the `dirty`\n // flags, so skip the linkParents + markSubtreeDirty walk entirely.\n if (!stringifyRoots.has(root)) {\n markMutation(root, parent, child);\n }\n dirty_roots.add(root);\n}\n\n// Hoisted comments on surviving ancestors share the edited value's exit offset.\n// Limit compensation to that value, excluding comments belonging to sibling keys.\nfunction enclosingInlineValue(parent: TreeNode, hostItems: TreeNode[]): TreeNode {\n for (const hostItem of hostItems) {\n if (!isKeyValue(hostItem)) continue;\n const value = hostItem.value;\n if (!isInlineArray(value) && !isInlineTable(value)) continue;\n let containsParent = false;\n const findParent = (node: TreeNode) => { if (node === parent) containsParent = true; };\n traverse(value, { InlineArray: findParent, InlineTable: findParent });\n if (containsParent) return value;\n }\n return parent;\n}\n\nfunction insertOnNewLine(\n root: Root,\n parent: Document | Table | TableArray,\n child: Block,\n index: number,\n leadingLinesOverride?: number\n): { shift: Span; offset: Span } {\n\n if (!isBlock(child)) {\n throw new Error(`Incompatible child type \"${(child as TreeNode).type}\"`);\n }\n\n const previous = parent.items[index - 1];\n const use_first_line = isDocument(parent) && !parent.items.length;\n // Inserting at position 0 of a non-empty Document: no previous sibling but the\n // document already has content. The new item lands at line 1 (no leading blank)\n // and all existing items must be shifted down to make room. This happens when a\n // new root-table key-value is prepended before the first explicit section header.\n const prepend_to_document = isDocument(parent) && !use_first_line && previous === undefined;\n\n parent.items.splice(index, 0, child);\n\n // Set start location from the item with the furthest end position among\n // all preceding items (up to index). This handles extracted comments that\n // appear after a KeyValue in the items array but are physically positioned\n // before the KeyValue's closing bracket in the source.\n //\n // Fast path: when the root is a stringify root (parseJS, no comments),\n // the immediate predecessor is the furthest — skip all scanning.\n let furthestPrevious: TreeNode | undefined;\n if (previous !== undefined) {\n if (stringifyRoots.has(root)) {\n furthestPrevious = previous;\n } else {\n let hasComment = false;\n for (let i = 0; i < index; i++) {\n if (isComment(parent.items[i])) { hasComment = true; break; }\n }\n if (!hasComment) {\n furthestPrevious = previous;\n } else {\n let maxEndLine = -1;\n let maxEndColumn = -1;\n for (let i = 0; i < index; i++) {\n const item = parent.items[i];\n const end = item.loc.end;\n if (end.line > maxEndLine || (end.line === maxEndLine && end.column > maxEndColumn)) {\n maxEndLine = end.line;\n maxEndColumn = end.column;\n furthestPrevious = item;\n }\n }\n }\n }\n }\n\n const start = furthestPrevious\n ? {\n line: furthestPrevious.loc.end.line,\n column: !isComment(furthestPrevious) ? furthestPrevious.loc.start.column : parent.loc.start.column\n }\n : clonePosition(parent.loc.start);\n \n const isSquareBracketsStructure = isTable(child) || isTableArray(child);\n let leading_lines = 0;\n if (leadingLinesOverride !== undefined) {\n leading_lines = leadingLinesOverride;\n } else if (use_first_line || prepend_to_document) {\n // 0 leading lines — item starts at line 1\n } else if (isSquareBracketsStructure) {\n leading_lines = 2;\n } else {\n leading_lines = 1;\n }\n start.line += leading_lines;\n\n const shift = {\n lines: start.line - child.loc.start.line,\n columns: start.column - child.loc.start.column\n };\n\n // Apply offsets after child node\n const child_span = getSpan(child.loc);\n // When prepending to a non-empty document, push all existing items down by the\n // new child's physical line count plus one newline separator. The existing\n // items' original leading-lines budget is already encoded in their loc.start.line\n // values, so we only need to account for the space the new child occupies.\n //\n // When inserting the first item into a Table/TableArray that was previously\n // emptied by remove(), decide based on whether multiple items were removed:\n // - Single item: skip the extra blank line (the original separator is intact).\n // - Multiple items: use normal offset (compensates accumulated removal shifts).\n // Track empty/multi-removal state — only needed during patching.\n const wasEmptied = !stringifyRoots.has(root) && previous === undefined\n && (isTable(parent) || isTableArray(parent) || isDocument(parent))\n && emptiedByRemove.has(parent);\n const wasSingleRemoval = wasEmptied && !hadNonLastRemoval.has(parent);\n if (wasEmptied) {\n emptiedByRemove.delete(parent);\n hadNonLastRemoval.delete(parent);\n }\n\n // When multiple items were removed from a table (or the document root),\n // the accumulated removal offset still sits on the parent's key (Table/\n // TableArray) or on the parent itself (Document) and will shift this new\n // child during applyWrites. Cancel it out exactly by shifting the child\n // the opposite amount, rather than assuming a fixed one-line offset. Also\n // skip the blank-line offset (like the single-removal case) to avoid\n // doubled blank lines.\n const needsCompensation = wasEmptied && !wasSingleRemoval;\n let compensation_lines = 0;\n if (needsCompensation) {\n const staleOffset = (isTable(parent) || isTableArray(parent))\n ? getExitOffsets(root).get((parent as Table | TableArray).key)\n : getEnterOffsets(root).get(parent);\n compensation_lines = staleOffset ? -staleOffset.lines : 1;\n }\n // When the container was emptied by remove(), the inserted child reuses the rows\n // the removals vacated, so only its EXTRA lines advance the following content.\n // Cancelling the whole span (`-child_span.lines`) is only correct for a\n // single-line child; a generated multiline inline table spans several lines and\n // its trailing lines would otherwise overlap the next sibling (seed 17339: the\n // following `[b]` header landed on the closing `}` row). This holds for both the\n // single-removal case and the compensated multi-removal case, where the\n // accumulated removal offset is already cancelled out through `shift`.\n const offset_leading = (wasSingleRemoval || needsCompensation)\n ? leading_lines - 2\n : (leading_lines - 1);\n const offset_lines = prepend_to_document\n ? child_span.lines + 1\n : child_span.lines + offset_leading;\n const offset = {\n lines: offset_lines,\n columns: child_span.columns\n };\n\n return { shift: { lines: shift.lines + compensation_lines, columns: shift.columns }, offset };\n}\n\n/**\n * Calculates positioning (shift and offset) for inserting a child into a parent container.\n * This function handles the core positioning logic used to insert an inline item inside a table (or at the document root level).\n * \n * @param parent - The parent container (Document, InlineArray or InlineTable)\n * @param child - The child node to be inserted\n * @param index - The insertion index within the parent's items\n * @param options - Configuration options for positioning calculation\n * @param options.useNewLine - Whether to place the child on a new line\n * @param options.skipCommaSpace - Number of columns to skip for comma + space (default: 2)\n * @param options.skipBracketSpace - Number of columns to skip for bracket/space (default: 1)\n * @param options.hasCommaHandling - Whether comma handling logic should be applied\n * @param options.isLastElement - Whether this is the last element in the container\n * @param options.hasSeparatingCommaBefore - Whether a comma should precede this element\n * @param options.hasSeparatingCommaAfter - Whether a comma should follow this element\n * @param options.hasTrailingComma - Whether the element has a trailing comma\n * @returns Object containing shift (positioning adjustment for the child) and offset (adjustment for following elements)\n */\nfunction calculateInlinePositioning(\n parent: Document | InlineArray | InlineTable,\n child: TreeNode,\n index: number,\n options: {\n useNewLine?: boolean;\n skipCommaSpace?: number;\n skipBracketSpace?: number;\n hasCommaHandling?: boolean;\n isLastElement?: boolean;\n hasSeparatingCommaBefore?: boolean;\n hasSeparatingCommaAfter?: boolean;\n hasTrailingComma?: boolean;\n indentWidth?: number;\n } = {}\n): { shift: Span; offset: Span } {\n \n // Configuration options with default values\n const {\n useNewLine = false,\n skipCommaSpace = 2,\n skipBracketSpace = 1,\n hasCommaHandling = false,\n isLastElement = false,\n hasSeparatingCommaBefore = false,\n hasSeparatingCommaAfter = false,\n hasTrailingComma = false,\n indentWidth = DEFAULT_INDENT_WIDTH\n } = options;\n\n // Store preceding node\n const previous = index > 0 ? parent.items[index - 1] : undefined;\n\n // Set start location from previous item or start of parent\n const start = previous\n ? {\n line: previous.loc.end.line,\n column: useNewLine\n ? !isComment(previous)\n ? previous.loc.start.column\n : parent.loc.start.column\n : previous.loc.end.column\n }\n : clonePosition(parent.loc.start);\n\n // With no previous sibling to line up against, the fallback above is the parent's own\n // opening bracket. On one line that is right, but in a multi-line container the bracket\n // sits at the end of `key = [` — nowhere near where the rows are indented, so a new first\n // row would land under the bracket instead of level with its siblings. Match the row that\n // will follow it instead (skipping comments, whose column is not the row indent).\n //\n // `i > index` rather than `>=`: insertInline() splices `child` in before calling this, so\n // `parent.items[index]` is `child` itself and `>=` would measure the new row against its\n // own pre-shift column. The other caller, insertInlineAtRoot(), splices afterwards but\n // passes useNewLine: false, so it never reaches here.\n if (!previous && useNewLine) {\n const following = (parent.items as TreeNode[]).find(\n (item, i) => i > index && !isComment(item)\n );\n if (following) {\n start.column = following.loc.start.column;\n } else if (parent.loc.end.line > parent.loc.start.line) {\n const preservedColumn = (isInlineArray(parent) || isInlineTable(parent))\n ? inlineIndentColumns.get(parent)\n : undefined;\n start.column = preservedColumn ?? parent.loc.end.column - 1 + indentWidth;\n }\n }\n\n let leading_lines = 0;\n if (useNewLine) {\n leading_lines = 1;\n } else {\n // Add spacing for inline positioning\n const hasSpacing = hasSeparatingCommaBefore || (!hasCommaHandling && !!previous);\n if (hasSpacing && hasCommaHandling) {\n start.column += skipCommaSpace;\n } else if (hasSpacing || (hasCommaHandling && !previous)) {\n start.column += skipBracketSpace;\n }\n }\n start.line += leading_lines;\n\n const shift = {\n lines: start.line - child.loc.start.line,\n columns: start.column - child.loc.start.column\n };\n\n // Apply offsets after child node\n const child_span = getSpan(child.loc);\n \n if (!hasCommaHandling) {\n // For documents or contexts without comma handling, simpler offset calculation\n const offset = {\n lines: child_span.lines + (leading_lines - 1),\n columns: child_span.columns\n };\n return { shift, offset };\n }\n\n // Special case: Fix trailing comma spacing issue for arrays that have trailing commas\n const has_trailing_comma_spacing_bug = \n hasSeparatingCommaBefore && \n hasTrailingComma && \n !hasSeparatingCommaAfter && \n isLastElement; \n\n let trailing_comma_offset_adjustment = 0;\n if (has_trailing_comma_spacing_bug) {\n trailing_comma_offset_adjustment = -1;\n }\n \n let offset_columns = child_span.columns +\n (hasSeparatingCommaBefore || hasSeparatingCommaAfter ? skipCommaSpace : 0) +\n (hasTrailingComma ? 1 + trailing_comma_offset_adjustment : 0);\n\n // When an appended item moves a shared-line closing delimiter onto its new\n // row, preserve the delimiter gap instead of shifting it by the whole item.\n if (useNewLine && isLastElement && previous && parent.loc.end.line === previous.loc.end.line) {\n offset_columns = child_span.columns - (previous.loc.end.column - previous.loc.start.column);\n }\n\n const offset = {\n lines: child_span.lines + (leading_lines - 1),\n columns: offset_columns\n };\n\n return { shift, offset };\n}\n\n/**\n * The horizontal gap a separating comma occupies between two adjacent inline\n * siblings: 1 column for a compact list (`[1,2]`), 2 for a spaced list\n * (`[1, 2]`). Detected once at parse time and stored in a WeakMap registry\n * (`inline-comma-space`), so it stays accurate even after later edits shift\n * the items' own positions. Defaults to 2 (spaced) for containers the parser\n * didn't tag (e.g. values regenerated by parseJS).\n */\nfunction commaSpaceOf(container: InlineArray | InlineTable): number {\n return getCommaSpace(container) ?? 2;\n}\n\nfunction insertInline(\n parent: InlineArray | InlineTable,\n child: InlineItem,\n index: number,\n indentWidth: number\n): { shift: Span; offset: Span } {\n if (!isInlineItem(child)) {\n throw new Error(`Incompatible child type \"${(child as TreeNode).type}\"`);\n }\n\n // Measure the container's own comma spacing BEFORE splicing the child in\n // (the child's loc is still stale and would skew the measurement).\n const skip_comma_space = commaSpaceOf(parent);\n\n // Store preceding node and insert\n const previous = index != null ? parent.items[index - 1] : last(parent.items as TreeNode[]);\n const is_last = index == null || index === parent.items.length;\n const next = index != null ? parent.items[index] : undefined;\n\n parent.items.splice(index, 0, child);\n\n // Add commas as-needed\n const has_separating_comma_before = !!previous;\n const has_separating_comma_after = !is_last;\n if (has_separating_comma_before) {\n (previous as InlineArrayItem | InlineTableItem).comma = true;\n }\n if (has_separating_comma_after) {\n child.comma = true;\n }\n\n // Use new line for arrays/tables that span multiple lines (one item per line).\n // A MULTILINE item (e.g. a multiline string) can end mid-line while the NEXT\n // item continues on that same line — a new-line insert would then land on\n // the following row, inside whatever occupies it (fuzz seed 620: inserting\n // after a multiline string dropped the new item into the next row's nested\n // array). The same hazard exists for a SINGLE-line previous item when the\n // container is shared-line: `previous` and `next` sit on one row while the\n // container's span is inflated by a trailing multiline nested array, so a\n // new-line insert shifts the tail and the move's realignment collapses that\n // nested array (fuzz seed 68861). In both cases stay on the same line as\n // the previous item.\n //\n // The sibling locs must look settled before trusting them: during comment\n // realignment / removal re-inserts `next` can start INSIDE the previous\n // item's span (pending offsets not yet applied) — treating that as\n // \"same line\" corrupts the insert (fuzz seed 203).\n const use_new_line = perLine(parent, child) && !(\n previous && next &&\n next.loc.start.line === previous.loc.end.line &&\n next.loc.start.column >= previous.loc.end.column\n ) && !(\n // Inserting at the end while the closing brace shares the last row's\n // line: a new-line insert would start one line PAST the brace and emit\n // the new row outside the table (`} k = 1` — fuzz seed 3632). Stay\n // on the last row's line instead; the exit offset then pushes the\n // brace down a line.\n getInlineContainerLayout(parent) !== true &&\n isInlineTable(parent) &&\n !next && previous &&\n previous.loc.end.line === parent.loc.end.line\n );\n const has_trailing_comma = is_last && child.comma === true;\n\n return calculateInlinePositioning(parent, child, index, {\n useNewLine: use_new_line,\n skipCommaSpace: skip_comma_space,\n hasCommaHandling: true,\n isLastElement: is_last,\n hasSeparatingCommaBefore: has_separating_comma_before,\n hasSeparatingCommaAfter: has_separating_comma_after,\n hasTrailingComma: has_trailing_comma,\n indentWidth\n });\n}\n\n/**\n * Inserts a child into a Document with inline positioning behavior.\n * This provides inline-style spacing while maintaining Document's Block item types.\n */\nfunction insertInlineAtRoot(\n parent: Document,\n child: TreeNode,\n index: number\n): { shift: Span; offset: Span } {\n // Calculate positioning as if inserting into an inline context\n const result = calculateInlinePositioning(parent, child, index, {\n useNewLine: false,\n hasCommaHandling: false\n });\n \n // Insert the child directly into the Document (as a Block item)\n parent.items.splice(index, 0, child as KeyValue | Comment);\n \n return result;\n}\n\nexport function remove(root: Root, parent: TreeNode, node: TreeNode, hostItems?: TreeNode[]) {\n // Remove an element from the parent's items\n // (supports Document, Table, TableArray, InlineTable, and InlineArray\n //\n // X\n // [ 1, 2, 3 ]\n // ^-^\n // -> Remove element 2 and apply 0,-3 offset to 1\n //\n // [table]\n // a = 1\n // b = 2 # X\n // c = 3\n // -> Remove element 2 and apply -1,0 offset to 1\n if (!hasItems(parent)) {\n throw new Error(`Unsupported parent type \"${parent.type}\" for remove`);\n }\n\n if (!stringifyRoots.has(root)) {\n markMutation(root, parent);\n }\n\n let index = parent.items.indexOf(node);\n if (index < 0) {\n // Try again, looking at child items for nodes like InlineArrayItem\n index = parent.items.findIndex(item => hasItem(item) && item.item === node);\n\n if (index < 0) {\n throw new Error('Node not found in parent for removal');\n }\n\n node = parent.items[index];\n }\n\n const previous = parent.items[index - 1];\n let next = parent.items[index + 1];\n\n // Remove node\n parent.items.splice(index, 1);\n let removed_span = getSpan(node.loc);\n\n // Remove an associated comment that appears on the same line\n //\n // [table]\n // a = 1\n // b = 2 # remove this too\n // c = 3\n //\n // TODO InlineTable - this only applies to comments in Table/TableArray\n if (next && isComment(next) && next.loc.start.line === node.loc.end.line) {\n // Add comment to removed\n removed_span = getSpan({ start: node.loc.start, end: next.loc.end });\n\n // Shift to next item\n // (use same index since node has already been removed)\n next = parent.items[index + 1];\n\n // Remove comment\n parent.items.splice(index, 1);\n }\n\n // For inline tables and arrays, check whether the line should be kept\n const is_inline = previous && isInlineItem(previous) || next && isInlineItem(next);\n // `node.loc.start.line` can be stale when `previous` carries a pending exit\n // offset (e.g. an earlier Edit collapsed a multiline item, leaving a line\n // offset that will pull this node up a line in applyWrites). Compensate so\n // a same-line removal is recognised as such instead of as a full-line\n // removal that shifts the container's closing bracket onto the wrong line\n // (fuzz seed 54607).\n const prevPendingExit = previous ? getExitOffsets(root).get(previous) : undefined;\n const previous_on_same_line = previous &&\n previous.loc.end.line === (node.loc.start.line + (prevPendingExit?.lines ?? 0));\n const next_on_sameLine = next && next.loc.start.line === node.loc.end.line;\n const keep_line = is_inline && (previous_on_same_line || next_on_sameLine);\n\n const offset = {\n lines: -(removed_span.lines - (keep_line ? 1 : 0)),\n // Column offsets only apply when removing inline content on the same line.\n // For block-level removals (entire lines removed), subsequent items on\n // different lines need no column adjustment — only a line shift.\n columns: keep_line ? -removed_span.columns : 0\n };\n\n // A node's span covers the lines it occupies but not the blank line above it, and\n // insertOnNewLine gives a [table]/[[array]] exactly such a separator when placing one\n // (leading_lines = 2). Shifting by the span alone therefore stranded it, so deleting\n // sections one at a time accumulated blank lines.\n //\n // Reclaim it, but only the separator the removed node itself owned. The gap *below* the\n // node belongs to whatever follows — a section carries its own leading blank and must keep\n // it, which is why this cannot simply close the distance to `next`.\n //\n // Skipped when `next` does not genuinely begin below the removed node: a comment hoisted\n // out of a multi-line inline container is filed as a sibling but keeps a loc pointing\n // *inside* the braces, so it can sit within the removed node's own span.\n const isBlockContainer = isDocument(parent) || isTable(parent) || isTableArray(parent);\n if (isBlockContainer && next && !keep_line && next.loc.start.line > node.loc.end.line) {\n const removedIsSection = isTable(node) || isTableArray(node);\n const nextIsSection = isTable(next) || isTableArray(next);\n\n // `previous` is the preceding sibling in items order, which is not necessarily the\n // furthest one physically: a comment hoisted out of a multi-line inline container is\n // filed after the key-value it came from while keeping a loc pointing *inside* the\n // braces. Measuring from it would count the container's own body as blank space and\n // pull `next` up over the closing brace. Take the furthest end line instead, the same\n // anchor insertOnNewLine picks.\n let precedingEndLine = -1;\n for (let i = 0; i < index; i++) {\n const end = parent.items[i].loc.end.line;\n if (end > precedingEndLine) precedingEndLine = end;\n }\n\n // When `previous` already has a pending exit offset (from a prior removal\n // in the same applyChanges batch), `node.loc.start.line` is stale — it\n // hasn't been shifted yet by that offset. The whole point of extra is to\n // measure the physical gap between the furthest preceding item and this\n // section's header, so it must use the post-offset position of `node`.\n // Compensate by adding the pending offset (which is always negative for\n // removals) to `node.loc.start.line` so the gap computation isn't inflated\n // by lines that were already accounted for.\n const prevPendingExit = previous ? getExitOffsets(root).get(previous) : undefined;\n // The removed node itself can also carry a pending exit offset (from an\n // earlier removal in the same applyChanges batch). In the \"nothing\n // above\" branch, `next.loc.start.line` has not been shifted by it yet, so\n // measuring the gap from the pre-offset position double-counts lines the\n // earlier removal already reclaimed and pulls `next` up onto the wrong\n // line (fuzz seed 65785).\n const nodePendingExit = getExitOffsets(root).get(node);\n const extra = previous\n // Only a section carries a leading separator, so only removing one frees a blank line.\n // A key-value sits flush against the line above and frees nothing extra.\n ? (removedIsSection ? (node.loc.start.line + (prevPendingExit?.lines ?? 0)) - precedingEndLine - 1 : 0)\n // Nothing above: `next` is pulled to the top of the container, where the separator it\n // was carrying becomes a spurious leading blank.\n : (nextIsSection ? (next.loc.start.line + (nodePendingExit?.lines ?? 0)) - node.loc.end.line - 1 : 0);\n if (extra > 0) offset.lines -= extra;\n }\n\n // If there is nothing left, don't perform any offsets.\n //\n // Exception: multiline inline containers (InlineTable / InlineArray whose opening\n // and closing brackets are on different lines). For those, `offset.lines` must\n // stay intact so that `applyWrites` shifts the closing bracket up to close the\n // gap left by the removed item. Single-line containers are fine to zero because\n // the bracket is on the same line as the (now-gone) item.\n //\n // Further exception: when the removed item STARTED on the container's own\n // bracket line (the first item of a multiline inline container), the item's\n // inclusive span counts that shared line too — shifting by the full span\n // would drag the closing bracket ABOVE the container and into the previous\n // row (fuzz seed 5522: `ecq = [\"\"\"…\"\"\"]` emptied, the bracket escaped into\n // the preceding key-value). Zero it like the single-line case and let the\n // caller tighten the emptied container to `[]`/`{}`.\n const isMultilineInlineContainer =\n (isInlineTable(parent) || isInlineArray(parent)) &&\n parent.loc.end.line > parent.loc.start.line;\n const emptiedFromContainerLine =\n isMultilineInlineContainer &&\n node.loc.start.line === parent.loc.start.line;\n\n // A multiline inline container whose only item sat on its own interior row\n // and whose closing delimiter had a row of its own: keep those two rows so\n // the source layout survives the removal. The removal offset below is left\n // intact (the container is not marked for tightening), and the renderer\n // emits the closing row for the marked container.\n const preservesMultilineLayout =\n isMultilineInlineContainer &&\n !emptiedFromContainerLine &&\n previous === undefined &&\n next === undefined &&\n node.loc.start.line > parent.loc.start.line &&\n parent.loc.end.line > node.loc.end.line;\n if (preservesMultilineLayout) {\n markPreservedMultilineEmpty(parent as InlineArray | InlineTable);\n }\n\n if (\n previous === undefined &&\n next === undefined &&\n (!isMultilineInlineContainer || emptiedFromContainerLine)\n ) {\n offset.lines = 0;\n offset.columns = 0;\n\n // When the only item is removed from a single-line InlineTable or\n // InlineArray, mark it so the caller can tighten the closing bracket\n // later. The exit offset that carried the bracket spacing was on the\n // removed item and is now lost. Multiline containers whose only item\n // started on the bracket line are marked too (see above).\n if (isInlineTable(parent) || isInlineArray(parent)) {\n inlineContainersNeedingTighten.add(parent);\n }\n\n // When a Table, TableArray, or the root Document becomes completely\n // empty, mark it.\n if (isTable(parent) || isTableArray(parent) || isDocument(parent)) {\n emptiedByRemove.set(parent, true);\n }\n }\n\n // Track non-last removals from Tables/TableArrays/Document so insertOnNewLine\n // knows whether multiple items were removed (needs compensation).\n if (!(previous === undefined && next === undefined)\n && (isTable(parent) || isTableArray(parent) || isDocument(parent))) {\n hadNonLastRemoval.add(parent);\n }\n\n // Offset for comma and remove comma that appear in front of the element (if-needed).\n // The comma occupies 1 column in a compact list (`[1,2]`) and 2 in a spaced list\n // (`[1, 2]`); read the container's parse-time spacing instead of assuming \", \".\n const removed_comma_gap =\n (isInlineArray(parent) || isInlineTable(parent))\n ? commaSpaceOf(parent as InlineArray | InlineTable)\n : 2;\n\n if (is_inline && previous_on_same_line) {\n offset.columns -= removed_comma_gap;\n }\n\n // If first element in array/inline-table, remove space for comma and space after element.\n // For single-line inline containers the next item shifts left to fill the gap.\n // For multiline (perLine) containers items live on their own lines, so no column\n // adjustment is needed — and applying one would corrupt the column tracking for\n // any root-level node (e.g. an extracted comment) that lands on the opening-brace line.\n if (is_inline && !previous && next) {\n if (!perLine(parent as InlineArray)) {\n offset.columns -= removed_comma_gap;\n }\n }\n\n if (is_inline && previous && !next) {\n // When removing the last element, preserve trailing comma preference\n // If the removed element had a trailing comma, transfer it to the new last element\n const removedHadTrailingComma = (node as InlineArrayItem | InlineTableItem).comma;\n if (removedHadTrailingComma) {\n (previous as InlineArrayItem | InlineTableItem).comma = true;\n } else {\n (previous as InlineArrayItem | InlineTableItem).comma = false;\n }\n\n // The container's closing bracket moves to right after the REMAINING\n // previous item, so the column shift is the end-to-end gap — not the\n // removed item's width, which is wrong when the previous item is\n // multiline and ends AFTER the removed item's stale start (fuzz seed\n // 706: the bracket slid inside the preceding nested array).\n //\n // When `previous` carries a pending exit offset (e.g. it was just\n // replaced by an Edit in the same applyChanges batch), `node.loc.end`\n // is still pre-shift — the raw gap measures across the stale distance.\n // Compensate with the pending column shift so the bracket lands right\n // after the surviving item (fuzz seed 12237: a nested array edit plus\n // a last-item removal spliced `,false,b` into a neighbouring string).\n if (previous_on_same_line) {\n const pendingPrevColumns = previous ? (getExitOffsets(root).get(previous)?.columns ?? 0) : 0;\n offset.columns = previous.loc.end.column - node.loc.end.column - pendingPrevColumns;\n }\n }\n\n // Apply offsets after preceding node or before remaining siblings.\n //\n // When the first item of a Table or TableArray is removed, we must NOT place\n // the enter offset on the parent — that would shift the table's key header\n // (which is visited before the items) by the removal offset, corrupting\n // its position (e.g. shifting it to line 0). Instead, place the offset as\n // an EXIT offset on the parent's key: the key itself is processed first\n // (unaffected), and the offset takes effect for the subsequently visited items.\n let target: TreeNode;\n let target_offsets: WeakMap<TreeNode, { lines: number; columns: number }>;\n\n if (previous) {\n target = previous;\n target_offsets = getExitOffsets(root);\n } else if ((isTable(parent) || isTableArray(parent)) && 'key' in parent) {\n target = (parent as Table | TableArray).key;\n target_offsets = getExitOffsets(root);\n } else {\n target = parent;\n target_offsets = getEnterOffsets(root);\n }\n const node_offsets = getExitOffsets(root);\n const previous_offset = target_offsets.get(target);\n if (previous_offset) {\n offset.lines += previous_offset.lines;\n offset.columns += previous_offset.columns;\n }\n const removed_offset = node_offsets.get(node);\n if (removed_offset) {\n offset.lines += removed_offset.lines;\n // Column offsets only matter when the removed node shared its line with\n // following inline content. Folding them into a block-level removal\n // shifts whole subsequent lines sideways — e.g. moving a freshly\n // replaced Table (which carries replace()'s column delta) to the end of\n // the document indented the next root KV by the table's width (fuzz\n // seed 590).\n if (keep_line) offset.columns += removed_offset.columns;\n }\n\n target_offsets.set(target, offset);\n dirty_roots.add(root);\n\n // Handle orphaned comments for multiline inline tables/arrays.\n //\n // When a TOML 1.1 multiline inline container is parsed, comments inside it are emitted into\n // the enclosing Document/Table's own items (`hostItems` — the container whose `.items` the\n // parser actually filed them under, which is `root.items` only when the inline container is\n // itself a ROOT-level key; a nested `[table]`'s array instead files them into that Table's\n // own items) rather than into the InlineTable/InlineArray's own items. The line-count offset\n // placed above (on `target`) bleeds through the rest of that container's traversal in\n // applyWrites, shifting every subsequent sibling item by `offset.lines`. That is correct for\n // comments AFTER the deleted line (they should shift up), but wrong for comments BEFORE the\n // deleted line (they must stay put), and comments ON the deleted line must be removed.\n //\n // Fix: for host-level comments that sit before the removed line, pre-shift them in the\n // opposite direction so that the bleedthrough restores them to their original position.\n // Comments on the deleted line are removed from `hostItems` entirely.\n //\n // `hostItems` defaults to `root.items` (the historical behavior, correct only when the\n // inline container is root-level); callers that know the real enclosing container — e.g.\n // comment-ownership.ts's findHostContainer() — should pass its `.items` explicitly so this\n // scans the array the comments actually live in, not always literally the document root.\n //\n // Scope: only multiline inline tables. For single-line inline tables the parser does NOT\n // extract comments into the host — any comment after `{ ... }` on the same line stays as a\n // host-level item but is NOT associated with the inline table's items, so the\n // `commentLine === removedLine` drop would incorrectly delete it.\n //\n // Compensate through the enclosing inline value, as in insert(), excluding\n // comments belonging to other keys in the host.\n if (isMultilineInlineContainer && (hostItems || hasItems(root)) && root !== parent) {\n const removedLine = node.loc.start.line;\n const commentHostItems = hostItems ?? (root as WithItems).items;\n const commentContainer = enclosingInlineValue(parent, commentHostItems);\n const toRemove: number[] = [];\n\n for (let i = 0; i < commentHostItems.length; i++) {\n const item = commentHostItems[i];\n if (!isComment(item)) continue;\n const commentLine = (item as Comment).loc.start.line;\n if (commentLine < commentContainer.loc.start.line || commentLine > commentContainer.loc.end.line) continue;\n if (commentLine === removedLine &&\n (commentLine < parent.loc.end.line || item.loc.start.column < parent.loc.end.column)) {\n // Only a same-line comment before the closing delimiter can belong to the removed item.\n toRemove.push(i);\n } else if (offset.lines !== 0 && commentLine < removedLine) {\n // Comment is before the removed line: pre-compensate so the bleedthrough\n // offset applied during applyWrites leaves it at its original position.\n (item as Comment).loc.start.line -= offset.lines;\n (item as Comment).loc.end.line -= offset.lines;\n }\n // Comments after removedLine: bleedthrough is already the correct shift.\n }\n\n for (let i = toRemove.length - 1; i >= 0; i--) {\n commentHostItems.splice(toRemove[i], 1);\n }\n }\n}\n\n/**\n * Recalculates a container's end position as the max of its key (for Table/\n * TableArray) and all its children's ends. Necessary because the offset-based\n * shiftEnd approach can produce wrong container ends when a block-level child\n * is removed: the column offset for the removed line bleeds into the previous\n * sibling's line after the line-count shift, causing the container end to\n * shrink below its remaining children.\n */\nexport function recalcContainerEnd(container: Document | Table | TableArray) {\n let endLine = container.loc.start.line;\n let endCol = container.loc.start.column;\n\n // Include the key for Table and TableArray\n if ('key' in container) {\n const ke = (container as Table | TableArray).key.loc.end;\n if (ke.line > endLine || (ke.line === endLine && ke.column > endCol)) {\n endLine = ke.line;\n endCol = ke.column;\n }\n }\n\n for (let i = 0; i < container.items.length; i++) {\n const e = container.items[i].loc.end;\n if (e.line > endLine || (e.line === endLine && e.column > endCol)) {\n endLine = e.line;\n endCol = e.column;\n }\n }\n\n container.loc.end = { line: endLine, column: endCol };\n}\n\nexport function applyBracketSpacing(\n root: Root,\n node: InlineArray | InlineTable,\n bracket_spacing: boolean = true\n) {\n // Can only add bracket spacing currently\n if (!bracket_spacing) return;\n if (!node.items.length) return;\n\n // Apply enter to node so that items are affected\n addOffset({ lines: 0, columns: 1 }, getEnterOffsets(root), node);\n\n // Apply exit to last node in items\n const last_item = last(node.items as TreeNode[])!;\n addOffset({ lines: 0, columns: 1 }, getExitOffsets(root), last_item);\n dirty_roots.add(root);\n}\n\nexport function applyTrailingComma(\n root: Root,\n node: InlineArray | InlineTable,\n trailing_commas: boolean = false\n) {\n // Can only add trailing comma currently\n if (!trailing_commas) return;\n if (!node.items.length) return;\n\n const last_item = last(node.items)!;\n last_item.comma = true;\n\n addOffset({ lines: 0, columns: 1 }, getExitOffsets(root), last_item);\n dirty_roots.add(root);\n}\n\n/**\n * Applies all accumulated write offsets (enter and exit) to the given CST node.\n * This function adjusts the start and end locations of each node in the tree based on\n * the offsets stored in the `enter` and `exit` maps. It ensures that the tree's location\n * data is consistent after modifications.\n *\n * @param root - The root node of the CST tree to which the write offsets will be applied.\n */\nexport function applyWrites(root: TreeNode) {\n if (!dirty_roots.has(root)) return;\n\n const enter = getEnterOffsets(root);\n const exit = getExitOffsets(root);\n\n let offsetLines = 0;\n const offsetColumns: { [index: number]: number } = {};\n\n // Inline shift helpers — access loc directly to keep V8 ICs monomorphic\n // (the generic traverse version passes many node shapes through the same\n // function, causing megamorphic inline caches)\n\n function visitNode(node: TreeNode) {\n switch (node.type) {\n case NodeType.Document: {\n const doc = node as Document;\n shiftLoc(doc);\n for (let i = 0; i < doc.items.length; i++) visitNode(doc.items[i]);\n shiftEnd(doc);\n recalcContainerEnd(doc);\n break;\n }\n case NodeType.Table: {\n const tbl = node as Table;\n shiftLoc(tbl);\n visitNode(tbl.key);\n for (let i = 0; i < tbl.items.length; i++) visitNode(tbl.items[i]);\n shiftEnd(tbl);\n recalcContainerEnd(tbl);\n break;\n }\n case NodeType.TableArray: {\n const ta = node as TableArray;\n shiftLoc(ta);\n visitNode(ta.key);\n for (let i = 0; i < ta.items.length; i++) visitNode(ta.items[i]);\n shiftEnd(ta);\n recalcContainerEnd(ta);\n break;\n }\n case NodeType.TableKey: {\n const tk = node as TableKey;\n shiftLoc(tk);\n visitNode(tk.item);\n shiftEnd(tk);\n break;\n }\n case NodeType.TableArrayKey: {\n const tak = node as TableArrayKey;\n shiftLoc(tak);\n visitNode(tak.item);\n shiftEnd(tak);\n break;\n }\n case NodeType.KeyValue: {\n const kv = node as KeyValue;\n // Special enter: adjust equals position before shifting\n const startLine = kv.loc.start.line + offsetLines;\n const keyExit = exit.get(kv.key);\n kv.equals += (offsetColumns[startLine] || 0) + (keyExit ? keyExit.columns : 0);\n shiftLoc(kv);\n // Children\n visitNode(kv.key);\n visitNode(kv.value);\n shiftEnd(kv);\n break;\n }\n case NodeType.InlineArray: {\n const ia = node as InlineArray;\n // Fast path: no offsets on this subtree — skip WeakMap lookups.\n if (!enter.get(ia) && !exit.get(ia)) {\n shiftPositionsNoOffsets(ia);\n for (let i = 0; i < ia.items.length; i++) visitNode(ia.items[i]);\n shiftPositionsNoOffsetsEnd(ia);\n break;\n }\n shiftLoc(ia);\n for (let i = 0; i < ia.items.length; i++) visitNode(ia.items[i]);\n shiftEnd(ia);\n break;\n }\n case NodeType.InlineTable: {\n const it = node as InlineTable;\n if (!enter.get(it) && !exit.get(it)) {\n shiftPositionsNoOffsets(it);\n for (let i = 0; i < it.items.length; i++) visitNode(it.items[i]);\n shiftPositionsNoOffsetsEnd(it);\n break;\n }\n shiftLoc(it);\n for (let i = 0; i < it.items.length; i++) visitNode(it.items[i]);\n shiftEnd(it);\n break;\n }\n case NodeType.InlineItem: {\n const ii = node as InlineItem;\n shiftLoc(ii);\n visitNode(ii.item);\n shiftEnd(ii);\n break;\n }\n // Leaf nodes — no children\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 shiftLoc(node);\n shiftEnd(node);\n break;\n default:\n throw new Error(`Unrecognized node type \"${(node as any).type}\"`);\n }\n }\n\n function shiftLoc(node: TreeNode) {\n node.loc.start.line += offsetLines;\n const colOff = offsetColumns[node.loc.start.line] || 0;\n node.loc.start.column += colOff;\n\n const entering = enter.get(node);\n if (entering) {\n offsetLines += entering.lines;\n offsetColumns[node.loc.start.line] =\n (offsetColumns[node.loc.start.line] || 0) + entering.columns;\n }\n }\n\n function shiftEnd(node: TreeNode) {\n node.loc.end.line += offsetLines;\n const colOff = offsetColumns[node.loc.end.line] || 0;\n node.loc.end.column += colOff;\n\n const exiting = exit.get(node);\n if (exiting) {\n offsetLines += exiting.lines;\n offsetColumns[node.loc.end.line] =\n (offsetColumns[node.loc.end.line] || 0) + exiting.columns;\n }\n }\n\n // Simplified shift helpers for clean subtrees — apply accumulated\n // offsets without checking for enter/exit offsets (there are none).\n function shiftPositionsNoOffsets(node: TreeNode) {\n node.loc.start.line += offsetLines;\n node.loc.start.column += (offsetColumns[node.loc.start.line] || 0);\n }\n\n function shiftPositionsNoOffsetsEnd(node: TreeNode) {\n node.loc.end.line += offsetLines;\n node.loc.end.column += (offsetColumns[node.loc.end.line] || 0);\n }\n\n visitNode(root);\n\n // Mark as clean and clear offset maps only after successful traversal\n dirty_roots.delete(root);\n enter_offsets.delete(root);\n exit_offsets.delete(root);\n}\n\nexport function shiftNode(\n node: TreeNode,\n span: Span,\n options: { first_line_only?: boolean; shift_generated_multiline_end?: boolean } = {}\n): TreeNode {\n const { lines, columns } = span;\n\n // Early return for no-op shifts\n if (lines === 0 && columns === 0) return node;\n\n const {\n first_line_only = false,\n shift_generated_multiline_end = false\n } = options;\n const start_line = node.loc.start.line;\n\n // Fast path for leaf nodes (no children to traverse)\n const type = node.type;\n if (type === NodeType.Key || type === NodeType.String ||\n type === NodeType.Integer || type === NodeType.Float ||\n type === NodeType.Boolean || type === NodeType.DateTime ||\n type === NodeType.Comment) {\n if (!first_line_only || node.loc.start.line === start_line) {\n node.loc.start.column += columns;\n // Only shift end.column when start and end are on the same line.\n // For multiline strings the end is on a completely different line, so its\n // column is an absolute position independent of where the node starts.\n if (node.loc.end.line === node.loc.start.line) {\n node.loc.end.column += columns;\n }\n }\n node.loc.start.line += lines;\n node.loc.end.line += lines;\n return node;\n }\n\n // Fast path for KeyValue with a leaf value (most common case in stringify).\n // Handles KeyValue → Key → leaf without function call / switch overhead.\n if (type === NodeType.KeyValue) {\n const kv = node as KeyValue;\n const valType = kv.value.type;\n if (valType === NodeType.String || valType === NodeType.Integer ||\n valType === NodeType.Float || valType === NodeType.Boolean ||\n valType === NodeType.DateTime) {\n const onFirstLine = !first_line_only || kv.loc.start.line === start_line;\n // Move KeyValue\n if (onFirstLine) {\n kv.loc.start.column += columns;\n // Same-line guard: a multiline string value puts the KV's end on a\n // different line, whose column must not move with the start.\n if (kv.loc.end.line === kv.loc.start.line) {\n kv.loc.end.column += columns;\n }\n }\n kv.loc.start.line += lines;\n kv.loc.end.line += lines;\n if (onFirstLine) {\n kv.equals += columns;\n }\n // Move Key\n const key = kv.key;\n if (!first_line_only || key.loc.start.line === start_line) {\n key.loc.start.column += columns;\n key.loc.end.column += columns;\n }\n key.loc.start.line += lines;\n key.loc.end.line += lines;\n // Move leaf Value\n const val = kv.value;\n if (!first_line_only || val.loc.start.line === start_line) {\n val.loc.start.column += columns;\n if (val.loc.end.line === val.loc.start.line) {\n val.loc.end.column += columns;\n }\n }\n val.loc.start.line += lines;\n val.loc.end.line += lines;\n return node;\n }\n }\n\n // Generic path: full traverse for complex nodes\n const move = (node: TreeNode) => {\n if (!first_line_only || node.loc.start.line === start_line) {\n node.loc.start.column += columns;\n // Only shift end.column when start and end are on the same line:\n // for a multi-line node the end is on a completely different line and\n // its column is an absolute position independent of the start line.\n //\n // Exception: containers built by parseJS carry coordinates relative to\n // the origin (line 1, column 0), so their end column must follow the\n // node even when the span is multi-line. That covers compact containers\n // whose span is stretched by a MULTILINE descendant (`{b = {c = {…}}}`)\n // as well as the multiline containers themselves, hence the\n // `!== undefined` (generated) rather than `=== true` (multiline) test.\n const generatedMultilineEnd = (!first_line_only || shift_generated_multiline_end) &&\n node.loc.end.line !== node.loc.start.line &&\n (((isInlineArray(node) || isInlineTable(node)) &&\n getInlineContainerLayout(node) !== undefined &&\n !isInlineContainerPositioned(node)) ||\n isInlineItem(node) &&\n ((isInlineArray(node.item) || isInlineTable(node.item)) &&\n getInlineContainerLayout(node.item) !== undefined &&\n !isInlineContainerPositioned(node.item) ||\n isKeyValue(node.item) &&\n (isInlineArray(node.item.value) || isInlineTable(node.item.value)) &&\n getInlineContainerLayout(node.item.value) !== undefined &&\n !isInlineContainerPositioned(node.item.value)) ||\n isKeyValue(node) &&\n (isInlineArray(node.value) || isInlineTable(node.value)) &&\n getInlineContainerLayout(node.value) !== undefined);\n if (node.loc.end.line === node.loc.start.line || generatedMultilineEnd) {\n node.loc.end.column += columns;\n }\n }\n node.loc.start.line += lines;\n node.loc.end.line += lines;\n };\n\n traverse(node, {\n [NodeType.Table]: move,\n [NodeType.TableKey]: move,\n [NodeType.TableArray]: move,\n [NodeType.TableArrayKey]: move,\n [NodeType.KeyValue](node) {\n const onFirstLine = !first_line_only || node.loc.start.line === start_line;\n move(node);\n if (onFirstLine) {\n node.equals += columns;\n }\n },\n [NodeType.Key]: move,\n [NodeType.String]: move,\n [NodeType.Integer]: move,\n [NodeType.Float]: move,\n [NodeType.Boolean]: move,\n [NodeType.DateTime]: move,\n [NodeType.InlineArray]: move,\n [NodeType.InlineItem]: move,\n [NodeType.InlineTable]: move,\n [NodeType.Comment]: move\n });\n\n return node;\n}\n\n/**\n * Answers \"is this container laid out with one item per row?\" for insertion\n * decisions. Rows are inferred from the items' START lines, so a container\n * whose next item continues on a MULTILINE item's end line still counts as\n * per-row here. Callers must handle that shape themselves: `insert` suppresses\n * the new line when `next` starts on `previous`'s end line (fuzz seed 620).\n *\n * Structural layout decisions (`'parent'`, multiline formatting) must not use\n * this loose answer. They use `hasStructuralMultilineRows`, which compares each\n * item's start line against the previous item's END line.\n */\nexport function perLine(array: InlineArray | InlineTable, excluded?: TreeNode): boolean {\n const layout = getInlineContainerLayout(array);\n if (layout === true) return true;\n if (layout !== undefined) return false;\n if (!array.items.length) return false;\n\n const items = excluded ? array.items.filter(item => item !== excluded) : array.items;\n if (!items.length) return array.loc.end.line > array.loc.start.line;\n const startsOnSeparateLines = array.loc.end.line > array.loc.start.line && items.every((item, index) =>\n index === 0 || item.loc.start.line > items[index - 1].loc.start.line\n );\n return startsOnSeparateLines;\n}\n\nfunction addOffset(offset: Span, offsets: Offsets, node: TreeNode, from?: TreeNode) {\n const previous_offset = offsets.get(from || node);\n if (previous_offset) {\n offset.lines += previous_offset.lines;\n offset.columns += previous_offset.columns;\n }\n\n offsets.set(node, offset);\n}\n"],"mappings":";;;;;;;;;;AAsDA,MAAM,8BAA6B,IAAI,QAAQ;AAK/C,MAAM,iCAAgC,IAAI,QAAQ;AAElD,MAAM,mCAA0C,IAAI,QAAQ;AAC5D,MAAM,sCAAkE,IAAI,QAAQ;AAEpF,SAAgB,mBAAmB,MAAY,aAA2B;CACxE,iBAAiB,IAAI,MAAM,WAAW;AACxC;AAEA,SAAgB,sBAAsB,WAAsC,QAAsB;CAChG,oBAAoB,IAAI,WAAW,MAAM;AAC3C;;AAGA,SAAgB,kBAAkB,MAAkB;CAClD,eAAe,IAAI,IAAI;AACzB;AAIA,MAAM,kCAA8C,IAAI,QAAQ;AAChE,MAAM,oCAAuC,IAAI,QAAQ;AAKzD,MAAM,iDAAoD,IAAI,QAA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,QAAQ,MAAM,OAAO,MAAM,UAC5F,UAAU,KAAK,KAAK,IAAI,MAAM,OAAO,MAAM,QAAQ,EAAE,CAAC,IAAI,MAAM,IAClE;AAEF;AAEA,SAAS,UAAU,QAAc,SAAkB,MAAgB,MAAiB;CAClF,MAAM,kBAAkB,QAAQ,IAAI,QAAQ,IAAI;CAChD,IAAI,iBAAiB;EACnB,OAAO,SAAS,gBAAgB;EAChC,OAAO,WAAW,gBAAgB;CACpC;CAEA,QAAQ,IAAI,MAAM,MAAM;AAC1B"}
package/package.json CHANGED
@@ -1,112 +1,30 @@
1
1
  {
2
2
  "name": "@decimalturn/toml-patch",
3
- "version": "3.1.1",
4
- "contributors": [
5
- "Tim Hall <tim.hall.engr@gmail.com>",
6
- "Martin Leduc <31558169+DecimalTurn@users.noreply.github.com>"
7
- ],
8
- "license": "MIT",
3
+ "version": "3.1.2-dev",
9
4
  "description": "Patch, parse, and stringify TOML while preserving comments, whitespace and formatting.",
10
5
  "homepage": "https://github.com/DecimalTurn/toml-patch",
11
6
  "repository": {
12
7
  "type": "git",
13
8
  "url": "git+https://github.com/DecimalTurn/toml-patch.git"
14
9
  },
15
- "publishConfig": {
16
- "access": "public"
17
- },
18
- "keywords": [
19
- "toml",
20
- "patch",
21
- "edit",
22
- "parse",
23
- "stringify",
24
- "parser",
25
- "encoder",
26
- "decoder",
27
- "preserve-whitespace",
28
- "preserve-comments",
29
- "preserve-formatting",
30
- "edit-in-place"
31
- ],
10
+ "license": "MIT",
11
+ "type": "module",
32
12
  "engines": {
33
13
  "node": ">=16"
34
14
  },
35
- "type": "module",
36
15
  "sideEffects": false,
37
16
  "types": "./dist/toml-patch.d.ts",
17
+ "files": [
18
+ "dist/"
19
+ ],
38
20
  "exports": {
39
21
  ".": {
40
22
  "types": "./dist/toml-patch.d.ts",
41
- "import": "./dist/toml-patch.js",
42
- "default": "./dist/toml-patch.js"
23
+ "import": "./dist/dev/toml-patch.js",
24
+ "default": "./dist/dev/toml-patch.js"
43
25
  }
44
26
  },
45
- "devDependencies": {
46
- "@decimalturn/toml-patch": "npm:@decimalturn/toml-patch@3.1.0",
47
- "@js-temporal/polyfill": "^0.5.1",
48
- "@playwright/test": "^1.59.1",
49
- "@types/dedent": "^0.7.2",
50
- "@types/js-yaml": "^4.0.0",
51
- "@types/node": "^24.12.3",
52
- "benchmark": "^2",
53
- "dedent": "^1.5.3",
54
- "glob": "^13.0.0",
55
- "js-yaml": "4.3.2",
56
- "jsr": "^0.14.0",
57
- "mri": "^1",
58
- "npm-run-all2": "^9.0.0",
59
- "oxlint": "^1.55.0",
60
- "rimraf": "^6.0.0",
61
- "smol-toml": "^1.6.1",
62
- "tsdown": "^0.23.0",
63
- "tslib": "^2.0.0",
64
- "typescript": "7.0.2",
65
- "vitest": "^5.0.0"
66
- },
67
- "prettier": {
68
- "singleQuote": true,
69
- "printWidth": 100
70
- },
71
- "files": [
72
- "dist/toml-patch.*"
73
- ],
74
- "json-comments": {
75
- "tips": "Please install the JsonComments plugin to enable commenting functionality for JSON files, see: https://github.com/zhangfisher/json_comments_extension",
76
- "package.json": {
77
- "devDependencies.js-yaml": "Used by specs/specs.test.ts to parse YAML expected-value fixtures from submodules/spec-tests (https://github.com/iarna/toml-spec-tests)."
78
- }
79
- },
80
- "scripts": {
81
- "dev": "pnpm run typecheck && pnpm run build && npm-run-all2 --parallel test:all specs",
82
- "test": "vitest run",
83
- "test:output": "node scripts/test-debug.mjs",
84
- "test:js": "vitest run --config vitest.js.config.ts",
85
- "test:watch": "vitest",
86
- "test:go": "./run-toml-test.bash",
87
- "test:playwright": "playwright test",
88
- "playwright:install": "playwright install --with-deps chromium",
89
- "test:all": "pnpm run test && pnpm run test:js && pnpm run test:playwright",
90
- "typecheck": "tsc",
91
- "specs": "vitest run --config vitest.specs.config.ts",
92
- "benchmark": "npm-run-all2 bench:*",
93
- "benchmark:ci": "npm-run-all2 \"bench:* -- --sample --versions latest\"",
94
- "benchmark:smol": "node benchmark/smol-benchmark.mjs",
95
- "fuzz": "npx -y tsx scripts/fuzz-run.ts --seed 0 --to 9999 --mutations 3 --progress 100",
96
- "seed-toml": "npx -y tsx scripts/generate-seed-toml.ts",
97
- "fuzz2": "npx -y tsx scripts/fuzz-run2.ts --seed 0 --to 9999 --mutations 3",
98
- "fuzz3": "npx -y tsx scripts/fuzz-run3.ts --seed 0 --to 9999 --mutations 3",
99
- "bench:parse": "node benchmark/parse-benchmark.mjs",
100
- "bench:stringify": "node benchmark/stringify-benchmark.mjs",
101
- "profile": "node benchmark/profile.mjs",
102
- "build": "rimraf dist && tsdown",
103
- "build:demo": "node scripts/build-demo.mjs",
104
- "build:dev": "node scripts/prepare-dev-package.mjs",
105
- "test:dev": "pnpm run build:dev && node scripts/test-dev-package.mjs",
106
- "lint": "oxlint",
107
- "lint:fix": "oxlint --fix",
108
- "check-overrides": "node scripts/check-overrides.mjs",
109
- "compare-branch-size": "node scripts/compare-branch-size.mjs",
110
- "publish:jsr": "jsr publish --allow-dirty"
27
+ "publishConfig": {
28
+ "access": "public"
111
29
  }
112
- }
30
+ }
package/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2019–2025 Tim Hall
4
- Copyright (c) 2025 Martin Leduc
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in all
14
- copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.
package/README.md DELETED
@@ -1,169 +0,0 @@
1
- <img src="assets/toml-patch-logo.png" alt="toml-patch logo" width="120"/>
2
-
3
- # toml-patch
4
-
5
- [![NPM Version](https://img.shields.io/npm/v/%40decimalturn%2Ftoml-patch?logo=npm&logoColor=white&labelColor=red&color=blue)](https://www.npmjs.com/package/@decimalturn/toml-patch)
6
- [![JSR Version](https://img.shields.io/jsr/v/%40decimalturn/toml-patch?logo=jsr&color=blue)](https://jsr.io/@decimalturn/toml-patch)
7
- [![GitHub branch status](https://img.shields.io/github/check-runs/DecimalTurn/toml-patch/latest)](https://github.com/DecimalTurn/toml-patch/actions/workflows/test-and-build.yml)
8
-
9
- Patch, parse, and stringify [TOML](https://toml.io/en/) (v1.1.0) while preserving comments and formatting.
10
-
11
- This project started as a fork of the [original toml-patch](https://github.com/timhall/toml-patch) but has since evolved into a standalone project with significant improvements in reliability and features. We've added TOML v1.1 support, introduced new APIs like `TomlDocument` and `TomlFormat` classes, fixed numerous bugs through increase in testing namely with [toml-test](https://github.com/toml-lang/toml-test).
12
-
13
- We hope that these improvements can be incorporated upstream one day if the original author returns, but until then, this project is the actively maintained version.
14
-
15
- ## Documentation
16
-
17
- - [Installation](#installation)
18
- - [API](#api)
19
- - [Comment ownership](#comment-ownership)
20
- - [Date/time handling and Temporal](#datetime-handling--temporal)
21
- - [Formatting](#formatting)
22
- - [Changelog](https://github.com/DecimalTurn/toml-patch/blob/v3.1.1/CHANGELOG.md)
23
- - [Contributing](https://github.com/DecimalTurn/toml-patch/blob/v3.1.1/CONTRIBUTING.md)
24
- - [MIT License](https://github.com/DecimalTurn/toml-patch/blob/v3.1.1/LICENSE)
25
-
26
- ## Installation
27
-
28
- toml-patch is dependency-free and can be installed via your favorite package manager.
29
-
30
- *Example with NPM*
31
-
32
- ```
33
- $ npm install --save @decimalturn/toml-patch
34
- ```
35
-
36
- For browser usage, you can use unpkg:
37
-
38
- ```html
39
- <script type="module">
40
- import * as TOML from 'https://unpkg.com/@decimalturn/toml-patch@v3.1.1/dist/toml-patch.js';
41
- </script>
42
- ```
43
-
44
- ## API
45
-
46
- overwrite(tomlString: string): void
47
- toml-patch provides a functional API for one-time operations and a document-oriented API for workflows that need multiple operations on the same TOML document.
48
-
49
- See the [API reference](https://github.com/DecimalTurn/toml-patch/blob/v3.1.1/docs/API.md) for `patch`, `parse`, `stringify` and the `TomlDocument` class.
50
-
51
- For a quick start, patch an existing TOML string like this:
52
-
53
- ```js
54
- import { patch } from '@decimalturn/toml-patch';
55
-
56
- const existing = 'title = "TOML example"\nowner.name = "Bob"\n';
57
- const updated = patch(existing, {
58
- title: 'TOML example',
59
- owner: { name: 'Tim' }
60
- });
61
- ```
62
-
63
- ## Comment Ownership
64
-
65
- When `patch()` removes or reorders an entry, any comment describing it (a same-line trailing
66
- comment, or a line-comment directly above with no blank line in between) travels along with
67
- it, instead of being left behind to describe whatever ends up in that spot. This applies to root
68
- keys, `[table]`/`[[array-of-tables]]` blocks, and elements inside multi-line arrays and inline
69
- tables.
70
-
71
- ```js
72
- import * as TOML from '@decimalturn/toml-patch';
73
- import { strict as assert } from 'assert';
74
-
75
- const existing = `
76
- x = 1 # a note about x
77
- y = 2
78
- `;
79
-
80
- const patched = TOML.patch(existing, { y: 2 });
81
-
82
- assert.strictEqual(patched, `
83
- y = 2
84
- `);
85
- ```
86
-
87
- See the [comment ownership guide](https://github.com/DecimalTurn/toml-patch/blob/v3.1.1/docs/Comment-Ownership.md) for the full behavior, including how a blank line opts a comment out of ownership and current scope limitations.
88
-
89
- Note that `patch()` does not reorder entries by default.
90
- To have it match the key order of the object you pass in, enable `updateOrder` in the [formatting options](https://github.com/DecimalTurn/toml-patch/blob/v3.1.1/docs/Formatting.md#updateorder).
91
-
92
- ## Date/Time Handling & Temporal
93
-
94
- TOML date/time values are parsed into custom `Date` subclasses (`LocalDate`, `LocalTime`, `LocalDateTime`, `OffsetDateTime`) by default. Set `temporal: true` to receive [Temporal](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Temporal) objects instead. `stringify()` and `patch()` auto-detect Temporal objects and serialize them correctly.
95
-
96
- ### Enabling Temporal
97
-
98
- The `temporal: true` option requires `Temporal` to be available in the runtime:
99
-
100
- | Runtime | How to enable |
101
- |---|---|
102
- | **Node.js 26+** | Built-in — enable with `temporal: true` |
103
- | **Node.js 20–24** | `node --harmony-temporal` flag |
104
- | **Node.js 14–26** | [@js-temporal/polyfill](https://www.npmjs.com/package/@js-temporal/polyfill) |
105
-
106
- ```js
107
- import * as TOML from '@decimalturn/toml-patch';
108
-
109
- // Node 26+ (native) or Node 20–24 with --harmony-temporal:
110
- const obj = TOML.parse('d = 2024-01-15\n', { temporal: true });
111
- // obj.d → Temporal.PlainDate
112
-
113
- // All Node versions with the polyfill:
114
- import { Temporal } from '@js-temporal/polyfill';
115
- globalThis.Temporal = Temporal;
116
- const obj2 = TOML.parse('d = 2024-01-15\n', { temporal: true });
117
- // obj2.d → PlainDate (polyfill)
118
- ```
119
-
120
- > **Note:** Only offset-based timezones (`+05:30`, `Z`) are supported in TOML. IANA timezone annotations (e.g., `[Asia/Kolkata]`) will throw an error.
121
-
122
- See the [date/time guide](https://github.com/DecimalTurn/toml-patch/blob/v3.1.1/docs/Dates.md) for details and examples.
123
-
124
- ## Formatting
125
-
126
- The `TomlFormat` class controls how TOML documents are formatted during stringification and patching operations.
127
-
128
- ```typescript
129
- class TomlFormat {
130
- newLine: string
131
- trailingNewline: number
132
- trailingComma: boolean
133
- bracketSpacing: boolean
134
- inlineTableStart?: number
135
- truncateZeroTimeInDates: boolean
136
- useTabsForIndentation?: boolean
137
- indentWidth: number
138
- minimumDecimals?: number
139
- leadingBom: boolean
140
- updateOrder?: boolean
141
- multilineTable: boolean | number | 'auto' | 'parent'
142
- multilineArray: boolean | number | 'auto' | 'parent'
143
-
144
- static default(): TomlFormat
145
- static autoDetectFormat(tomlString: string): TomlFormat
146
- }
147
- ```
148
-
149
- Start with `TomlFormat.default()` and override the options you need. e.g.:
150
-
151
- ```js
152
- import { stringify, TomlFormat } from '@decimalturn/toml-patch';
153
-
154
- const format = TomlFormat.default();
155
- format.newLine = '\r\n';
156
- format.trailingNewline = 0;
157
- format.trailingComma = true;
158
- format.bracketSpacing = false;
159
- format.indentWidth = 4;
160
- format.multilineTable = 'parent';
161
-
162
- const toml = stringify({
163
- title: 'My App',
164
- tags: ['dev', 'config'],
165
- database: { host: 'localhost', port: 5432 }
166
- }, format);
167
-
168
- ```
169
- See the [formatting reference](https://github.com/DecimalTurn/toml-patch/blob/v3.1.1/docs/Formatting.md) for the complete list of options, auto-detection behavior, `updateOrder` and more examples.