Remove redundant return from parsers.blockRuleset()
#4265
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.
What:
Remove redundant return from
parsers.blockRuleset()
.Why:
The
content
fromparseBlock()
is either undefined or an array array fromparsers.primary()
. The falsy return that preservesblock
creates the impression that something is happening or being changed, but in actuality it is equivalent to matching nothing / returning nothing. Other parser methods likeblock
anddetachedRuleset
handle this by not having a return value.What led me to this change is the PHP code in https://github.com/wikimedia/less.php. In PHP, arrays are primitives values (like Python tuples) which means
if (block)
is falsy for empty arrays. As opposed to in JS, where arrays are objects and thus always truthy. When porting this over, we forgot to convert this toif ( block !== null )
. Combined with the fakereturn block
at the end for the impliedelse
block, led to a subtle bug. This doesn't apply to the JS code base of course, but it felt to me like removing this made for improved visual clarity overall, so I'm offering it up for your consideration 🙂wikimedia/less.php@2cd9715
https://gerrit.wikimedia.org/r/c/mediawiki/libs/less.php/+/1010592
Checklist: N/A