Avoid returning nil values from ClassDeclaration#child_nodes
#16
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.
For a class declaration node having
superclass
is optional so currentlyClassDeclaration#child_nodes
method returns an array that contains anil
value which complicates traversing a little bit.Here is an example:
I wasn't sure about our intentions, but I feel like it might be helpful to expect
child_nodes
to always return an array of node objects and nothing else so I opened this PR as a discussion with a potential solution.The solution I'm suggesting may look excessive but I end up choosing it versus calling
.compact
on the resulting array because I liked that we explicitly state which part of the class declaration is optional. Let me know if you have other suggestions!After the change:
If we think that this is a reasonable change to implement, I can quickly change similar nodes like
BodyStmt
, for example:https://github.com/kddnewton/syntax_tree/blob/d738840feab02648899f08d00dc9fcf5f018f6a3/lib/syntax_tree.rb#L2850
I haven't covered it with tests because wasn't sure if that would be a correct change to do so let me know if I should add some.
Thanks!