JavaScript: Fix compactChildNodes dropping node list fields - #4187
Merged
Conversation
marcoroth
added a commit
to marcoroth/herb
that referenced
this pull request
Jul 29, 2026
`@ruby/prism` generates `compactChildNodes()` with `compact.concat(this.field)` and discards the result, so node list fields are dropped from the traversal. Visitors never descended into `when`/`in` branch conditions, multiple assignment targets, `rescue` exceptions or method parameters. This pull request overrides the Prism visitors and walks `childNodes()` instead, which spreads those arrays correctly. This fixes false negatives in `erb-no-instance-variables-in-partials`, `erb-no-debug-output` and `erb-no-unused-literals`. Upstream fix: ruby/prism#4187
Collaborator
|
I think this was closed by accident? |
Contributor
Author
|
lol whoops, I didn't realize it would close the issue here in |
Earlopain
approved these changes
Jul 29, 2026
Earlopain
left a comment
Collaborator
There was a problem hiding this comment.
Thanks! Would have worked with ruby semantics 😉
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.
In the JavaScript bindings
compactChildNodes()is generated two ways. When a node has at least oneOptionalNodeFieldit builds up acompactarray, otherwise it returns an array literal.The literal branch spreads node lists correctly, but the
compactbranch usedconcatand threw the result away:BasicVisitor#visitChildNodeswalkscompactChildNodes(), so aVisitorsilently never descends into those children:This affects 17 fields across 11 node types:
ArrayPatternNodeBlockParametersNodeCaseMatchNodeCaseNodeFindPatternNodeHashPatternNodeMultiTargetNodeMultiWriteNodeParametersNodeRescueNodeandWhenNodeNodes without an optional field take the literal branch and are fine, which is why
StatementsNodeworks and the problem is easy to miss.