Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

fix(rome_js_analyze): fix the removal of nodes from syntax lists in batch mutations #2980

Merged
merged 3 commits into from
Aug 2, 2022

Conversation

leops
Copy link
Contributor

@leops leops commented Aug 1, 2022

Summary

This PR fixes #2966 by changing the behavior of the remove_node batch mutation method in syntax lists, making it actually remove the corresponding slot from the list instead of replacing the previous node with an empty slot.

In order to make this work the batch mutation now has to track the number of removed slots in a node to adjust the indices of other modifications being applied to the same node, in turn this means I had to change the ordering semantics of mutation changes slightly so that modifications that apply to the same node are sorted in increasing order by the index of the slot they are modifying.

Test Plan

To test this change and protect from future regressions I modified the analyzer tests to perform additional checks on the syntax tree emitted by code actions. These checks include:

  • verifying that applying the text edits returned by as_text_edits and printing the syntax tree returned by commit result in the same source code
  • verifying the resulting syntax tree has no unknown nodes, empty slots or missing required children
  • verifying that re-parsing the returned source code does not yield any syntax errors

Incidentally these new checks required changes in a few existing tests that had syntax errors in the input file

@leops leops requested a review from a team August 1, 2022 08:50
@leops leops temporarily deployed to aws August 1, 2022 08:51 Inactive
@github-actions
Copy link

github-actions bot commented Aug 1, 2022

@github-actions
Copy link

github-actions bot commented Aug 1, 2022

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45878 45878 0
Passed 44938 44938 0
Failed 940 940 0
Panics 0 0 0
Coverage 97.95% 97.95% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 395 395 0
Failed 5551 5551 0
Panics 0 0 0
Coverage 6.64% 6.64% 0.00%

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12393 12393 0
Failed 3864 3864 0
Panics 0 0 0
Coverage 76.23% 76.23% 0.00%

@xunilrj
Copy link
Contributor

xunilrj commented Aug 1, 2022

I suppose we will need to be able to insert nodes in the future. Right?

@leops
Copy link
Contributor Author

leops commented Aug 1, 2022

I suppose we will need to be able to insert nodes in the future. Right?

At the moment it's possible to get around it by first creating a mutated copy of the parent list with the new node inserted, then adding a replacement operation for that list node to the batch mutation (this is what useSingleVarDeclarator does for instance). But it certainly would be nicer to have insertion supported directly in the batch mutation API

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Aug 2, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0bb327f
Status:⚡️  Build in progress...

View logs

@leops leops temporarily deployed to aws August 2, 2022 07:32 Inactive
@leops leops temporarily deployed to aws August 2, 2022 07:56 Inactive
@leops leops merged commit 08b49db into main Aug 2, 2022
@leops leops deleted the fix/mutation-remove-list branch August 2, 2022 08:44
IWANABETHATGUY pushed a commit to IWANABETHATGUY/tools that referenced this pull request Aug 22, 2022
…atch mutations (rome#2980)

* fix(rome_js_analyze): fix the removal of nodes from syntax lists in batch mutations

* address PR review

* run the configuration codegen
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 noDebugger errors while trying a safe fix
4 participants