Skip to content

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

@Krinkle Krinkle closed this Jun 24, 2025
@Krinkle Krinkle reopened this Jun 24, 2025
@Krinkle Krinkle force-pushed the parse-blockRuleset branch from 9a34d5c to 92ab5e1 Compare October 20, 2025 21:16
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant