toLeopard: Fixes and improved clarity for unique-name behavior#137
toLeopard: Fixes and improved clarity for unique-name behavior#137PullJosh merged 9 commits intoleopard-js:masterfrom
Conversation
| const LEOPARD_RESERVED_SPRITE_NAMES = [ | ||
| // Browser-provided identifiers | ||
| "Date", | ||
| "Math", |
There was a problem hiding this comment.
Question: Do we want to blacklist browser-provided identifiers like Array, Audio, Error, File, Map, Set, Temporal, etc., which are not used in generated Leopard code but could cause conflicts or confusion when the user starts adding their own hand-written JS code?
There are a lot of them. And keeping up-to-date might be challenging.
There was a problem hiding this comment.
Thanks, this is a good point! We've followed it up in detail here: #138
|
This looks nice! Thanks. 😄 I haven't properly tested the behavior, but the code looks good (aside from one comment with a requested fix). If you're reasonably confident that the behavior is correct, I'm happy with merging this and then maybe I can give it a proper test of my own after switching away from Or if you'd rather wait until I can really sit down with it, it'll just take a few days. |
|
Oops! Thanks for that catch LOL. We'd prefer that you take the time to check it out before we merge. It fixes some bugs and otherwise is a totally non-breaking release, so we'd kind of like to publish it as a separate version from the change for No problem about the delay, by the way. Thanks to your blessing/look-over we can say this is a good base, so we can get started on |
|
Addendum for this PR: While we can generate the lists dynamically and certainly include a broader list of globals than just what sb-edit depends on accessing—we are still OK to start on implementations based on these top-level constants. Because, we'd just be changing how the lists are generated, not how they are externally accessed (still the same variable names that still represent the same practical contents, just better versions of those lists). |
|
Tested and looks good! 😄 (Sorry for the delay) |
|
No problem! We've been busy anyway LOL. 🥳 Thanks!! |
Development:
sprite.vars.*in favor of using class properties directly? leopard#196Addresses the stuff above! Notable details:
toLeopardfunction. This makes them more convenient to locate and edit, and separates particularly word-based data from actual conversion logic.uniqueNameGeneratortouniqueNameFactorybecause generator functions and factory functions are different things, and this is the latter. (Best not to conflate with the JavaScript term "generators", especially since Leopard itself makes extensive use of JS generators.)Here's the big external change, besides the word-list fixes listed at the start:
SpriteBase,Stage, andSpriteto make sure we're covering everything (and not leaving some crucial things only in the sprite list and not the stage list, for example). But a second pair of eyes comparing that code with this would be great, of course!We have also introduced a new
JS_RESERVED_PROPERTIESlist. These are names you really don't want generated code to ever be messing with! This is mostly to cover our bases when we do variables onthis. We technically won't ever hit__proto__because that's not a camel-case name, andprototypeis only meaningful on functions (which sprite instances aren't)... butconstructorreally does fix a bug (#136), and we figured better to be a little more comprehensive than less, in such a context-generic list.