fix: ensure root KV are properly inserted at the top of the document#171
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes incorrect placement of newly-added root-level key/value pairs so they’re inserted into TOML’s implicit root table (before the first [table] / [[array-of-tables]] header), addressing issue #170.
Changes:
- Clamp insertion index for new root-level
KeyValuenodes to the end of the implicit root table scope (before the first table/AoT header). - Adjust writer line-offset logic when prepending into a non-empty document to correctly shift existing content down.
- Add regression tests for root key/value placement relative to tables and AoT sections.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/writer.ts |
Adds special-case handling for inserting at the start of a non-empty document so existing nodes are shifted correctly. |
src/patch.ts |
Ensures root-level key/values are inserted before the first explicit table/AoT section rather than appended at the document end. |
src/__tests__/patch.test.ts |
Adds coverage for root key/value placement before sections/AoTs (and includes one currently skipped inline-table scenario). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Fixes #170