Skip to content

fix: patching errors - #276

Merged
DecimalTurn merged 7 commits into
latestfrom
dev-fuzz-fix
Aug 9, 2026
Merged

fix: patching errors#276
DecimalTurn merged 7 commits into
latestfrom
dev-fuzz-fix

Conversation

@DecimalTurn

Copy link
Copy Markdown
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 *.
Copilot AI lite review requested due to automatic review settings August 9, 2026 03:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 InlineItem wrappers when the parent container is a nested InlineArray, so insert() 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.fails regression 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.

Comment thread src/patch.ts
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
@DecimalTurn
DecimalTurn merged commit 5346dbb into latest Aug 9, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants