espruino / BangleApps

Bangle.js App Loader (and Apps)
https://banglejs.com/apps
MIT License
498 stars 1.17k forks source link

sanitycheck: parse ecma2020 constructs (`??`) #3653

Closed bobrippling closed 1 day ago

bobrippling commented 2 weeks ago

To help with PRs such as #3642

bobrippling commented 2 weeks ago

@gfwilliams this PR assumes we can parse all syntaxes from the 2020 edition

https://github.com/espruino/BangleApps/blob/a8f1aa97e51bf9fa3d2b3777c63248b243cc0199/bin/sanitycheck.js#L29

... but I don't think that's the case (e.g. destructuring isn't supported), so I have two questions:

  1. Is there a list anywhere of what's supported and what isn't?
  2. Does this matter or do we just accept that we might pass some things through sanitycheck which then fail to parse on-device? Or vice-versa, we only enable ?? parsing and possibly other things espruino supports (based on the above list)
gfwilliams commented 2 weeks ago

Is there a list anywhere of what's supported and what isn't?

https://www.espruino.com/Features

I guess ideally it'd be really nice to throw errors for unsupported stuff. Is there a 'visitor' for acorn maybe, so we can iterate over everything in the syntax tree and check for unsupported stuff that gets parsed (eg spread I guess)?

bobrippling commented 1 week ago

I've gone with upgrading to 8.0 which lets acorn parse ?? without an extra dependency, at the price of having to specify an ecma version. A visitor would be ideal but I'm afraid I don't have capacity atm (happy to close this for now to keep the PRs clear)

gfwilliams commented 1 week ago

Thanks! No I'm fine if you want to merge this - I guess the Lint config (or something in espruinotools) should ideally be the one to catch it anyway.

bobrippling commented 1 day ago

Cool, sounds good - I suppose there's existing constructs that are parsed but not warned about too, so the lint config does sound like the right approach (e.g. destructuring)

gfwilliams commented 1 day ago

Thanks! I think this should probably be in https://github.com/espruino/EspruinoTools (which the IDE as well as BangleApps uses). We could then use the tools themselves (there is some commented out code in https://github.com/espruino/BangleApps/blob/master/bin/sanitycheck.js#L565-L573) to parse which could check for supported constructs as well as potentially some other things (like libraries that don't exist)

bobrippling commented 6 hours ago

Ah, so the tools can accurately tell if the JS will be parsed by espruino? That's cool