@decimalturn/toml-patch 3.2.1-dev → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +202 -0
- package/dist/toml-patch.js +84 -0
- package/package.json +102 -16
- package/dist/dev/comment-alignment.js +0 -372
- package/dist/dev/comment-alignment.js.map +0 -1
- package/dist/dev/comment-ownership.js +0 -660
- package/dist/dev/comment-ownership.js.map +0 -1
- package/dist/dev/cst-source.js +0 -118
- package/dist/dev/cst-source.js.map +0 -1
- package/dist/dev/cst.js +0 -68
- package/dist/dev/cst.js.map +0 -1
- package/dist/dev/cursor.js +0 -66
- package/dist/dev/cursor.js.map +0 -1
- package/dist/dev/date-format.js +0 -196
- package/dist/dev/date-format.js.map +0 -1
- package/dist/dev/decode-utf8.js +0 -27
- package/dist/dev/decode-utf8.js.map +0 -1
- package/dist/dev/diff-lite.js +0 -123
- package/dist/dev/diff-lite.js.map +0 -1
- package/dist/dev/diff.js +0 -265
- package/dist/dev/diff.js.map +0 -1
- package/dist/dev/encode-lite.js +0 -193
- package/dist/dev/encode-lite.js.map +0 -1
- package/dist/dev/escape-preference.js +0 -166
- package/dist/dev/escape-preference.js.map +0 -1
- package/dist/dev/find-by-path.js +0 -111
- package/dist/dev/find-by-path.js.map +0 -1
- package/dist/dev/formatter.js +0 -298
- package/dist/dev/formatter.js.map +0 -1
- package/dist/dev/generate.js +0 -465
- package/dist/dev/generate.js.map +0 -1
- package/dist/dev/inline-comma-space.js +0 -13
- package/dist/dev/inline-comma-space.js.map +0 -1
- package/dist/dev/inline-format.js +0 -106
- package/dist/dev/inline-format.js.map +0 -1
- package/dist/dev/inline-layout.js +0 -107
- package/dist/dev/inline-layout.js.map +0 -1
- package/dist/dev/line-ending-backslash.js +0 -320
- package/dist/dev/line-ending-backslash.js.map +0 -1
- package/dist/dev/literal-string.js +0 -46
- package/dist/dev/literal-string.js.map +0 -1
- package/dist/dev/location.js +0 -104
- package/dist/dev/location.js.map +0 -1
- package/dist/dev/parse-error.js +0 -27
- package/dist/dev/parse-error.js.map +0 -1
- package/dist/dev/parse-js.js +0 -150
- package/dist/dev/parse-js.js.map +0 -1
- package/dist/dev/parse-string.js +0 -122
- package/dist/dev/parse-string.js.map +0 -1
- package/dist/dev/parse-toml.js +0 -714
- package/dist/dev/parse-toml.js.map +0 -1
- package/dist/dev/patch-lite.js +0 -4
- package/dist/dev/patch-lite2.js +0 -96
- package/dist/dev/patch-lite2.js.map +0 -1
- package/dist/dev/patch.js +0 -2652
- package/dist/dev/patch.js.map +0 -1
- package/dist/dev/smol-toml-date.js +0 -61
- package/dist/dev/smol-toml-date.js.map +0 -1
- package/dist/dev/to-js.js +0 -303
- package/dist/dev/to-js.js.map +0 -1
- package/dist/dev/to-toml.js +0 -874
- package/dist/dev/to-toml.js.map +0 -1
- package/dist/dev/tokenizer.js +0 -225
- package/dist/dev/tokenizer.js.map +0 -1
- package/dist/dev/toml-document.js +0 -220
- package/dist/dev/toml-document.js.map +0 -1
- package/dist/dev/toml-format.js +0 -528
- package/dist/dev/toml-format.js.map +0 -1
- package/dist/dev/toml-patch.js +0 -94
- package/dist/dev/toml-patch.js.map +0 -1
- package/dist/dev/traverse.js +0 -61
- package/dist/dev/traverse.js.map +0 -1
- package/dist/dev/truncate.js +0 -64
- package/dist/dev/truncate.js.map +0 -1
- package/dist/dev/update-order.js +0 -235
- package/dist/dev/update-order.js.map +0 -1
- package/dist/dev/utils.js +0 -244
- package/dist/dev/utils.js.map +0 -1
- package/dist/dev/writer.js +0 -758
- package/dist/dev/writer.js.map +0 -1
- package/dist/patch-lite.d.ts +0 -18
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"comment-ownership.js","names":[],"sources":["../../src/comment-ownership.ts"],"sourcesContent":["import {\n Document,\n Table,\n TableArray,\n InlineTable,\n InlineArray,\n KeyValue,\n TreeNode,\n Comment,\n isComment,\n isKeyValue,\n isTable,\n isTableArray,\n isDocument,\n isInlineTable,\n isInlineArray,\n isInlineItem,\n isString,\n hasItems,\n InlineItem\n} from './cst';\nimport { last } from './utils';\nimport { clonePosition } from './location';\nimport { remove, insert, shiftNode, applyWrites, recalcContainerEnd, perLine, getExitOffsets, addExitOffset, Root } from './writer';\n\n// See docs/Comment-Ownership.md for the full model (rules R1-R6).\n\n// R6 — commented-out entries are not owned.\n// Segment charset matches IS_BARE_KEY (/^[\\w-]+$/, src/tokenizer.ts:22).\nconst KEY_SEGMENT = String.raw`(?:[\\w-]+|\"[^\"]*\"|'[^']*')`;\n\n/** `# key = ...`, `# a.b.c = ...`, `# \"quoted key\" = ...` */\nexport const IS_COMMENTED_OUT_KEY_VALUE =\n new RegExp(String.raw`^#\\s*${KEY_SEGMENT}(?:\\s*\\.\\s*${KEY_SEGMENT})*\\s*=`);\n\n/** A value after `=` in a commented-out KV: a quoted string, number, boolean,\n * date-like token, or a single bare word. Multi-word prose (e.g.\n * `# key = 1 is something to consider`) does NOT match, so the comment\n * is treated as alive prose rather than a dead entry. */\nconst VALUE_TOKEN = String.raw`(?:\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*'|\"\"\"[\\s\\S]*?\"\"\"|'''[\\s\\S]*?'''|[^\\s#]+)`;\n\n/** Full-line match: `# key = value` where value is a single token. */\nconst IS_PURE_COMMENTED_OUT_KV =\n new RegExp(String.raw`^#\\s*${KEY_SEGMENT}(?:\\s*\\.\\s*${KEY_SEGMENT})*\\s*=\\s*${VALUE_TOKEN}\\s*$`);\n\n/** `# [table]`, `# [[array]]`, `# [a.b]` */\nexport const IS_COMMENTED_OUT_HEADER =\n new RegExp(String.raw`^#\\s*\\[\\[?\\s*${KEY_SEGMENT}(?:\\s*\\.\\s*${KEY_SEGMENT})*\\s*\\]\\]?\\s*$`);\n\nexport function isCommentedOutEntry(comment: Comment): boolean {\n return IS_PURE_COMMENTED_OUT_KV.test(comment.raw) || IS_COMMENTED_OUT_HEADER.test(comment.raw);\n}\n\n/**\n * True when a `#` appears outside of quotes after the `=` in a\n * commented-out-KV line — i.e. the line has an inline trailing comment\n * (`# key = val # note`). `#` inside a quoted value (e.g.\n * `# key = \"a # b\" extra`) is NOT an inline comment.\n */\nfunction hasInlineCommentAfterValue(comment: Comment): boolean {\n const eqIdx = comment.raw.indexOf('=');\n if (eqIdx < 0) return false;\n let inDQuote = false;\n let inSQuote = false;\n for (let i = eqIdx + 1; i < comment.raw.length; i++) {\n const ch = comment.raw[i];\n if (ch === '\\\\') { i++; continue; }\n if (!inSQuote && ch === '\"') { inDQuote = !inDQuote; continue; }\n if (!inDQuote && ch === \"'\") { inSQuote = !inSQuote; continue; }\n if (!inDQuote && !inSQuote && ch === '#') return true;\n }\n return false;\n}\n\n/**\n * True when the comment looks enough like a KV to act as a barrier in\n * scanGroups. Broader than `isCommentedOutEntry`: also matches lines with\n * an inline trailing comment (`# key = val # note`) and lines whose value\n * part is short enough not to be obvious prose (≤3 words after `=`).\n */\nfunction looksLikeKV(comment: Comment): boolean {\n if (isCommentedOutEntry(comment)) return true;\n if (!IS_COMMENTED_OUT_KEY_VALUE.test(comment.raw)) return false;\n // Has an inline comment after the value: `# key = val # note`\n if (hasInlineCommentAfterValue(comment)) return true;\n // Short value: `# key = a few words` (not running prose)\n const afterEq = comment.raw.replace(/^[^=]*=\\s*/, '');\n const wordCount = afterEq.split(/\\s+/).filter(Boolean).length;\n return wordCount <= 3;\n}\n\n/** Extract the first key segment from a commented-out KV like `# key = val`. */\nfunction commentedOutFirstKey(comment: Comment): string | undefined {\n const m = comment.raw.match(IS_COMMENTED_OUT_KEY_VALUE);\n if (!m) return undefined;\n // Strip `#` prefix and everything from `=` onward, then trim.\n // For dotted keys like `# a.b.c = val`, this gives `a.b.c`.\n let key = m[0].replace(/^#\\s*/, '').replace(/\\s*=.*$/, '').trim();\n // Take only the first segment for comparison with the KV's own first key.\n const dot = key.indexOf('.');\n if (dot >= 0) key = key.substring(0, dot);\n // Strip quotes if present\n if ((key.startsWith('\"') && key.endsWith('\"')) || (key.startsWith(\"'\") && key.endsWith(\"'\"))) {\n key = key.slice(1, -1);\n }\n return key || undefined;\n}\n\n/**\n * True only for a genuinely multi-line InlineTable/InlineArray. Single-line\n * containers can never hold hoisted interior comments in the first place\n * (Non-goals in the plan doc), and — critically — `start.line === end.line`\n * for a single-line container means ANY same-line trailing comment on the\n * OUTER key-value (e.g. `data = [x, y] # note`) would otherwise appear to\n * fall \"inside\" a nested single-line array's own line range too, wrongly\n * treating an unrelated comment as hoisted from inside it. The element-level\n * ownership machinery below (resolveInlineElementGroups / removeMember's and\n * moveInlineElement's InlineTable/InlineArray branches) must only engage\n * here, matching writer.ts's own `isMultilineInlineContainer` convention.\n */\nfunction isMultilineInlineContainer(node: TreeNode): node is InlineTable | InlineArray {\n return (isInlineTable(node) || isInlineArray(node)) && node.loc.end.line > node.loc.start.line;\n}\n\nexport interface Group {\n kind: 'member' | 'pinned';\n /** The orderable child: KeyValue | Table | TableArray. Absent for pinned blocks. */\n member?: TreeNode;\n /** First key segment — `key.value[0]` / `key.item.value[0]`. Absent for pinned blocks. */\n key?: string;\n /** Every node in the group, in items-array order. */\n items: TreeNode[];\n /** min over items. */\n startLine: number;\n /** max over items — NOT the last item's end, because of hoisted comments. */\n endLine: number;\n}\n\nfunction getMemberKey(member: TreeNode): string | undefined {\n if (isKeyValue(member)) return member.key.value[0];\n if (isTable(member) || isTableArray(member)) return member.key.item.value[0];\n if (isInlineItem(member) && isKeyValue(member.item)) return (member.item as KeyValue).key.value[0];\n return undefined;\n}\n\n/**\n * The rule scan shared by resolveGroups (Document/Table/TableArray, where members\n * and comments are already interleaved in one items array) and\n * resolveInlineElementGroups (InlineTable/InlineArray, where they are merged from\n * two different arrays first — see that function). `items` must already be in\n * ascending line order; a `Comment` node is a comment, anything else is a member.\n */\nfunction scanGroups(\n items: TreeNode[],\n initialLastMemberEndLine: number,\n isEligibleForLeading: (member: TreeNode) => boolean,\n memberKey = getMemberKey\n): Group[] {\n const groups: Group[] = [];\n\n let lastMemberEndLine = initialLastMemberEndLine;\n let currentMemberGroup: Group | undefined;\n let pendingRun: Comment[] = [];\n\n const flushPendingAsPinned = () => {\n if (!pendingRun.length) return;\n groups.push({\n kind: 'pinned',\n items: pendingRun,\n startLine: pendingRun[0].loc.start.line,\n endLine: last(pendingRun)!.loc.end.line\n });\n pendingRun = [];\n };\n\n for (const item of items) {\n if (isComment(item)) {\n if (item.loc.start.line <= lastMemberEndLine) {\n // R1: trailing ownership.\n if (currentMemberGroup) {\n currentMemberGroup.items.push(item);\n currentMemberGroup.endLine = Math.max(currentMemberGroup.endLine, item.loc.end.line);\n } else {\n // Owned by the container's own header (e.g. `[a] # hdr`), which\n // isn't itself a member of `items` — nothing to attach to, and it\n // never travels with any row.\n groups.push({ kind: 'pinned', items: [item], startLine: item.loc.start.line, endLine: item.loc.end.line });\n }\n continue;\n }\n\n const runEndLine = pendingRun.length ? last(pendingRun)!.loc.end.line : undefined;\n if (pendingRun.length && item.loc.start.line === runEndLine! + 1) {\n pendingRun.push(item);\n } else {\n flushPendingAsPinned();\n pendingRun.push(item);\n }\n continue;\n }\n\n // A member: KeyValue | Table | TableArray | InlineItem.\n let leading: Comment[] = [];\n if (pendingRun.length) {\n const runEndLine = last(pendingRun)!.loc.end.line;\n const adjacent = runEndLine + 1 === item.loc.start.line;\n if (adjacent && isEligibleForLeading(item)) {\n // R2, subject to R6. A commented-out KV whose key differs from\n // the following KV's key acts as a barrier: only comments after\n // the LAST such barrier belong to the KV. Dead entries whose\n // key matches the KV's key stay in the block (they are \"related\").\n // This applies to all-dead blocks too — when every dead entry's\n // key matches the KV, R6 does not apply and the block is owned.\n const key = memberKey(item);\n if (key !== undefined) {\n let lastBarrierIdx = -1;\n for (let i = pendingRun.length - 1; i >= 0; i--) {\n // Use looksLikeKV for barrier detection — a line like\n // `# key = val # extra` still severs ownership even though\n // it isn't a \"pure\" dead entry.\n const ck = looksLikeKV(pendingRun[i]) ? commentedOutFirstKey(pendingRun[i]) : undefined;\n if (ck !== undefined && ck !== key) {\n lastBarrierIdx = i;\n break;\n }\n }\n if (lastBarrierIdx >= 0) {\n const pinned = pendingRun.splice(0, lastBarrierIdx + 1);\n groups.push({\n kind: 'pinned',\n items: pinned,\n startLine: pinned[0].loc.start.line,\n endLine: last(pinned)!.loc.end.line\n });\n }\n }\n leading = pendingRun;\n pendingRun = [];\n } else {\n // R3 (severed by a blank line) or R6 (dead-entry block) — pin it.\n flushPendingAsPinned();\n }\n }\n\n const groupItems: TreeNode[] = [...leading, item];\n const group: Group = {\n kind: 'member',\n member: item,\n key: memberKey(item),\n items: groupItems,\n startLine: groupItems[0].loc.start.line,\n endLine: item.loc.end.line\n };\n groups.push(group);\n currentMemberGroup = group;\n lastMemberEndLine = item.loc.end.line;\n }\n\n flushPendingAsPinned(); // R4: a trailing block with no member below it.\n\n return groups;\n}\n\n/**\n * Partitions a container's items into ownership groups, in document order.\n * Pure: does not mutate the tree.\n *\n * @param isEligibleForLeading - optional predicate; members that fail it cannot\n * acquire leading comments via R2. Used by callers that have just inserted\n * nodes which must not adopt a preceding block.\n */\nexport function resolveGroups(\n container: Document | Table | TableArray,\n isEligibleForLeading: (member: TreeNode) => boolean = () => true,\n memberKey: (member: TreeNode) => string | undefined = getMemberKey\n): Group[] {\n // For a table body, comments on the header's own line (`[a] # hdr`) are\n // owned by the header itself (R1) — initialising to the header's end line\n // makes that fall out of the same check as ownership by a preceding row.\n const initialLastMemberEndLine = isDocument(container) ? 0 : container.key.loc.end.line;\n return scanGroups(container.items as TreeNode[], initialLastMemberEndLine, isEligibleForLeading, memberKey);\n}\n\n/**\n * The element-level analogue of resolveGroups, for a multi-line InlineTable or\n * InlineArray. Unlike Document/Table/TableArray, an inline container's own\n * `.items` can never hold a Comment (InlineTableItem/InlineArrayItem are both\n * InlineItem<...>) — the parser hoists interior comments out into the\n * *enclosing* Document/Table's `.items` instead (Background, case 4 in the\n * plan doc). `hostItems` is that enclosing container's `.items`; this merges\n * the comments physically inside `container`'s line range back in with\n * `container.items` (sorted into true reading order) before running the same\n * scan resolveGroups uses.\n *\n * There is no R6 analogue for bare array elements (they aren't `key = value`\n * shaped), but nothing here suppresses R6 for an InlineArray's own comments —\n * see docs/Comment-Ownership.md for why that's an accepted, untested edge\n * case rather than a deliberate rule.\n */\nexport function resolveInlineElementGroups(\n container: InlineTable | InlineArray,\n hostItems: TreeNode[]\n): Group[] {\n const interiorComments = hostItems.filter(\n (item): item is Comment =>\n isComment(item) &&\n (item.loc.start.line > container.loc.start.line ||\n (item.loc.start.line === container.loc.start.line && item.loc.start.column >= container.loc.start.column)) &&\n (item.loc.end.line < container.loc.end.line ||\n (item.loc.end.line === container.loc.end.line && item.loc.end.column <= container.loc.end.column))\n );\n\n const merged: TreeNode[] = [...(container.items as TreeNode[]), ...interiorComments].sort(\n (a, b) => a.loc.start.line - b.loc.start.line || a.loc.start.column - b.loc.start.column\n );\n\n return scanGroups(merged, container.loc.start.line, () => true);\n}\n\n/**\n * Finds the nearest Document/Table/TableArray ancestor whose OWN `.items`\n * holds the top-level Block from which `target` is reachable, following\n * KeyValue.value / InlineTable.items / InlineArray.items / InlineItem.item\n * links down through any nesting depth. This is where the parser files\n * comments hoisted out of `target` (Background, case 4) — regardless of how\n * deeply `target` is nested inside other inline containers, they always\n * flatten up to the same enclosing Document/Table.\n */\n/**\n * Finds the InlineItem that wraps `target` (an InlineTable/InlineArray)\n * inside its own parent container's items, searching the whole tree.\n */\nfunction findWrapperItem(root: TreeNode, target: TreeNode): InlineItem | undefined {\n function walk(node: TreeNode): InlineItem | undefined {\n if (isKeyValue(node)) return walk(node.value);\n if (!hasItems(node)) return undefined;\n for (const item of node.items as TreeNode[]) {\n if (isInlineItem(item) && item.item === target) return item;\n }\n for (const item of node.items as TreeNode[]) {\n const found = walk(isInlineItem(item) ? item.item : item);\n if (found) return found;\n }\n return undefined;\n }\n return walk(root);\n}\n\nexport function findHostContainer(root: Document, target: TreeNode): Document | Table | TableArray | undefined {\n function searchValue(value: TreeNode, container: Document | Table | TableArray): Document | Table | TableArray | undefined {\n if (value === target) return container;\n // An inline table's entries are InlineItems wrapping a KeyValue, so reaching anything\n // nested under one of its keys means stepping through that KeyValue's value. Without\n // this, `t = { xs = [...] }` never reaches `xs`'s array and the caller falls back to the\n // comment-oblivious path.\n if (isKeyValue(value)) return searchValue(value.value, container);\n if (isInlineTable(value) || isInlineArray(value)) {\n for (const inlineItem of (value as InlineTable | InlineArray).items) {\n if ((inlineItem as TreeNode) === target) return container;\n const found = searchValue(inlineItem.item, container);\n if (found) return found;\n }\n }\n return undefined;\n }\n\n function search(container: Document | Table | TableArray): Document | Table | TableArray | undefined {\n for (const item of container.items as TreeNode[]) {\n if (item === target) return container;\n if (isKeyValue(item)) {\n const found = searchValue(item.value, container);\n if (found) return found;\n } else if (isTable(item) || isTableArray(item)) {\n const found = search(item);\n if (found) return found;\n }\n }\n return undefined;\n }\n\n return search(root);\n}\n\n/**\n * R5, applied once as a general-purpose (non-destructive-to-text) pass: a\n * comment that visually introduces the next [table]/[[array]] block is\n * physically stored as a trailing item of the PREVIOUS block, because the\n * parser consumes everything up to the next `[` into the current table\n * (src/parse-toml.ts:517-524). This re-parents such blocks into Document.items,\n * immediately before the block they visually belong to.\n *\n * Mutates the tree; loc-preserving, so serialized output is unchanged. NOTE:\n * because the re-parenting is loc-preserving, a document normalized this way\n * no longer matches what re-parsing its own serialized text would produce\n * (the parser always re-derives the original, pre-normalization container\n * assignment from the text). Do not call this as a blanket pre-pass before\n * general patching — it is intended for callers that immediately consume the\n * result without round-tripping through text (e.g. a future reorder pass that\n * is about to change those lines anyway). For deletion, `removeMember` below\n * computes the same R5 ownership lazily and only mutates when a comment is\n * genuinely being deleted, which has no such divergence risk.\n */\nexport function normalizeSectionComments(document: Document): void {\n for (let i = 0; i < document.items.length; i++) {\n const block = document.items[i];\n if (!isTable(block) && !isTableArray(block)) continue;\n\n const nextBlock = document.items[i + 1];\n if (!nextBlock) continue;\n\n const runItems = trailingOwnedRun(block, nextBlock);\n if (!runItems) continue;\n\n const items = block.items as TreeNode[];\n items.splice(items.length - runItems.length, runItems.length);\n document.items.splice(i + 1, 0, ...runItems);\n recalcContainerEnd(block);\n\n i += runItems.length; // skip over the just-inserted comments\n }\n}\n\n/**\n * R5, computed lazily: if `container`'s trailing comment block is R2-adjacent\n * to `nextBlock` (and not R6-dead), returns it — these are the comments a\n * removal of `nextBlock` must take along, even though they physically live\n * in `container.items`. Returns undefined otherwise.\n */\nfunction trailingOwnedRun(container: Table | TableArray, nextBlock: TreeNode): Comment[] | undefined {\n const lastGroup = last(resolveGroups(container));\n if (!lastGroup || lastGroup.kind !== 'pinned') return undefined;\n\n const runItems = lastGroup.items as Comment[];\n const adjacent = lastGroup.endLine + 1 === nextBlock.loc.start.line;\n const allDead = runItems.every(isCommentedOutEntry);\n if (!adjacent || allDead) return undefined;\n\n return runItems;\n}\n\n/**\n * Removes `member` from `parent.items` along with every comment it owns\n * (leading block and trailing comments — see resolveGroups), plus,\n * when `member` is a [table]/[[array]] block, any trailing comment block the\n * parser filed under the PRECEDING sibling table but which R5 assigns to\n * `member` instead. Falls back to a plain removal when `parent` isn't a\n * container the ownership model applies to (e.g. InlineTable/InlineArray).\n */\nexport function removeMember(root: Root, parent: TreeNode, member: TreeNode): void {\n if (isDocument(parent) && (isTable(member) || isTableArray(member))) {\n const index = (parent.items as TreeNode[]).indexOf(member);\n const previousSibling = index > 0 ? parent.items[index - 1] : undefined;\n if (previousSibling && (isTable(previousSibling) || isTableArray(previousSibling))) {\n const runItems = trailingOwnedRun(previousSibling, member);\n if (runItems) {\n for (const item of runItems) {\n remove(root, previousSibling, item);\n }\n }\n }\n }\n\n if (isDocument(parent) || isTable(parent) || isTableArray(parent)) {\n const group = resolveGroups(parent).find(s => s.member === member);\n if (group) {\n const memberIndex = group.items.indexOf(member);\n\n // Leading comments and the member itself: every one of these occupies\n // its own line(s) that the member's own span does not otherwise cover,\n // so each is removed via the generic primitive, which computes real\n // line/column offset accounting.\n for (let i = 0; i <= memberIndex; i++) {\n const item = group.items[i];\n // A prior remove() call in this loop may already have absorbed a\n // same-line trailing comment via its own single-comment logic —\n // see the trailing-comments loop below for why that's fine.\n if (!(parent.items as TreeNode[]).includes(item)) continue;\n remove(root, parent, item);\n }\n\n // Trailing (R1) comments: by definition their start line\n // is <= the member's own end line, so they sit *within* the span the\n // member's removal above already accounted for (a same-line trailing\n // comment, or one hoisted out of a multiline inline value). remove()'s\n // own legacy same-line check may already have absorbed a simple\n // trailing comment as a side effect of removing the member. Anything\n // still present here is spliced out directly, with NO further offset —\n // registering one would double-count a line height already removed.\n for (let i = memberIndex + 1; i < group.items.length; i++) {\n const item = group.items[i];\n const idx = (parent.items as TreeNode[]).indexOf(item);\n if (idx < 0) continue;\n (parent.items as TreeNode[]).splice(idx, 1);\n }\n return;\n }\n }\n\n if (isMultilineInlineContainer(parent) && isDocument(root)) {\n const hostContainer = findHostContainer(root, parent);\n if (hostContainer) {\n const group = resolveInlineElementGroups(parent, hostContainer.items as TreeNode[]).find(s => s.member === member);\n if (group) {\n const comments = group.items.filter(item => item !== member) as Comment[];\n\n // Every comment in this group is hoisted into hostContainer (the\n // enclosing Document/Table) — a DIFFERENT array from the member's own\n // `parent.items`, and NOT a sibling of it: hostContainer.items holds\n // the KeyValue that owns `parent` as its value, so an offset\n // registered there only ever affects that KeyValue's OWN siblings\n // (e.g. a later root key), never the surviving rows still inside\n // `parent` (a descendant of that KeyValue, not a sibling). Splicing\n // the comments out directly here (zero offset — purely structural),\n // then extending the member's own loc to cover their lines before\n // removing IT, lets remove()'s existing target-selection (a\n // preceding sibling row within `parent`, or an ENTER offset on\n // `parent` itself when the member is first) correctly propagate ONE\n // combined height reduction to both `parent`'s remaining rows and\n // whatever comes after it — it only needs the full height, comments\n // included, in a single call. `member` is being discarded regardless,\n // so mutating its own loc here has no lasting effect.\n for (const comment of comments) {\n const idx = (hostContainer.items as TreeNode[]).indexOf(comment);\n if (idx < 0) continue;\n (hostContainer.items as TreeNode[]).splice(idx, 1);\n }\n\n if (comments.length) {\n member.loc.start = group.items[0].loc.start;\n member.loc.end = last(group.items)!.loc.end;\n }\n\n remove(root, parent, member, hostContainer.items as TreeNode[]);\n\n // Flush immediately, matching moveInlineElement's identical discipline (see\n // its docstring): writer.remove()'s own orphaned-comment compensation above\n // mutates surviving comments' `.loc` as a PRE-compensation for an offset that\n // only actually resolves once applyWrites runs. If a SECOND removeMember (or\n // moveInlineElement) call on this same container ran before that offset were\n // resolved, resolveInlineElementGroups would read those pre-compensated,\n // not-yet-restored positions as if they were final — misattributing or\n // losing ownership. Flushing here keeps every subsequent call in this patch\n // starting from a fully-resolved, non-stale state.\n applyWrites(root);\n return;\n }\n }\n }\n\n remove(root, parent, member);\n}\n\n/**\n * Relocates `node` (an element of `parent`, an InlineTable/InlineArray) from\n * its current position to `toIndex`, carrying its own owned comments along\n * (see resolveInlineElementGroups) rather than leaving them at their old\n * absolute position — which is what plain remove()+insert() does, and why a\n * Move on a commented inline array can misplace a comment onto an unrelated\n * line (see \"Elements inside multi-line arrays and inline tables\" in\n * docs/Comment-Ownership.md).\n *\n * It isn't enough to protect only `node`'s own comments: writer.remove()'s\n * per-container \"orphaned comment\" cleanup reasons purely by absolute line\n * number, with no notion of ownership, so relocating `node` past *other*\n * elements can drag an unrelated element's own comment along as a side\n * effect (or leave it stranded) even though that element never moved. Every\n * commented element in the container is protected the same way: its\n * comment(s) are detached before the move and re-attached afterward, based\n * on how far *that specific element* actually shifted — which may differ\n * from how far `node` itself moved, or be zero.\n */\nexport function moveInlineElement(root: Root, parent: TreeNode, node: TreeNode, toIndex: number): void {\n let sharedLineContainerBeforeMove = false;\n if (isMultilineInlineContainer(parent) && isDocument(root)) {\n const hostContainer = findHostContainer(root, parent);\n if (hostContainer) {\n const groups = resolveInlineElementGroups(parent, hostContainer.items as TreeNode[]);\n\n // The container's per-line vs shared-line layout must be judged on\n // the state BEFORE this move: remove()+insert() inflate the tail's\n // line coordinates, and a later perLine() read of the corrupted span\n // misclassifies a shared-line container as per-line, skipping the\n // tail realignment and stranding the rows (fuzz seed 16034).\n //\n // The honest signature of a shared-line layout is a RUN of at least\n // three adjacent items STARTING on the same line. Two items sharing\n // a line is the signature of a per-line container whose multiline\n // member ends on the next item's line — the writer offsets handle\n // those (fuzz seeds 9553, 9829). A same-line pair caused by a\n // just-inserted item still carrying its pending exit offset is\n // transient and must not count (fuzz seed 761).\n {\n const items = (parent as InlineTable | InlineArray).items as TreeNode[];\n let run = 1;\n for (let i = 1; i < items.length; i++) {\n if (items[i].loc.start.line === items[i - 1].loc.start.line) {\n const prevPending = getExitOffsets(root).get(items[i - 1]);\n const selfPending = getExitOffsets(root).get(items[i]);\n if (prevPending || selfPending) continue;\n run++;\n if (run >= 3) {\n sharedLineContainerBeforeMove = true;\n break;\n }\n } else {\n run = 1;\n }\n }\n }\n\n const detached: Array<{ owner: TreeNode; ownerOriginalStart: { line: number; column: number }; comments: Comment[] }> = [];\n let nodeOwnStart: { line: number; column: number } | undefined;\n let nodeOwnEnd: { line: number; column: number } | undefined;\n let nodeInnerEnd: { line: number; column: number } | undefined;\n\n // Snapshot descendants of the moved node that start BELOW its first\n // line. insert()'s rigid horizontal translation shifts every subtree\n // column by the first line's column delta, but interior rows of a\n // multiline inline table/array are indented from line start (not from\n // the opening bracket), so they must not move sideways. This covers\n // both rows anchored to a preceding multiline value's end column\n // (fuzz seed 706: `, 5, 6` after a multiline string inside a moved\n // nested array slid left onto the string's closing quotes) and the\n // FIRST row of a multiline container that has no predecessor at all\n // (fuzz seed 599513: `nxweV7FF3` slid to a negative column and toTOML\n // emitted `,-1.5nx=`).\n const anchoredDescendants: Array<{ node: TreeNode; start: { line: number; column: number }; end: { line: number; column: number }; endOnly?: boolean; equals?: number }> = [];\n const collectAnchored = (container: TreeNode, firstLine: number) => {\n if (!hasItems(container)) return;\n const items = container.items as TreeNode[];\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n const below = item.loc.start.line > firstLine;\n if (below) {\n anchoredDescendants.push({ node: item, start: clonePosition(item.loc.start), end: clonePosition(item.loc.end) });\n }\n // A multiline element's wrapper END (where its comma lands) is\n // anchored to the element's own end column, which the leaf path of\n // the rigid translation leaves alone — but the wrapper's end is\n // shifted with the first line. Restore it too.\n if (item.loc.end.line > firstLine && item.loc.end.line > item.loc.start.line) {\n anchoredDescendants.push({ node: item, start: clonePosition(item.loc.start), end: clonePosition(item.loc.end), endOnly: true });\n }\n if (isInlineItem(item)) {\n const inner = item.item;\n if (below) {\n const kv = isKeyValue(inner) ? inner : undefined;\n anchoredDescendants.push({\n node: inner,\n start: clonePosition(inner.loc.start),\n end: clonePosition(inner.loc.end),\n equals: kv ? kv.equals : undefined\n });\n // The KV's key and value nodes ride the same rigid translation\n // as the row, but only the row and the KV are restored above —\n // the key keeps its shifted column and toTOML writes it at its\n // own loc, overwriting the preceding content (fuzz seed 19506).\n if (kv) {\n anchoredDescendants.push({\n node: kv.key,\n start: clonePosition(kv.key.loc.start),\n end: clonePosition(kv.key.loc.end)\n });\n anchoredDescendants.push({\n node: kv.value,\n start: clonePosition(kv.value.loc.start),\n end: clonePosition(kv.value.loc.end)\n });\n }\n }\n // A multiline STRING's own end column is what its closing quotes\n // follow — offsets can nudge it while the wrapper's end (with the\n // comma) stays put, making toTOML's multiline writer consume the\n // columns between them (fuzz seed 706). Restore it independently.\n if (inner.loc.end.line > firstLine && inner.loc.end.line > inner.loc.start.line) {\n anchoredDescendants.push({ node: inner, start: clonePosition(inner.loc.start), end: clonePosition(inner.loc.end), endOnly: true });\n }\n collectAnchored(inner, firstLine);\n } else if (hasItems(item)) {\n collectAnchored(item, firstLine);\n }\n }\n };\n\n for (const group of groups) {\n if (group.kind !== 'member' || !group.member) continue;\n const comments = group.items.filter(item => item !== group.member) as Comment[];\n\n if (group.member === node) {\n nodeOwnStart = clonePosition(node.loc.start);\n nodeOwnEnd = clonePosition(node.loc.end);\n if (isInlineItem(node)) {\n nodeInnerEnd = clonePosition(node.item.loc.end);\n }\n collectAnchored(isInlineItem(node) ? node.item : node, nodeOwnStart.line);\n if (comments.length) {\n // Extend node's own loc to the full group span so the bare\n // remove()+insert() below accounts for the combined height —\n // matters for a leading, separate-line comment; a no-op for a\n // same-line trailing one, since that doesn't change the line\n // count (mirrors removeMember's identical trick).\n node.loc.start = clonePosition(group.items[0].loc.start);\n node.loc.end = clonePosition(last(group.items)!.loc.end);\n }\n }\n\n if (!comments.length) continue;\n detached.push({ owner: group.member, ownerOriginalStart: clonePosition(group.member.loc.start), comments });\n for (const comment of comments) {\n const idx = (hostContainer.items as TreeNode[]).indexOf(comment);\n if (idx >= 0) (hostContainer.items as TreeNode[]).splice(idx, 1);\n }\n }\n\n // For a multiline item removed from the END of a shared-line container,\n // remove()'s bracket-slide offset (fuzz seed 706) mixes the removed\n // item's LAST line with the previous item's line. The re-insert below\n // cannot cancel it — its own span-based offset has the same cross-line\n // defect — so the pair leaks past the container and corrupts every\n // subsequent node on the flush (fuzz seed 900: the rows after the array\n // slid onto the multiline string's content). Drop both; the tail\n // realignment below repositions the container's interior explicitly.\n const nodeIndexBeforeRemove = (parent.items as TreeNode[]).indexOf(node);\n const removedWasLast = nodeIndexBeforeRemove === (parent.items as TreeNode[]).length - 1;\n const prevBeforeRemove = nodeIndexBeforeRemove > 0\n ? (parent.items as TreeNode[])[nodeIndexBeforeRemove - 1]\n : undefined;\n\n // A multiline node moved to the FRONT (index 0) that, before the move,\n // shared its START line with the item now following it (`prevBeforeRemove`,\n // which ends up at index 1). The writer's per-line offset model assumes\n // each item sits on its own line, so the shared-line item's columns go\n // stale (it lands with a negative start column, overwriting the moved\n // multiline string's closing delimiter). The tail realignment below is\n // gated on `sharedLineContainerBeforeMove`, which a two-item same-line\n // pairing does NOT satisfy — so record this case explicitly (fuzz seed\n // 421965: `[false, \"\"\"\\nAAA\\n\"\"\", \"z\"]` moving the string to the front\n // left `false` at column -2 on the string's last line).\n const movedMultilineToFront = toIndex === 0 && nodeIndexBeforeRemove > 0 &&\n node.loc.end.line > node.loc.start.line &&\n prevBeforeRemove !== undefined &&\n prevBeforeRemove.loc.start.line === node.loc.start.line;\n\n remove(root, parent, node, hostContainer.items as TreeNode[]);\n\n let cancelMultilineLastRemovalOffsets = false;\n if (removedWasLast && prevBeforeRemove !== undefined &&\n node.loc.end.line > node.loc.start.line &&\n !perLine(parent as InlineArray | InlineTable)) {\n const prevPending = getExitOffsets(root).get(prevBeforeRemove);\n if (prevPending) {\n getExitOffsets(root).delete(prevBeforeRemove);\n cancelMultilineLastRemovalOffsets = true;\n }\n }\n\n // Resolve the removal's offsets before re-inserting, so insert()\n // measures against final positions. Otherwise insert() absorbs the\n // removal's pending exit offset into the inserted item's own offset,\n // which then leaks into the container's end column (and any wrapper\n // InlineItem's end) — a comma or closing bracket lands inside the\n // last value on that line (fuzz seed 50).\n applyWrites(root);\n insert(root, parent, node, toIndex, undefined, hostContainer.items as TreeNode[]);\n\n if (cancelMultilineLastRemovalOffsets) {\n const childPending = getExitOffsets(root).get(node);\n if (childPending) {\n childPending.lines = 0;\n childPending.columns = 0;\n }\n }\n\n // Flush before reading anything back out below. Every other element's\n // own loc (an untouched sibling that nonetheless shifted because this\n // move made room around it) only becomes fully current at this point,\n // and it's what each owner's delta below is computed against. It also\n // means any FURTHER change in this patch touching the same container\n // starts from a fully-resolved, non-stale state.\n applyWrites(root);\n\n // insert() translates the node rigidly: every line of a multi-line\n // node receives the first line's column delta. A multi-line value's\n // content columns below the first line are part of its raw text and\n // must not move — the writer only reads the END column on the last\n // line, so restore just that, on both the wrapper InlineItem and the\n // inner value node it wraps (fuzz seed 50).\n if (nodeOwnStart && nodeOwnEnd && node.loc.end.line > node.loc.start.line) {\n node.loc.end.column = nodeOwnEnd.column;\n // The inner value keeps its OWN original end — for a multiline\n // string the wrapper's end includes the comma that follows, and\n // assigning it to the string makes toTOML's multiline writer\n // consume the columns between the closing quotes and the next item\n // (fuzz seed 706).\n if (isInlineItem(node) && nodeInnerEnd && node.item.loc.end.line > node.item.loc.start.line) {\n node.item.loc.end.column = nodeInnerEnd.column;\n }\n }\n\n // Restore the columns of anchored below-first-line descendants that the\n // rigid translation shifted horizontally (see the snapshot comment above).\n for (const { node: descendant, start, end, endOnly, equals } of anchoredDescendants) {\n if (endOnly) {\n descendant.loc.end.column = end.column;\n continue;\n }\n descendant.loc.start.column = start.column;\n if (descendant.loc.end.line === descendant.loc.start.line) {\n descendant.loc.end.column = end.column;\n }\n if (equals !== undefined && isKeyValue(descendant)) {\n (descendant as KeyValue).equals = equals;\n }\n }\n\n for (const { owner, ownerOriginalStart, comments } of detached) {\n let delta: { lines: number; columns: number };\n if (owner === node) {\n // node.loc is still the (possibly extended) relocated group span;\n // derive the shift from that, then restore node's own bare span.\n delta = {\n lines: node.loc.start.line - ownerOriginalStart.line,\n columns: node.loc.start.column - ownerOriginalStart.column\n };\n node.loc.start = { line: nodeOwnStart!.line + delta.lines, column: nodeOwnStart!.column + delta.columns };\n node.loc.end = { line: nodeOwnEnd!.line + delta.lines, column: nodeOwnEnd!.column + delta.columns };\n } else {\n delta = {\n lines: owner.loc.start.line - ownerOriginalStart.line,\n columns: owner.loc.start.column - ownerOriginalStart.column\n };\n }\n\n for (const comment of comments) {\n shiftNode(comment, delta);\n const insertAt = (hostContainer.items as TreeNode[]).findIndex(\n item => item.loc.start.line > comment.loc.start.line\n );\n if (insertAt === -1) (hostContainer.items as TreeNode[]).push(comment);\n else (hostContainer.items as TreeNode[]).splice(insertAt, 0, comment);\n }\n }\n\n // The writer's offset model assumes the next sibling sits at the moved\n // node's first-line column. When the moved node wraps lines (a\n // multiline string) inside a container whose items share lines, that\n // assumption breaks and every item after the moved one lands in the\n // wrong place, dragging the container's (and any wrapper InlineItem's)\n // end column with it. Realign the tail sequentially: each item starts\n // right after the previous one's end (fuzz seed 50).\n const container = parent as InlineTable | InlineArray;\n // Gate the tail realignment on the original layout classification:\n // perLine() reads the container's own end, which the moves above can\n // leave stale. The pre-move capture reflects the true layout. A\n // multiline node moved to the front also needs the tail realignment\n // (see movedMultilineToFront above), even though the shared-line run\n // is only two items and `sharedLineContainerBeforeMove` stays false.\n const sharedLineContainer = sharedLineContainerBeforeMove || movedMultilineToFront;\n if (sharedLineContainer) {\n // Re-anchor the interior rows of a multiline inline container whose\n // subtree the tail shift above translated rigidly: the shiftNode\n // moves every row's START, but rows anchored to a preceding\n // multiline value keep their END columns — the boundary between a\n // multiline string row and the next row then closes up and the\n // separator comma is overwritten (fuzz seed 16552).\n const realignInterior = (inner: InlineTable | InlineArray, wrapper?: TreeNode) => {\n let anchor: { line: number; column: number } | undefined;\n for (const row of inner.items as TreeNode[]) {\n if (!anchor) {\n anchor = { line: row.loc.end.line, column: row.loc.end.column + 2 };\n continue;\n }\n const d = {\n lines: anchor.line - row.loc.start.line,\n columns: anchor.column - row.loc.start.column\n };\n if (d.lines !== 0 || d.columns !== 0) {\n shiftNode(row, d);\n if (row.loc.end.line > row.loc.start.line) {\n row.loc.end.column -= d.columns;\n if (isInlineItem(row) && row.item.loc.end.line > row.item.loc.start.line) {\n row.item.loc.end.column -= d.columns;\n }\n }\n const rowInner = isInlineItem(row)\n ? (isKeyValue(row.item) ? row.item.value : row.item)\n : row;\n if ((isInlineTable(rowInner) || isInlineArray(rowInner)) &&\n rowInner.loc.end.line > rowInner.loc.start.line) {\n realignInterior(rowInner, row);\n }\n }\n anchor = { line: row.loc.end.line, column: row.loc.end.column + 2 };\n }\n if (anchor) {\n inner.loc.end = { line: anchor.line, column: anchor.column - 1 };\n // The enclosing InlineItem's end carries the comma that follows\n // the closing brace — track the new end so the comma stays\n // adjacent (fuzz seed 16552).\n if (wrapper && wrapper.loc.end.line === inner.loc.end.line) {\n wrapper.loc.end.column = inner.loc.end.column;\n }\n }\n };\n\n let tailAnchor: { line: number; column: number } | undefined;\n for (const item of container.items as TreeNode[]) {\n if (item === node) {\n tailAnchor = { line: node.loc.end.line, column: node.loc.end.column + 2 };\n continue;\n }\n if (!tailAnchor) continue;\n const delta = {\n lines: tailAnchor.line - item.loc.start.line,\n columns: tailAnchor.column - item.loc.start.column\n };\n if (delta.lines !== 0 || delta.columns !== 0) {\n shiftNode(item, delta);\n const itemInner = isInlineItem(item)\n ? (isKeyValue(item.item) ? item.item.value : item.item)\n : item;\n if ((isInlineTable(itemInner) || isInlineArray(itemInner)) &&\n itemInner.loc.end.line > itemInner.loc.start.line) {\n realignInterior(itemInner, isInlineItem(item) ? item : undefined);\n }\n }\n // A multiline STRING member's end line may be stale (the move\n // offsets inflated it) — derive it from the raw content so the\n // chain doesn't push the following items onto the wrong lines\n // (fuzz seed 9553).\n let itemEndLine = item.loc.end.line;\n const tailInner = isInlineItem(item) ? item.item : item;\n if (isString(tailInner) && tailInner.loc.end.line > tailInner.loc.start.line) {\n itemEndLine = tailInner.loc.start.line + tailInner.raw.split('\\n').length - 1;\n tailInner.loc.end.line = itemEndLine;\n item.loc.end.line = itemEndLine;\n }\n tailAnchor = { line: itemEndLine, column: item.loc.end.column + 2 };\n }\n if (tailAnchor) {\n const endBeforeRealign = clonePosition(container.loc.end);\n container.loc.end = { line: tailAnchor.line, column: tailAnchor.column - 1 };\n\n // The container may itself be an element of another inline\n // container; the wrapper InlineItem's end must track the\n // container's end or its comma lands inside the last value.\n const wrapper = findWrapperItem(root, container as TreeNode);\n if (wrapper) {\n wrapper.loc.end = { line: container.loc.end.line, column: container.loc.end.column };\n }\n\n // Nodes AFTER the container (same-line followers, enclosing\n // table rows, the table's own end) were positioned by the writer\n // offsets this realignment has just replaced. Re-anchor them to\n // the new end with a pending exit offset so a later flush shifts\n // them by exactly the end delta (fuzz seed 900: the row following\n // the moved array would otherwise sit on the moved item's stale\n // column and the subsequent removal then slides it sideways onto\n // the multiline string's content).\n const endDelta = {\n lines: container.loc.end.line - endBeforeRealign.line,\n columns: container.loc.end.column - endBeforeRealign.column\n };\n if (endDelta.lines !== 0 || endDelta.columns !== 0) {\n addExitOffset(root, wrapper ?? (container as TreeNode), endDelta);\n }\n }\n }\n\n return;\n }\n }\n\n // Capture the container's bracket gaps before the move so they can be\n // restored afterwards. remove()+insert() uses writer offsets that do\n // not perfectly cancel over consecutive Moves on the same container,\n // which corrupts the leading gap (space after `[`/`{`) and trailing gap\n // (space before `]`/`}`).\n const container = parent as InlineTable | InlineArray;\n const itemsBefore = container.items as TreeNode[];\n const firstBefore = itemsBefore[0];\n const lastBefore = itemsBefore[itemsBefore.length - 1];\n const originalLeadingGap = firstBefore.loc.start.column - container.loc.start.column - 1;\n const originalTrailingGap = container.loc.end.column - 1 - lastBefore.loc.end.column;\n\n remove(root, parent, node);\n insert(root, parent, node, toIndex);\n\n // Flush so consecutive Moves start from resolved positions (prevents\n // exit-offset accumulation on the same target) and so the gap\n // measurements below see final positions.\n applyWrites(root);\n\n // Restore bracket gaps corrupted by the move's offsets.\n const itemsAfter = container.items as TreeNode[];\n const firstAfter = itemsAfter[0];\n const leadingGap = firstAfter.loc.start.column - container.loc.start.column - 1;\n if (leadingGap !== originalLeadingGap) {\n shiftNode(firstAfter, {\n lines: 0,\n columns: originalLeadingGap - leadingGap\n });\n }\n const lastAfter = itemsAfter[itemsAfter.length - 1];\n const trailingGap = container.loc.end.column - 1 - lastAfter.loc.end.column;\n if (trailingGap !== originalTrailingGap) {\n container.loc.end.column = lastAfter.loc.end.column + 1 + originalTrailingGap;\n }\n}\n"],"mappings":";;;;;;;AA6BA,MAAM,cAAc,OAAO,GAAG;;AAG9B,MAAa,6BACX,IAAI,OAAO,OAAO,GAAG,QAAQ,YAAY,aAAa,YAAY,OAAO;;;;;AAM3E,MAAM,cAAc,OAAO,GAAG;;AAG9B,MAAM,2BACJ,IAAI,OAAO,OAAO,GAAG,QAAQ,YAAY,aAAa,YAAY,WAAW,YAAY,KAAK;;AAGhG,MAAa,0BACX,IAAI,OAAO,OAAO,GAAG,gBAAgB,YAAY,aAAa,YAAY,eAAe;AAE3F,SAAgB,oBAAoB,SAA2B;CAC7D,OAAO,yBAAyB,KAAK,QAAQ,GAAG,KAAK,wBAAwB,KAAK,QAAQ,GA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AAM,cAAc,UAAU;CAC9B,MAAM,cAAc,YAAY;CAChC,MAAM,aAAa,YAAY,YAAY,SAAS;CACpD,MAAM,qBAAqB,YAAY,IAAI,MAAM,SAAS,UAAU,IAAI,MAAM,SAAS;CACvF,MAAM,sBAAsB,UAAU,IAAI,IAAI,SAAS,IAAI,WAAW,IAAI,IAAI;CAE9E,OAAO,MAAM,QAAQ,IAAI;CACzB,OAAO,MAAM,QAAQ,MAAM,OAAO;CAKlC,YAAY,IAAI;CAGhB,MAAM,aAAa,UAAU;CAC7B,MAAM,aAAa,WAAW;CAC9B,MAAM,aAAa,WAAW,IAAI,MAAM,SAAS,UAAU,IAAI,MAAM,SAAS;CAC9E,IAAI,eAAe,oBACjB,UAAU,YAAY;EACpB,OAAO;EACP,SAAS,qBAAqB;CAChC,CAAC;CAEH,MAAM,YAAY,WAAW,WAAW,SAAS;CAEjD,IADoB,UAAU,IAAI,IAAI,SAAS,IAAI,UAAU,IAAI,IAAI,WACjD,qBAClB,UAAU,IAAI,IAAI,SAAS,UAAU,IAAI,IAAI,SAAS,IAAI;AAE9D"}
|
package/dist/dev/cst-source.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
//! @decimalturn/toml-patch v3.2.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
|
|
2
|
-
import { hasItems, isInlineItem, isKeyValue, isTable, isTableArray } from "./cst.js";
|
|
3
|
-
|
|
4
|
-
//#region src/cst-source.ts
|
|
5
|
-
const nodeSources = /* @__PURE__ */ new WeakMap();
|
|
6
|
-
const nodeParents = /* @__PURE__ */ new WeakMap();
|
|
7
|
-
const linkedRoots = /* @__PURE__ */ new WeakSet();
|
|
8
|
-
const originalChildren = /* @__PURE__ */ new WeakMap();
|
|
9
|
-
function positionToOffset(lineStarts, position) {
|
|
10
|
-
return (lineStarts[position.line - 1] ?? lineStarts[lineStarts.length - 1]) + position.column;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Attaches source positions to every node reachable from the given roots using
|
|
14
|
-
* a single `lineStarts` scan. This prepares a CST parsed without source
|
|
15
|
-
* attachment (the default, since attachment is only needed for patching) for
|
|
16
|
-
* the `range` and node-source lookups used by the writer and stringifier.
|
|
17
|
-
*/
|
|
18
|
-
function attachSources(roots, source) {
|
|
19
|
-
const attach = createSourceAttacher(source);
|
|
20
|
-
for (const root of roots) attach(root);
|
|
21
|
-
}
|
|
22
|
-
function createSourceAttacher(source) {
|
|
23
|
-
const lineStarts = [0];
|
|
24
|
-
for (let index = 0; index < source.length; index++) if (source.charCodeAt(index) === 10) lineStarts.push(index + 1);
|
|
25
|
-
const attach = (root) => {
|
|
26
|
-
const stack = [root];
|
|
27
|
-
while (stack.length > 0) {
|
|
28
|
-
const current = stack.pop();
|
|
29
|
-
const range = [positionToOffset(lineStarts, current.loc.start), positionToOffset(lineStarts, current.loc.end)];
|
|
30
|
-
Object.defineProperty(current, "range", {
|
|
31
|
-
configurable: true,
|
|
32
|
-
enumerable: false,
|
|
33
|
-
value: range
|
|
34
|
-
});
|
|
35
|
-
nodeSources.set(current, source);
|
|
36
|
-
originalChildren.set(current, childrenOf(current).slice());
|
|
37
|
-
if (isKeyValue(current)) {
|
|
38
|
-
stack.push(current.value);
|
|
39
|
-
stack.push(current.key);
|
|
40
|
-
} else if (isInlineItem(current)) stack.push(current.item);
|
|
41
|
-
else if (isTable(current) || isTableArray(current)) {
|
|
42
|
-
stack.push(current.key);
|
|
43
|
-
const items = current.items;
|
|
44
|
-
for (let index = items.length - 1; index >= 0; index--) stack.push(items[index]);
|
|
45
|
-
} else if (hasItems(current)) {
|
|
46
|
-
const items = current.items;
|
|
47
|
-
for (let index = items.length - 1; index >= 0; index--) stack.push(items[index]);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
return attach;
|
|
52
|
-
}
|
|
53
|
-
function getNodeSource(node) {
|
|
54
|
-
return nodeSources.get(node);
|
|
55
|
-
}
|
|
56
|
-
function sourceStructureUnchanged(node) {
|
|
57
|
-
const original = originalChildren.get(node);
|
|
58
|
-
if (!original) return false;
|
|
59
|
-
const current = childrenOf(node);
|
|
60
|
-
return original.length === current.length && original.every((child, index) => child === current[index]);
|
|
61
|
-
}
|
|
62
|
-
function childrenOf(node) {
|
|
63
|
-
if (isKeyValue(node)) return [node.key, node.value];
|
|
64
|
-
if (isInlineItem(node)) return [node.item];
|
|
65
|
-
if (isTable(node) || isTableArray(node)) return [node.key, ...node.items];
|
|
66
|
-
return hasItems(node) ? node.items : [];
|
|
67
|
-
}
|
|
68
|
-
function linkParents(root) {
|
|
69
|
-
if (linkedRoots.has(root)) return;
|
|
70
|
-
const stack = [root];
|
|
71
|
-
while (stack.length > 0) {
|
|
72
|
-
const parent = stack.pop();
|
|
73
|
-
for (const child of childrenOf(parent)) {
|
|
74
|
-
nodeParents.set(child, parent);
|
|
75
|
-
stack.push(child);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
linkedRoots.add(root);
|
|
79
|
-
}
|
|
80
|
-
function markSubtreeDirty(node) {
|
|
81
|
-
const stack = [node];
|
|
82
|
-
while (stack.length > 0) {
|
|
83
|
-
const current = stack.pop();
|
|
84
|
-
setDirty(current);
|
|
85
|
-
for (const child of childrenOf(current)) stack.push(child);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
function markTreeDirty(node) {
|
|
89
|
-
markSubtreeDirty(node);
|
|
90
|
-
}
|
|
91
|
-
function setDirty(node) {
|
|
92
|
-
Object.defineProperty(node, "dirty", {
|
|
93
|
-
configurable: true,
|
|
94
|
-
enumerable: false,
|
|
95
|
-
value: true,
|
|
96
|
-
writable: true
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
function markMutation(root, parent, changed) {
|
|
100
|
-
linkParents(root);
|
|
101
|
-
if (changed) {
|
|
102
|
-
nodeParents.set(changed, parent);
|
|
103
|
-
markSubtreeDirty(changed);
|
|
104
|
-
}
|
|
105
|
-
let current = parent;
|
|
106
|
-
while (current) {
|
|
107
|
-
setDirty(current);
|
|
108
|
-
current = nodeParents.get(current);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function originalFirstChildStartedAfterOpener(node) {
|
|
112
|
-
const original = originalChildren.get(node);
|
|
113
|
-
return !!(original === null || original === void 0 ? void 0 : original[0]) && original[0].loc.start.line > node.loc.start.line;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
//#endregion
|
|
117
|
-
export { attachSources, createSourceAttacher, getNodeSource, linkParents, markMutation, markTreeDirty, originalFirstChildStartedAfterOpener, sourceStructureUnchanged };
|
|
118
|
-
//# sourceMappingURL=cst-source.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cst-source.js","names":[],"sources":["../../src/cst-source.ts"],"sourcesContent":["import {\n TreeNode,\n hasItems,\n isInlineItem,\n isKeyValue,\n isTable,\n isTableArray\n} from './cst';\nimport { Position } from './location';\n\nconst nodeSources = new WeakMap<TreeNode, string>();\nconst nodeParents = new WeakMap<TreeNode, TreeNode>();\nconst linkedRoots = new WeakSet<TreeNode>();\nconst originalChildren = new WeakMap<TreeNode, TreeNode[]>();\n\nfunction positionToOffset(lineStarts: number[], position: Position): number {\n return (lineStarts[position.line - 1] ?? lineStarts[lineStarts.length - 1]) + position.column;\n}\n\nexport function attachSource(node: TreeNode, source: string): void {\n createSourceAttacher(source)(node);\n}\n\n/**\n * Attaches source positions to every node reachable from the given roots using\n * a single `lineStarts` scan. This prepares a CST parsed without source\n * attachment (the default, since attachment is only needed for patching) for\n * the `range` and node-source lookups used by the writer and stringifier.\n */\nexport function attachSources(roots: Iterable<TreeNode>, source: string): void {\n const attach = createSourceAttacher(source);\n for (const root of roots) attach(root);\n}\n\nexport function createSourceAttacher(source: string): (node: TreeNode) => void {\n const lineStarts = [0];\n for (let index = 0; index < source.length; index++) {\n if (source.charCodeAt(index) === 0x0a) lineStarts.push(index + 1);\n }\n\n const attach = (root: TreeNode): void => {\n const stack: TreeNode[] = [root];\n while (stack.length > 0) {\n const current = stack.pop()!;\n const range = [\n positionToOffset(lineStarts, current.loc.start),\n positionToOffset(lineStarts, current.loc.end)\n ] as const;\n\n Object.defineProperty(current, 'range', {\n configurable: true,\n enumerable: false,\n value: range\n });\n nodeSources.set(current, source);\n // Snapshot: childrenOf returns node.items by reference for some node types,\n // so a later in-place splice would also mutate the stored \"original\" list.\n originalChildren.set(current, childrenOf(current).slice());\n\n if (isKeyValue(current)) {\n stack.push(current.value);\n stack.push(current.key);\n } else if (isInlineItem(current)) {\n stack.push(current.item);\n } else if (isTable(current) || isTableArray(current)) {\n stack.push(current.key);\n const items = current.items as TreeNode[];\n for (let index = items.length - 1; index >= 0; index--) stack.push(items[index]);\n } else if (hasItems(current)) {\n const items = current.items as TreeNode[];\n for (let index = items.length - 1; index >= 0; index--) stack.push(items[index]);\n }\n }\n };\n\n return attach;\n}\n\nexport function getNodeSource(node: TreeNode): string | undefined {\n return nodeSources.get(node);\n}\n\nexport function sourceStructureUnchanged(node: TreeNode): boolean {\n const original = originalChildren.get(node);\n if (!original) return false;\n const current = childrenOf(node);\n return original.length === current.length &&\n original.every((child, index) => child === current[index]);\n}\n\nfunction childrenOf(node: TreeNode): TreeNode[] {\n if (isKeyValue(node)) return [node.key, node.value];\n if (isInlineItem(node)) return [node.item];\n if (isTable(node) || isTableArray(node)) {\n return [node.key, ...(node.items as TreeNode[])];\n }\n return hasItems(node) ? node.items as TreeNode[] : [];\n}\n\nexport function linkParents(root: TreeNode): void {\n if (linkedRoots.has(root)) return;\n\n const stack: TreeNode[] = [root];\n while (stack.length > 0) {\n const parent = stack.pop()!;\n for (const child of childrenOf(parent)) {\n nodeParents.set(child, parent);\n stack.push(child);\n }\n }\n linkedRoots.add(root);\n}\n\nfunction markSubtreeDirty(node: TreeNode): void {\n const stack: TreeNode[] = [node];\n while (stack.length > 0) {\n const current = stack.pop()!;\n setDirty(current);\n for (const child of childrenOf(current)) stack.push(child);\n }\n}\n\nexport function markTreeDirty(node: TreeNode): void {\n markSubtreeDirty(node);\n}\n\nfunction setDirty(node: TreeNode): void {\n Object.defineProperty(node, 'dirty', {\n configurable: true,\n enumerable: false,\n value: true,\n writable: true\n });\n}\n\nexport function markMutation(root: TreeNode, parent: TreeNode, changed?: TreeNode): void {\n linkParents(root);\n if (changed) {\n nodeParents.set(changed, parent);\n markSubtreeDirty(changed);\n }\n\n let current: TreeNode | undefined = parent;\n while (current) {\n setDirty(current);\n current = nodeParents.get(current);\n }\n}\n\nexport function originalFirstChildStartedAfterOpener(node: TreeNode): boolean {\n const original = originalChildren.get(node);\n return !!original?.[0] && original[0].loc.start.line > node.loc.start.line;\n}"],"mappings":";;;;AAUA,MAAM,8BAAc,IAAI,QAA0B;AAClD,MAAM,8BAAc,IAAI,QAA4B;AACpD,MAAM,8BAAc,IAAI,QAAkB;AAC1C,MAAM,mCAAmB,IAAI,QAA8B;AAE3D,SAAS,iBAAiB,YAAsB,UAA4B;CAC1E,QAAQ,WAAW,SAAS,OAAO,MAAM,WAAW,WAAW,SAAS,MAAM,SAAS;AACzF;;;;;;;AAYA,SAAgB,cAAc,OAA2B,QAAsB;CAC7E,MAAM,SAAS,qBAAqB,MAAM;CAC1C,KAAK,MAAM,QAAQ,OAAO,OAAO,IAAI;AACvC;AAEA,SAAgB,qBAAqB,QAA0C;CAC7E,MAAM,aAAa,CAAC,CAAC;CACrB,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SACzC,IAAI,OAAO,WAAW,KAAK,MAAM,IAAM,WAAW,KAAK,QAAQ,CAAC;CAGlE,MAAM,UAAU,SAAyB;EACvC,MAAM,QAAoB,CAAC,IAAI;EAC/B,OAAO,MAAM,SAAS,GAAG;GACvB,MAAM,UAAU,MAAM,IAAI;GAC1B,MAAM,QAAQ,CACZ,iBAAiB,YAAY,QAAQ,IAAI,KAAK,GAC9C,iBAAiB,YAAY,QAAQ,IAAI,GAAG,CAC9C;GAEA,OAAO,eAAe,SAAS,SAAS;IACtC,cAAc;IACd,YA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,SAAgB,YAAY,MAAsB;CAChD,IAAI,YAAY,IAAI,IAAI,GAAG;CAE3B,MAAM,QAAoB,CAAC,IAAI;CAC/B,OAAO,MAAM,SAAS,GAAG;EACvB,MAAM,SAAS,MAAM,IAAI;EACzB,KAAK,MAAM,SAAS,WAAW,MAAM,GAAG;GACtC,YAAY,IAAI,OAAO,MAAM;GAC7B,MAAM,KAAK,KAAK;EAClB;CACF;CACA,YAAY,IAAI,IAAI;AACtB;AAEA,SAAS,iBAAiB,MAAsB;CAC9C,MAAM,QAAoB,CAAC,IAAI;CAC/B,OAAO,MAAM,SAAS,GAAG;EACvB,MAAM,UAAU,MAAM,IAAI;EAC1B,SAAS,OAAO;EAChB,KAAK,MAAM,SAAS,WAAW,OAAO,GAAG,MAAM,KAAK,KAAK;CAC3D;AACF;AAEA,SAAgB,cAAc,MAAsB;CAClD,iBAAiB,IAAI;AACvB;AAEA,SAAS,SAAS,MAAsB;CACtC,OAAO,eAAe,MAAM,SAAS;EACnC,cAAc;EACd,YAAY;EACZ,OAAO;EACP,UAAU;CACZ,CAAC;AACH;AAEA,SAAgB,aAAa,MAAgB,QAAkB,SAA0B;CACvF,YAAY,IAAI;CAChB,IAAI,SAAS;EACX,YAAY,IAAI,SAAS,MAAM;EAC/B,iBAAiB,OAAO;CAC1B;CAEA,IAAI,UAAgC;CACpC,OAAO,SAAS;EACd,SAAS,OAAO;EAChB,UAAU,YAAY,IAAI,OAAO;CACnC;AACF;AAEA,SAAgB,qCAAqC,MAAyB;CAC5E,MAAM,WAAW,iBAAiB,IAAI,IAAI;CAC1C,OAAO,CAAC,sDAAC,SAAW,OAAM,SAAS,EAAE,CAAC,IAAI,MAAM,OAAO,KAAK,IAAI,MAAM;AACxE"}
|
package/dist/dev/cst.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
//! @decimalturn/toml-patch v3.2.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
|
|
2
|
-
//#region src/cst.ts
|
|
3
|
-
function isDocument(node) {
|
|
4
|
-
return node.type === "Document";
|
|
5
|
-
}
|
|
6
|
-
function isTable(node) {
|
|
7
|
-
return node.type === "Table";
|
|
8
|
-
}
|
|
9
|
-
function isTableKey(node) {
|
|
10
|
-
return node.type === "TableKey";
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Is a TableArray (aka Array of Tables)
|
|
14
|
-
* @param node
|
|
15
|
-
* @returns
|
|
16
|
-
*/
|
|
17
|
-
function isTableArray(node) {
|
|
18
|
-
return node.type === "TableArray";
|
|
19
|
-
}
|
|
20
|
-
function isTableArrayKey(node) {
|
|
21
|
-
return node.type === "TableArrayKey";
|
|
22
|
-
}
|
|
23
|
-
function isKeyValue(node) {
|
|
24
|
-
return node.type === "KeyValue";
|
|
25
|
-
}
|
|
26
|
-
function isString(node) {
|
|
27
|
-
return node.type === "String";
|
|
28
|
-
}
|
|
29
|
-
function isInteger(node) {
|
|
30
|
-
return node.type === "Integer";
|
|
31
|
-
}
|
|
32
|
-
function isFloat(node) {
|
|
33
|
-
return node.type === "Float";
|
|
34
|
-
}
|
|
35
|
-
function isBoolean(node) {
|
|
36
|
-
return node.type === "Boolean";
|
|
37
|
-
}
|
|
38
|
-
function isDateTime(node) {
|
|
39
|
-
return node.type === "DateTime";
|
|
40
|
-
}
|
|
41
|
-
function isInlineArray(node) {
|
|
42
|
-
return node.type === "InlineArray";
|
|
43
|
-
}
|
|
44
|
-
function isInlineItem(node) {
|
|
45
|
-
return node.type === "InlineItem";
|
|
46
|
-
}
|
|
47
|
-
function isInlineTable(node) {
|
|
48
|
-
return node.type === "InlineTable";
|
|
49
|
-
}
|
|
50
|
-
function isComment(node) {
|
|
51
|
-
return node.type === "Comment";
|
|
52
|
-
}
|
|
53
|
-
function hasItems(node) {
|
|
54
|
-
return isDocument(node) || isTable(node) || isTableArray(node) || isInlineTable(node) || isInlineArray(node);
|
|
55
|
-
}
|
|
56
|
-
function hasItem(node) {
|
|
57
|
-
return isTableKey(node) || isTableArrayKey(node) || isInlineItem(node);
|
|
58
|
-
}
|
|
59
|
-
function isBlock(node) {
|
|
60
|
-
return isKeyValue(node) || isTable(node) || isTableArray(node) || isComment(node);
|
|
61
|
-
}
|
|
62
|
-
function isValue(node) {
|
|
63
|
-
return isString(node) || isInteger(node) || isFloat(node) || isBoolean(node) || isDateTime(node) || isInlineArray(node) || isInlineTable(node);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
|
-
export { hasItem, hasItems, isBlock, isBoolean, isComment, isDateTime, isDocument, isFloat, isInlineArray, isInlineItem, isInlineTable, isInteger, isKeyValue, isString, isTable, isTableArray, isTableArrayKey, isTableKey, isValue };
|
|
68
|
-
//# sourceMappingURL=cst.js.map
|
package/dist/dev/cst.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cst.js","names":[],"sources":["../../src/cst.ts"],"sourcesContent":["import { Location } from './location';\n\nexport enum NodeType {\n Document = 'Document',\n Table = 'Table',\n TableKey = 'TableKey',\n /**\n * Array of Tables node\n * More info: https://toml.io/en/latest#array-of-tables\n */\n TableArray = 'TableArray',\n TableArrayKey = 'TableArrayKey',\n KeyValue = 'KeyValue',\n Key = 'Key',\n String = 'String',\n Integer = 'Integer',\n Float = 'Float',\n Boolean = 'Boolean',\n DateTime = 'DateTime',\n InlineArray = 'InlineArray',\n InlineItem = 'InlineItem',\n InlineTable = 'InlineTable',\n /**\n * Comment node\n * More info: https://toml.io/en/latest#comment\n */\n Comment = 'Comment'\n}\n\n//\n// Concrete Syntax Tree\n//\n// CST nodes are used to represent TOML data\n//\nexport type CST = Iterable<Block>;\n\n//\n// Document\n//\n// Top-level document that stores CST nodes\n//\nexport interface Document extends TreeNode {\n type: NodeType.Document;\n items: Array<Block>;\n}\nexport function isDocument(node: TreeNode): node is Document {\n return node.type === NodeType.Document;\n}\n\n//\n// Table\n//\n// Top-level object\n//\n// v-------|\n// [table] |\n// b = \"c\" |\n// |\n// # note |\n// ^--|\n// [b]\n//\nexport interface Table extends TreeNode {\n type: NodeType.Table;\n key: TableKey;\n items: RowItem[];\n}\nexport function isTable(node: TreeNode): node is Table {\n return node.type === NodeType.Table;\n}\n\n//\n// TableKey\n//\n// Used to store bracket information for Table keys\n//\n// loc includes brackets\n//\n// [ key ]\n// ^-------^\n//\nexport interface TableKey extends TreeNode {\n type: NodeType.TableKey;\n item: Key;\n}\nexport function isTableKey(node: TreeNode): node is TableKey {\n return node.type === NodeType.TableKey;\n}\n\n//\n// TableArray\n//\n// Top-level array item\n//\n// v---------|\n// [[array]] |\n// a=\"b\" |\n// |\n// # details |\n// ^-|\n// [[array]]\n//\nexport interface TableArray extends TreeNode {\n type: NodeType.TableArray;\n key: TableArrayKey;\n items: RowItem[];\n}\n\n/**\n * Is a TableArray (aka Array of Tables)\n * @param node \n * @returns \n */\nexport function isTableArray(node: TreeNode): node is TableArray {\n return node.type === NodeType.TableArray;\n}\n\n//\n// TableArrayKey\n//\n// Used to store bracket information for TableArray keys\n// loc includes brackets\n//\n// [[ key ]]\n// ^---------^\n//\nexport interface TableArrayKey extends TreeNode {\n type: NodeType.TableArrayKey;\n item: Key;\n}\nexport function isTableArrayKey(node: TreeNode): node is TableArrayKey {\n return node.type === NodeType.TableArrayKey;\n}\n\n//\n// KeyValue\n//\n// Key and Value nodes, with position information on equals sign\n//\n// key=\"value\" # note\n// ^---------^\n//\nexport interface KeyValue extends TreeNode {\n type: NodeType.KeyValue;\n key: Key;\n value: Value;\n\n // Column index (0-based) of the equals sign\n equals: number;\n}\nexport function isKeyValue(node: TreeNode): node is KeyValue {\n return node.type === NodeType.KeyValue;\n}\n\n//\n// Key\n//\n// Store raw key and parts (from dots)\n//\nexport interface Key extends TreeNode {\n type: NodeType.Key;\n raw: string;\n\n // Note: Array for keys with dots\n // e.g. a.b -> raw = 'a.b', value = ['a', 'b']\n value: string[];\n}\nexport function isKey(node: TreeNode): node is Key {\n return node.type === NodeType.Key;\n}\n\n//\n// String\n//\n// loc includes quotes\n//\n// a = \"string\"\n// ^------^\n//\nexport interface String extends TreeNode {\n type: NodeType.String;\n raw: string;\n value: string;\n}\nexport function isString(node: TreeNode): node is String {\n return node.type === NodeType.String;\n}\n\n//\n// Integer\n//\nexport interface Integer extends TreeNode {\n type: NodeType.Integer;\n raw: string;\n value: number | bigint;\n}\nexport function isInteger(node: TreeNode): node is Integer {\n return node.type === NodeType.Integer;\n}\n\n//\n// Float\n//\nexport interface Float extends TreeNode {\n type: NodeType.Float;\n raw: string;\n value: number;\n /** Sign prefix for NaN values: '+' for +nan, '-' for -nan, undefined for nan */\n nanSign?: '+' | '-';\n}\nexport function isFloat(node: TreeNode): node is Float {\n return node.type === NodeType.Float;\n}\n\n//\n// Boolean\n//\nexport interface Boolean extends TreeNode {\n type: NodeType.Boolean;\n\n // Only `true` and `false` are permitted\n // -> don't need separate raw and value\n value: boolean;\n}\nexport function isBoolean(node: TreeNode): node is Boolean {\n return node.type === NodeType.Boolean;\n}\n\n//\n// DateTime\n//\n// Note: Currently, Offset Date-Time, Local Date-Time, Local Date, and Local Time\n// are handled via raw\n//\nexport interface DateTime extends TreeNode {\n type: NodeType.DateTime;\n raw: string;\n value: Date;\n}\nexport function isDateTime(node: TreeNode): node is DateTime {\n return node.type === NodeType.DateTime;\n}\n\n//\n// InlineArray\n//\nexport interface InlineArray<TItem = TreeNode> extends TreeNode {\n type: NodeType.InlineArray;\n items: InlineArrayItem<TItem>[];\n}\nexport function isInlineArray(node: TreeNode): node is InlineArray {\n return node.type === NodeType.InlineArray;\n}\n\n// InlineItem (internal CST wrapper — not a TOML spec concept)\n//\n// InlineItem is a container node that wraps each element inside an inline\n// container (InlineArray or InlineTable). It carries two responsibilities:\n//\n// 1. Tracking the comma that follows the element (comma: boolean).\n// When the element is the last one in the container, `comma` may be\n// false (no trailing comma) or true (trailing comma, TOML 1.1+).\n//\n// 2. Providing a stable \"slot\" node in the parent's .items array so that\n// the writer can apply positional offsets independently of the wrapped\n// value node itself.\n//\n// It is generic over TItem so that the two concrete subtypes can constrain\n// what they wrap:\n//\n// InlineArrayItem<TItem> — wraps any Value (scalar, array, inline table)\n// InlineTableItem — always wraps a KeyValue\n//\n// Location:\n// loc spans from the start of the wrapped value to the character just\n// before the comma (or the end of the value when there is no comma).\n//\n// [ \"a\" ,\"b\", \"c\" ]\n// ^---^ ^-^ ^-^\n//\n// { a = 1 , b = 2 }\n// ^---^ ^---^\n//\n// Note on findByPath traversal:\n// When navigating a path into an InlineArray, findByPath matches numeric\n// indices to InlineArrayItem positions. When the wrapped item is an\n// InlineTable and the path has further segments to resolve, traversal\n// continues into item.item (the InlineTable), not into the InlineItem\n// wrapper itself (which has no .items of its own).\n//\nexport interface InlineItem<TItem = TreeNode> extends TreeNode {\n type: NodeType.InlineItem;\n item: TItem;\n comma: boolean;\n}\nexport function isInlineItem(node: TreeNode): node is InlineItem {\n return node.type === NodeType.InlineItem;\n}\n\n// InlineArrayItem — semantic alias for InlineItem used as the element type of\n// InlineArray.items. It adds no fields; its existence is purely documentary:\n// naming the subtype makes the array-vs-table distinction visible in type\n// annotations without requiring an extra runtime check.\n//\n// TItem can be any Value: a scalar (String, Integer, …), a nested InlineArray,\n// or an InlineTable. The generic parameter is propagated so that typed arrays\n// such as InlineArray<String> carry their element type through to the items.\n//\n// [ \"a\" ,\"b\", \"c\" ]\n// ^---^ ^-^ ^-^ ← each element is an InlineArrayItem\n//\nexport interface InlineArrayItem<TItem = TreeNode> extends InlineItem<TItem> {}\n\n//\n// InlineTable\n//\nexport interface InlineTable extends TreeNode {\n type: NodeType.InlineTable;\n items: InlineTableItem[];\n}\nexport function isInlineTable(node: TreeNode): node is InlineTable {\n return node.type === NodeType.InlineTable;\n}\n\n// InlineTableItem — semantic alias for InlineItem<KeyValue> used as the element type\n// of InlineTable.items. It adds no fields; its existence is purely documentary:\n// naming the subtype makes the array-vs-table distinction visible in type\n// annotations without requiring an extra runtime check.\n//\n// The type parameter is fixed to KeyValue, which means the unsafe cast\n// `existing.item as KeyValue` that previously appeared in patch.ts is\n// unnecessary — the type system already guarantees it.\n//\n// { a=\"b\" , c = \"d\" }\n// ^------^ ^--------^ ← each element is an InlineTableItem\n//\nexport interface InlineTableItem extends InlineItem<KeyValue> {}\n\n//\n// Comment\n//\n// loc starts at \"#\" and goes to end of comment (trailing whitespace ignored)\n//\n// # comment here\n// ^------------^\n//\nexport interface Comment extends TreeNode {\n type: NodeType.Comment;\n raw: string;\n}\nexport function isComment(node: TreeNode): node is Comment {\n return node.type === NodeType.Comment;\n}\n\n//\n// Combinations\n//\n\n/**\n * RowItem represents items that can appear inside Table and TableArray sections.\n * These are the items that form the \"rows\" of content within table structures.\n * \n * Unlike Block items (which include Table and TableArray), RowItems can only be\n * KeyValue pairs and Comments - you cannot have nested tables within a table section.\n */\nexport type RowItem = KeyValue | Comment;\nexport function isRowItem(node: TreeNode): node is RowItem {\n return isKeyValue(node) || isComment(node);\n}\n\nexport interface WithItems extends TreeNode {\n items: TreeNode[];\n}\nexport function hasItems(node: TreeNode): node is WithItems {\n return (\n isDocument(node) ||\n isTable(node) ||\n isTableArray(node) ||\n isInlineTable(node) ||\n isInlineArray(node)\n );\n}\n\nexport interface WithItem extends TreeNode {\n item: TreeNode;\n}\nexport function hasItem(node: TreeNode): node is WithItem {\n return isTableKey(node) || isTableArrayKey(node) || isInlineItem(node);\n}\n\n/**\n * Block represents items that can appear at the root level (Document level) in TOML.\n * \n * Context and Usage:\n * - Block items are the fundamental top-level constructs in a TOML document\n * - They appear directly in Document containers and regular Table sections\n * - This is in contrast to InlineItems, which appear within inline containers\n * \n * Important Distinction:\n * - Table and TableArray can ONLY exist as Block items (they cannot appear inside inline containers)\n * - KeyValue and Comment can exist as BOTH Block items AND as InlineItems:\n * * As Block: When they appear at root level or inside regular Table sections\n * * As InlineItem: When they appear inside InlineTable or InlineArray containers\n * \n * Examples:\n * ```toml\n * # These are Block items at root level:\n * name = \"value\" # KeyValue as Block\n * # This is a comment # Comment as Block\n * [table] # Table as Block\n * [[array]] # TableArray as Block\n * \n * # These are Block items inside a Table:\n * [config]\n * setting = \"value\" # KeyValue as Block (inside Table)\n * # comment here # Comment as Block (inside Table)\n * \n * # These are InlineItems (NOT Block items):\n * array = [ \"a\", \"b\" ] # \"a\", \"b\" are InlineItems\n * table = { key = \"value\" } # key=\"value\" is InlineItem\n * ```\n * \n * Type Safety:\n * This distinction is crucial for the CST structure because:\n * - Document.items: Block[]\n * - Table.items: RowItem[] (KeyValue | Comment)\n * - TableArray.items: RowItem[] (KeyValue | Comment)\n * - InlineArray.items: InlineArrayItem[] (which extends InlineItem)\n * - InlineTable.items: InlineTableItem[] (which extends InlineItem)\n */\nexport type Block = KeyValue | Table | TableArray | Comment;\nexport function isBlock(node: TreeNode): node is Block {\n return isKeyValue(node) || isTable(node) || isTableArray(node) || isComment(node);\n}\n\nexport type Value<TInlineArrayItem = TreeNode> =\n | String\n | Integer\n | Float\n | Boolean\n | DateTime\n | InlineArray<TInlineArrayItem>\n | InlineTable;\nexport function isValue(node: TreeNode): node is Value {\n return (\n isString(node) ||\n isInteger(node) ||\n isFloat(node) ||\n isBoolean(node) ||\n isDateTime(node) ||\n isInlineArray(node) ||\n isInlineTable(node)\n );\n}\n\nexport interface TreeNode {\n type: NodeType;\n loc: Location;\n /** Absolute UTF-16 offsets into the source that produced this node. */\n readonly range?: readonly [number, number];\n /** Set on generated or mutated nodes and propagated to their ancestors. */\n dirty?: boolean;\n}\n"],"mappings":";;AA6CA,SAAgB,WAAW,MAAkC;CAC3D,OAAO,KAAK;AACd;AAoBA,SAAgB,QAAQ,MAA+B;CACrD,OAAO,KAAK;AACd;AAgBA,SAAgB,WAAW,MAAkC;CAC3D,OAAO,KAAK;AACd;;;;;;AA0BA,SAAgB,aAAa,MAAoC;CAC/D,OAAO,KAAK;AACd;AAeA,SAAgB,gBAAgB,MAAuC;CACrE,OAAO,KAAK;AACd;AAkBA,SAAgB,WAAW,MAAkC;CAC3D,OAAO,KAAK;AACd;AAgCA,SAAgB,SAAS,MAAgC;CACvD,OAAO,KAAK;AACd;AAUA,SAAgB,UAAU,MAAiC;CACzD,OAAO,KAAK;AACd;AAYA,SAAgB,QAAQ,MAA+B;CACrD,OAAO,KAAK;AACd;AAYA,SAAgB,UAAU,MAAiC;CACzD,OAAO,KAAK;AACd;AAaA,SAAgB,WAAW,MAAkC;CAC3D,OAAO,KAAK;AACd;AASA,SAAgB,cAAc,MAAqC;CACjE,OAAO,KAAK;AACd;AA2CA,SAAgB,aAAa,MAAoC;CAC/D,OAAO,KAAK;AACd;AAuBA,SAAgB,cAAc,MAAqC;CACjE,OAAO,KAAK;AACd;AA4BA,SAAgB,UAAU,MAAiC;CACzD,OAAO,KAAK;AACd;AAqBA,SAAgB,SAAS,MAAmC;CAC1D,OACE,WAAW,IAAI,KACf,QAAQ,IAAI,KACZ,aAAa,IAAI,KACjB,cAAc,IAAI,KAClB,cAAc,IAAI;AAEtB;AAKA,SAAgB,QAAQ,MAAkC;CACxD,OAAO,WAAW,IAAI,KAAK,gBAAgB,IAAI,KAAK,aAAa,IAAI;AACvE;AA2CA,SAAgB,QAAQ,MAA+B;CACrD,OAAO,WAAW,IAAI,KAAK,QAAQ,IAAI,KAAK,aAAa,IAAI,KAAK,UAAU,IAAI;AAClF;AAUA,SAAgB,QAAQ,MAA+B;CACrD,OACE,SAAS,IAAI,KACb,UAAU,IAAI,KACd,QAAQ,IAAI,KACZ,UAAU,IAAI,KACd,WAAW,IAAI,KACf,cAAc,IAAI,KAClB,cAAc,IAAI;AAEtB"}
|
package/dist/dev/cursor.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
//! @decimalturn/toml-patch v3.2.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
|
|
2
|
-
//#region src/cursor.ts
|
|
3
|
-
/**
|
|
4
|
-
* Cursor<T>
|
|
5
|
-
*
|
|
6
|
-
* A utility class that wraps an iterator and provides additional functionality
|
|
7
|
-
* such as peeking at the next value without advancing the iterator, tracking
|
|
8
|
-
* the current index, and iterating over the values.
|
|
9
|
-
*
|
|
10
|
-
* @template T - The type of elements in the iterator.
|
|
11
|
-
*
|
|
12
|
-
* Properties:
|
|
13
|
-
* - `iterator`: The underlying iterator being wrapped.
|
|
14
|
-
* - `index`: The current index of the iterator (starts at -1).
|
|
15
|
-
* - `value`: The current value of the iterator.
|
|
16
|
-
* - `done`: A boolean indicating whether the iterator is complete.
|
|
17
|
-
* - `peeked`: The result of peeking at the next value without advancing.
|
|
18
|
-
*
|
|
19
|
-
* Methods:
|
|
20
|
-
* - `next()`: Advances the iterator and returns the next value.
|
|
21
|
-
* - `peek()`: Returns the next value without advancing the iterator.
|
|
22
|
-
* - `[Symbol.iterator]`: Makes the Cursor itself iterable.
|
|
23
|
-
*/
|
|
24
|
-
var Cursor = class {
|
|
25
|
-
iterator;
|
|
26
|
-
index;
|
|
27
|
-
value;
|
|
28
|
-
done;
|
|
29
|
-
peeked;
|
|
30
|
-
constructor(iterator) {
|
|
31
|
-
this.iterator = iterator;
|
|
32
|
-
this.index = -1;
|
|
33
|
-
this.value = void 0;
|
|
34
|
-
this.done = false;
|
|
35
|
-
this.peeked = null;
|
|
36
|
-
}
|
|
37
|
-
next() {
|
|
38
|
-
if (this.done) return done();
|
|
39
|
-
const result = this.peeked || this.iterator.next();
|
|
40
|
-
this.index += 1;
|
|
41
|
-
this.value = result.value;
|
|
42
|
-
this.done = result.done ?? false;
|
|
43
|
-
this.peeked = null;
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
peek() {
|
|
47
|
-
if (this.done) return done();
|
|
48
|
-
if (this.peeked) return this.peeked;
|
|
49
|
-
this.peeked = this.iterator.next();
|
|
50
|
-
return this.peeked;
|
|
51
|
-
}
|
|
52
|
-
[Symbol.iterator]() {
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const DONE = Object.freeze({
|
|
57
|
-
value: void 0,
|
|
58
|
-
done: true
|
|
59
|
-
});
|
|
60
|
-
function done() {
|
|
61
|
-
return DONE;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
//#endregion
|
|
65
|
-
export { Cursor as default };
|
|
66
|
-
//# sourceMappingURL=cursor.js.map
|
package/dist/dev/cursor.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cursor.js","names":[],"sources":["../../src/cursor.ts"],"sourcesContent":["export function iterator(value: string): Iterator<string>;\nexport function iterator<T>(value: Iterable<T>): Iterator<T>;\nexport function iterator<T>(value: Iterable<T> | string): Iterator<T | string> {\n if (typeof value === 'string') {\n return utf16Iterator(value);\n }\n return value[Symbol.iterator]();\n}\n\n/**\n * Cursor<T>\n * \n * A utility class that wraps an iterator and provides additional functionality\n * such as peeking at the next value without advancing the iterator, tracking\n * the current index, and iterating over the values.\n * \n * @template T - The type of elements in the iterator.\n * \n * Properties:\n * - `iterator`: The underlying iterator being wrapped.\n * - `index`: The current index of the iterator (starts at -1).\n * - `value`: The current value of the iterator.\n * - `done`: A boolean indicating whether the iterator is complete.\n * - `peeked`: The result of peeking at the next value without advancing.\n * \n * Methods:\n * - `next()`: Advances the iterator and returns the next value.\n * - `peek()`: Returns the next value without advancing the iterator.\n * - `[Symbol.iterator]`: Makes the Cursor itself iterable.\n */\nexport default class Cursor<T> implements Iterator<T | undefined> {\n iterator: Iterator<T>;\n index: number;\n value?: T;\n done: boolean;\n peeked: IteratorResult<T | undefined> | null;\n\n constructor(iterator: Iterator<T>) {\n this.iterator = iterator;\n this.index = -1;\n this.value = undefined;\n this.done = false;\n this.peeked = null;\n }\n\n next(): IteratorResult<T | undefined> {\n if (this.done) return done();\n\n const result = this.peeked || this.iterator.next();\n\n this.index += 1;\n this.value = result.value;\n this.done = result.done ?? false;\n this.peeked = null;\n\n return result;\n }\n\n peek(): IteratorResult<T | undefined> {\n if (this.done) return done();\n if (this.peeked) return this.peeked;\n\n this.peeked = this.iterator.next();\n return this.peeked;\n }\n\n [Symbol.iterator]() {\n return this;\n }\n}\n\nconst DONE: IteratorResult<undefined> = Object.freeze({ value: undefined, done: true });\n\nfunction done(): IteratorResult<undefined> {\n return DONE;\n}\n\n/**\n * Creates a UTF-16 code unit iterator for a string.\n * This is necessary because cursor.index is used to access string positions\n * via input[cursor.index] and input.slice() throughout the tokenizer.\n * While Symbol.iterator yields code points (better for humans), we need\n * UTF-16 indices for correct string access in JavaScript.\n */\nfunction* utf16Iterator(str: string): Generator<string, void, unknown> {\n for (let i = 0; i < str.length; i++) {\n yield str[i];\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAqB,SAArB,MAAkE;CAChE;CACA;CACA;CACA;CACA;CAEA,YAAY,UAAuB;EACjC,KAAK,WAAW;EAChB,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,OAAO;EACZ,KAAK,SAAS;CAChB;CAEA,OAAsC;EACpC,IAAI,KAAK,MAAM,OAAO,KAAK;EAE3B,MAAM,SAAS,KAAK,UAAU,KAAK,SAAS,KAAK;EAEjD,KAAK,SAAS;EACd,KAAK,QAAQ,OAAO;EACpB,KAAK,OAAO,OAAO,QAAQ;EAC3B,KAAK,SAAS;EAEd,OAAO;CACT;CAEA,OAAsC;EACpC,IAAI,KAAK,MAAM,OAAO,KAAK;EAC3B,IAAI,KAAK,QAAQ,OAAO,KAAK;EAE7B,KAAK,SAAS,KAAK,SAAS,KAAK;EACjC,OAAO,KAAK;CACd;CAEA,CAAC,OAAO,YAAY;EAClB,OAAO;CACT;AACF;AAEA,MAAM,OAAkC,OAAO,OAAO;CAAE,OAAO;CAAW,MAAM;AAAK,CAAC;AAEtF,SAAS,OAAkC;CACzC,OAAO;AACT"}
|