getNodePath/modify do not work for property nodes (capture too much content)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- typescript
- Lĩnh vực
- tooling
Hướng nghiên cứu
Bắt đầu với việc tái hiện trong src/app.ts và chạy npm install && npm run build, sau đó chạy lệnh node được ghi trong tài liệu. Kiểm tra các entry point getNodePath và modify đối chiếu với hành vi của property path được mô tả trong issue. Được xem là hoàn tất khi findNodeAtLocation(tree, getNodePath(node)) trả về property node và modify chỉ xóa property đó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
When run on a property node, getNodePath appears to instead returns a path to the enclosing dictionary of the property. This results in some serious problems:
findNodeAtLocation(tree, getNodePath(node))is a different node fromnode.- Calling
modify()on a property node removes additional content other than the property node targeted.
Repro steps
Check out the jsonc-parser-demo branch of this github repo.
Run these steps:
npm install && npm run build
node . -d transformBackground testcase.json > testcase-post.json
src/app.ts in this repro is a short script that processes a json file and removes all instances of the property whose key name is given as the -d argument, then prints the file out to STDOUT. To demonstrate the bug more clearly, it currently removes only the first instance before bailing out, and once it has identified the property to be removed it console.warns to STDERR (1) the node it intends to remove (2) the getNodePath of the target node and (3) the roundtrip result of findNodeAtLocation(tree, getNodePath(node)) on the target node. The important code in this example is the code immediately following the comment "PERFORM OPERATIONS HERE"; everything else only serves to load the file and walk the node tree.
My expected behavior running this test script on the included testcase JSON is that on STDERR the "DELETING" and "BUT REALLY DELETING" nodes will be the same (ie, findNodeAtLocation(tree, getNodePath(node)) should be a noop); and on STDOUT the single property "transformBackground" in the dictionary levels/0/screen will be removed.
My observed behavior is quite different:
- The path printed is
[ 'levels', 0, 'screen' ]. In other words, as printed, it points to the enclosing dictionary, not thetransformBackgroundproperty. - The "DELETING" prints as expected the property I'm looking for, but the "BUT REALLY DELETING" is different and contains much more content— it does appear to encompass the entire dictionary stored under "screen".
- After applying the edits, jsondiff shows this change for the output file:
[{"path": "/levels/0", "value": {"color": [0.3, 0.37, 1], "png": "level/test/trigger/trigger.png"}, "op": "replace"}]. In other words, it shows the "screen" property and its value were deleted from /levels/0.
Analysis
I am able to get the "expected behavior" I desire by, instead of passing at.node to getNodePath in the "PERFORM OPERATIONS HERE" section, passing in either of its children. If I do this I get the path [ 'levels', 0, 'screen', 'transformBackground' ] as expected and this is indeed the content that gets removed. However this feels wierd, and additionally it contradicts the documentation. The comment/doc for modify says: " * @param path The path of the value to change. The path represents either to the document root, a property or an array item." This implies modify should accept property nodes.
- Ngôn ngữ chính
- TypeScript
- Star
- 759
- Fork
- 66
- Merge trung bình
- 5 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 7
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/node-jsonc-parser
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
microsoft/node-jsonc-parser#125 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
microsoft/node-jsonc-parser#105 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
microsoft/node-jsonc-parser#103 · 2 bình luận · 8 reaction ·
-
Provide usage examples Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 48/100
microsoft/node-jsonc-parser#97 · 2 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
microsoft/node-jsonc-parser#95 · 1 reaction ·
Tất cả issue của microsoft/node-jsonc-parser
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
copse-dev/agent-pane#2953 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
[Bug]: Matrix progress drafts fail with "Matrix runtime not initialized" during tool activity Đang mởbug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Client support matrix inclusion Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
calcite-components needs triage refactor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Esri/calcite-design-system#15203 ·