ES6 Constructs NOT available in modules

Posted on
  • Hello,

    @Gordon: Thanks so much for your contribution to this product.

    I am an experienced JS developer, but new to espruino. I understand that espruino is not 100% of any JS spec, and that it has implemented a few ES6 constructs (such as arrow functions, template strings, etc.).

    I am using the IDE (ver 0.70.4) with projects enabled, allowing me to define/use my own modules.

    My experience is the the supported espruino ES6 constructs are ONLY AVAILABLE in the main code that is deployed to the MCU. Using something like arrow functions or template strings:

    • WORK when it is in the main code
    • ERROR (at MCU deployment time) when they are found in a module

    Thoughts?

    Your help is greatly appreciated.

    Kevin

  • In the ide I think you may get warnings, however the interpreter itself can handle the code.

    From memory the acorn parser in the ide does not handle things like arrow functions.

  • Sat 2018.10.06

    Hello @KevinAst,

    You may have uncovered the new 'features' page, but in case:

    http://forum.espruino.com/conversations/­326063/

  • Thanks @Wilberforce.

    I think I had noticed (as you suggest) that the deployed code was actually working, even with the IDE deployment error.

    Unfortunately, this would be a rather problematic process ... not knowing if there is a legitimate error in the deployment, or it is just a false indicator.

    Curious as to what the real problem is, and if there is a way to eliminate this "false error" from the IDE.

  • Thanks @Robin.

    Yes I will most likely be using github eventually ... right now I am in a "sandbox" mode.

    This would be rather odd if a remote deployment solved the "false error" coming out of the IDE. At best, this would be a "hack".

    Curious as to what the real problem is.

    Thanks for the link!

  • Hi Kevin, are you actually a supporter on Patreon? If so, can you PM me the email address you used so I can make sure your badge on the forum reflects it?

    I believe the real problem is that the IDE automatically minifies unminified modules by default, and since we haven't been able to tell the minifier which ES6 features are supported we have to tell it that it's only using ES5. That means that all the ES6 constructs get torn back to some really messed up ES5 JS code which may/may not work.

    If you go into settings and disable module minification, or swap it to 'whitespace only', or even just rename your modules .min.js then it'll probably work fine

  • Hello @Gordon. I am currently not a patreon, other than the purchase of a couple of your Espruino WiFi boards. I am currently in a "discovery" phase ... determining whether espruino will meet our needs. Actually, I am working on my Son's behalf (as I am retired) ... he has the MCU experience, I am the JS expert :-) Is your time (and/or response) typically limited to patreons?

    Thanks for explaining what is going on.

    Background: I am researching a technique by which I can isolate my MCU logic from the hardware it is running on. This is accomplished by defining a "binding" structure that bridges the gap between hardware/logic. As a result, I heavily rely on modules. The entire MCU logic is found in a module, and the driving code (in the editor window) is a very small snippet that defines and passes the hardware "binding" structure to the logic module's start() function. This supports many sets of hardware by creating small mainlines (again in the editor window), that vary only in the hardware binding definition.

    As a result, I'm not sure how I feel about disabling module minification. I would assume this is pretty important with the MCU's limited resources (as well as proprietary obfuscation) . With that said, I see in the IDE settings that "by default" no minification occurs in the main code, so my "resource" concern may be unfounded. Thoughts?

    In looking at the minification options, I see that you have two options (Esprima and Closure). Have you considered babel? ... this may be a loaded question.

    I am considering researching/using your espruino npm package for deployment, and bypassing the IDE. Any thoughts on this?

    • does it have the same options (and/or limitations) of deployment through the IDE?

    Your assistance is greatly appreciated.

    Kevin

  • Is your time (and/or response) typically limited to patreons?

    No, not at all. But the "Place for Patreon Patrons" part of the forum is meant to be - generally I try and respond first and give a bit more time to those that have decided to try and support Espruino through Patreon... Same applies to the WiFi boards you bought though - I try and give you much better support than I would give to someone who bought a $4 ESP8266 from China, installed Espruino on it and started asking a bunch of questions :)

    I'll move your post out - can you try and post in maybe the JavaScript part of the forum if you have questions like this one in the future?

    minification is pretty important with the MCU's limited resources?

    It depends, if you write reasonably compact code with the suggestions at http://www.espruino.com/Performance it may not be too bad. Minification is rubbish for debugging, and if you're writing all your logic in modules then you may care about having it off at least during development.

    In looking at the minification options, I see that you have two options (Esprima and Closure). Have you considered babel?

    There is some work going on at the moment looking at using rollup and terser. Trying to make heavyweight Node.js tools run inside a web browser can be particularly difficult though.

    But see below - if you have some favorite tools, just use those.

    I am considering researching/using your espruino npm package for deployment, and bypassing the IDE.

    It's basically the same underlying set of tools, but in a CLI.

    It sounds like what you may want to do is write a little script which:

    • Write your code
    • Use rollup/some kind of tree-shaking to combine everything into one file
    • Minify it with an ES6 compatible minifier
    • Write that with the CLI. It has a -w option to watch a file for changes while displaying the REPL, so it plays well with external tools.

    Rather than trying to reimplement some Espruino-specific set of tools, it feels like you're probably used to working a certain way - so I'd just do that and write the final file with the CLI tools.

  • Thanks @Gordon ... I very much appreciate your insight!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

ES6 Constructs NOT available in modules

Posted by Avatar for KevinAst @KevinAst

Actions