fix: patching errors - #276
Merged
Merged
Conversation
DecimalTurn
commented
Aug 9, 2026
Owner
- fix: tighten empty single-line inline tables and propagate to parent containers
- fix: unwrap InlineArrayItem when inserting into nested inline array
…containers When the only item is removed from a single-line InlineTable, the closing brace stayed at its original far-right position because the tightening code only handled non-empty tables (node.items.length > 0). Now also handles empty tables by setting loc.end.column = loc.start.column + 2. Additionally, nested InlineTable tightening doesn't propagate through the offset system (remove() zeros the offset for single-item, no-sibling removals), so parent container end positions must be recalculated explicitly via a new recalcInlineContainerEnds() function. This walks single-line InlineTables/InlineArrays and adjusts their end positions when a descendant was tightened, preserving the original bracket-spacing gap. Also fixed the test to use valid TOML (quoted keys for special characters) instead of bare keys with invalid characters like *.
There was a problem hiding this comment.
Pull request overview
This PR fixes two patching failure modes in the TOML patcher: inserting into nested inline arrays and tightening single-line inline tables after removals (including empty tables), with new regression tests for both previously failing scenarios.
Changes:
- Unwrap
InlineItemwrappers when the parent container is a nestedInlineArray, soinsert()receives a node with.items. - Tighten single-line inline tables after removals even when the table becomes empty (
{}), and attempt to propagate end-column shrinking to ancestor inline containers. - Convert previously
test.failsregression cases into passing tests, including corrected TOML quoting for special-character keys.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/patch.ts | Fixes parent unwrapping for nested inline-array inserts; improves inline-table tightening and adds ancestor end-position recalculation. |
| src/tests/patch.test.ts | Adds/updates regression tests to ensure the reported patching errors no longer occur. |
Suppressed comments (1)
src/patch.ts:1688
- InlineArray recalculation only looks through KeyValue→InlineTable, but InlineArray items can directly wrap InlineTable/InlineArray values. If the last element is a nested inline container whose loc.end changed (directly or via prior recalculation), the parent array end can remain stale. Consider resolving the end column from lastItem.item when it is an InlineTable or InlineArray, and run this visitor on exit to support nested propagation.
InlineArray: (node) => {
if (node.items.length === 0) return;
if (node.loc.end.line !== node.loc.start.line) return;
const lastItem = node.items[node.items.length - 1];
let innerEndCol = lastItem.loc.end.column;
if (isInlineItem(lastItem) && isKeyValue(lastItem.item) && isInlineTable(lastItem.item.value)) {
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Switch from pre-order (inline function) to post-order (exit) visitors so child inline containers are recalculated before their parents. Also broadened the inner-end-column lookup to handle InlineArray values in addition to InlineTable.
Verifies recalcInlineContainerEnds correctly propagates end-column fixes
through three levels of nesting: outer { mid { inner { k = "x" } } }.
A pre-order traversal would read the inner table is stale loc.end and
leave trailing whitespace before the outer closing braces.
…gaps Three known gaps marked as test.fails: - Emptying a single-line inline array leaves trailing whitespace - Emptying a nested inline array inside an inline table has same issue - Tightening an inline table inside an inline array does not propagate to the outer container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.