Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant return from parsers.blockRuleset() #4265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Krinkle
Copy link

@Krinkle Krinkle commented Mar 21, 2024

What:

Remove redundant return from parsers.blockRuleset().

Why:

The content from parseBlock() is either undefined or an array array from parsers.primary(). The falsy return that preserves block creates the impression that something is happening or being changed, but in actuality it is equivalent to matching nothing / returning nothing. Other parser methods like block and detachedRuleset 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 to if ( block !== null ). Combined with the fake return block at the end for the implied else 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant