Repository navigation
fix: preserve nested table-array scoping - #329
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Empty-array restoration can create incorrect nesting, and nested path lookup introduces quadratic scanning.
2 open issues
What changed in this PR
This PR improves nested TOML table-array patching so changes stay within the owning entry.
Changes:
- Scope sub-table cleanup and nested path resolution to the correct entry.
- Preserve parent indices when restoring emptied arrays.
- Add regression tests and a changelog entry.
| File | Description |
|---|---|
| src/patch.ts | Adjusts cleanup scope and empty-array restoration. |
| src/find-by-path.ts | Adds scoped lookup through nested table arrays. |
| src/__tests__/patch.test.ts | Adds three nested-entry regression tests. |
| CHANGELOG.md | Documents the patching fixes. |
Review effort: Balanced
Benchmark comparisonThis branch measured against Fixture Benchmark ResultsTime per iteration. Lower is better. Parse, smol-toml spec example (toml-spec-example.toml)
Parse, smol-toml 5MB mixed (5mb-mixed.toml)
Parse, iarna spec example v0.4.0 (0A-spec-01-example-v0.4.0.toml)
Stringify, smol-toml spec example (toml-spec-example.toml)
Stringify, smol-toml 5MB mixed (5mb-mixed.toml)
Stringify, iarna spec example v0.4.0 (0A-spec-01-example-v0.4.0.toml)
|
DecimalTurn
marked this pull request as ready for review
October 18, 2026 22:15
- Build object replacements under an explicit parent with inlineTableStart 0 so they stay a single row instead of a [key] section that fell through to a dotted rebuild colliding with the existing header. - Insert replacement [[sections]] where the removed sub-table was, and otherwise after the entry's own sections rather than after unrelated tables in its scope.
Structural edits below an explicit [table] outside any AOT entry were rebuilt from the root, emitting an inline table that collided with the surviving parent header. Replace them inside the deepest explicit parent instead, inserting [[sections]] where the old sub-table was. Share the explicit-parent lookup, row replacement and section insertion helpers with the AOT entry path.
Replacing a value more than one key below the deepest explicit [table]
(or below no explicit table at all) fell through to a rebuild that nested
the implicit intermediates as an inline table, e.g. `args = { deep = … }`,
which a surviving `[route.args.other]` header can't extend.
- Render the explicit-parent replacement row with a dotted key for any
relative key length, in both the AOT entry and regular table paths.
- With no explicit ancestor, emit a root dotted row when a surviving header
extends one of the implicit intermediates.
- Share the row re-keying with the AOT tail flattening.
New root key-values were placed directly above the first section header, between the header and the comment block R2 assigns to it, so the comment read as introducing the new key. Back up over that block, and route every root insertion point through rootKeyValueInsertIndex so they agree.
Scoping key-value validation per AOT entry looked the scope up from the key's full path, so `arr = 2` under `[parent-table]` after `[[parent-table.arr]]` landed in the array's own entry scope and missed that the array was already defined (toml-test invalid/table/overwrite-array-in-parent). Scope by the key's container instead, like the table header handlers.
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.


This PR mainly combines nested AOT bugs and other minor bugs.
Fixed
[[array]]entry defined with a header.[table]header no longer produces invalid TOML when a sibling header still extends the table in between.Changed