feat(ast): support moving and copying nodes by path - #971
Conversation
|
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a206fdd47b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| moved := *source | ||
| if err := self.setByPath(dst, moved); err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
Preserve nested destinations when removing an earlier array item
When the source is an array element and the destination is nested beneath a later element of that same array, writing the destination before deleting the source shifts the destination to a different index. For example, moving path {0} to {1, "x"} in ["a", {}] returns success but produces [{"x":"a"}], where the requested destination path no longer exists. The move must account for the index shift or resolve/create the destination after removing the earlier source element.
Useful? React with 👍 / 👎.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #971 +/- ##
==========================================
+ Coverage 51.86% 53.53% +1.66%
==========================================
Files 127 171 +44
Lines 10893 14401 +3508
==========================================
+ Hits 5650 7710 +2060
- Misses 4920 6595 +1675
+ Partials 323 96 -227
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What type of PR is this?
feat
Check the PR title.
(Optional) Translate the PR title into Chinese.
feat(ast): 支持按路径移动和复制节点
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
ast.Path,Node.MovePath, andNode.CopyPathfor reshaping JSON trees at arbitrary depth.null, preserve existing in-array move/reorder semantics, and reject moves into a source descendant.Validation (Go 1.25.12, macOS arm64):
go test -raceacross the package set used by the upstream ARM CI workflow.(cd issue_test && go test -race ./...).SONIC_USE_OPTDEC=1 SONIC_USE_FASTMAP=1 SONIC_ENCODER_USE_VM=1 go test ./ast -count=1.zh:
null、同数组重排与复制隔离。(Optional) Which issue(s) this PR fixes:
Fixes #732
(optional) The PR that updates user documentation:
The in-repository AST README section is updated in this PR.