toLeopard: Code style cleanup for blockToJS & related functions#124
toLeopard: Code style cleanup for blockToJS & related functions#124towerofnix merged 5 commits intoleopard-js:masterfrom
Conversation
PullJosh
left a comment
There was a problem hiding this comment.
Looks great! As long as this passes all tests, I'm happy 👍
|
There have been a lot of commits since a new release on npm. Is it time to do that soon? |
|
We haven't been in a rush for it since none of these are behavior changes, but the housekeeping stuff does clean up dependencies and update our name on the license - if you'd like to put a release online then everything is certainly good to go as-is. #122 will probably be ready tomorrow, with the fix for #123 shortly after... but if pushing an extra NPM release is no hassle, then there's not much reason to wait pending those. ^^ |
|
We may have forgotten that tomorrow is Christmas eve, LOL. Well, you know: those pull requests will be set when they're set, and that'll be sooner rather than later. Happy holidays! ✨ 📦 |
This pull request cleans up the code style contained by and surrounding
blockToJSin a number of fairly high-impact ways, which together make it far easier to incrementally edit block definitions, compare one block to another, and generally read and understand the codebase. See individual commits; in summary:inputToJSare basically never inlined as part of theblockSourcetemplate strings anymore; instead, they're defined in temporary variables, each on its own line, immediately above. This gets rid of the question of "is it worth it enough to store this input on a variable?" (always yes) and avoids some really brutal line breaking on particularly long template strings.case OpCode.category_opnow gets a proper block scope, i.e.case OpCode.foo: { ... }. This is to help with the new variables above, but also just makes the code style more consistent. (This pattern is reflected in other switch-cases in the same file, purely for consistency.)case OpCode.category_opis divided into three sections: one which setssatisfiesInputShape, one which setsblockSource(including the relatedinputToJScalls), and one which is just the finalbreak;at the end. This is mostly aesthetic, but it does lend a visual consistency across both those cases which are simpler and more complex.spriteInputToJSandcolorInputToJSisolate commonly reused logic/patterns into helper functions. This doesn't actually change any behavior at all - all uses ofspriteInputToJSfollowed exactly that behavior, etc. But it means there's a lot less logical volume being dedicated to this unnecessarily duplicate behavior, so block definitions are more focused on just what's unique about them.inputToJS! This means we don't have to use loads and loads and loads of redundant parentheses, rather inconsistently, in block definitions. Accordingly, any explicitly written parentheses that remain (very few) actually carry significance, and don't get lost in the noise.let xandlet yinstead oflet coords.typeof parseNumber(input) !== "number"instead ofparseNumber(input) === null.operator_addandoperator_subtractis written with fewer nested cases and duplicate lines.blockToJSwhich matches againstdesiredInputShapenow uses a switch/case rather than a bunch of if-else cases, since it logically lines up with a switch/case/case/case/default quite well.This PR basically doesn't change any behavior, apart from a few logic tidiness mentioned above, and the change to how order of operations is expressed. Since the latter has always been collaped by prettier, this doesn't affect sb-edit output at all — only how the code is expressed.
A neat way of reviewing this would probably be to view the diff in the "side by side" / split view appearance (rather than with additions and subtractions all in one column).