Conversation
c862232 to
fc2424f
Compare
I think we need a more general solution here. I am fine with taking this change, but we should not keep going down this wake-a-mole path, we either say we run the formatter as a best-effort attempt, or we will fix the formatting scanner so that it does not assert on invalid nodes. |
|
I think the problem in this case is that we create a new node with old nodes as children. When we emit the new nodes we create new emitted text which emits the string literal correctly, but the formatter looks at the old source file's text which only has the opening quote. |
|
Would cloning the nodes solve the issue? |
|
If it did we wouldn't be able to get the comments from the old nodes... but if we do keep the old positions the formatter can run into problems. |
|
Well, then we should always be cloning them and their comments. I think that is a simpler invariant to assert, do not repurpose nodes from the existing tree, you can only add new nodes, and that is recursive.. |
|
Thanks for your contribution. This PR has not been updated in a while and cannot be automatically merged at the time being. For housekeeping purposes we are closing stale PRs. If you'd still like to continue working on this PR, please leave a message and one of the maintainers can reopen it. |
Fixes #23942
Instead of replacing the entire arrow function node, just replace the parameter with the string "()". This avoids reformatting the body, which can contain invalid emitted nodes like
"(with no closing quote) that trigger formatter assertions. (When we emit it we also emit the closing quote, but we're still using the original positions which end after the opening quote.)