I want to write all my code in >ES6 (actually want to match what is implemented in Node 14 which is a good bit of ES8/2017 too). I am already using rollup but will need some transpilation. What is actually supported in Espruino 2.0+? I mean should I transpile/shim to ES5 or do I need to go older?
Maybe if I knew exactly what was supported I could use buble to only transpile what is needed as in a espruino column like in this chart showing what is implemented. https://kangax.github.io/compat-table/es6/
check the open wishlist ES5/ES6 wishlist #1302 to have clear view what is available and what is missing.
There is page with ES compatibility here https://www.espruino.com/Features
I understand the limitations. Mostly just need to to spin up a TCP socket client or server and manipulate the gpio bus. Sockets are supported in Espruino with the very similar to Node net library. This will be a simple refactor of my es6+ code written for node 14 (as long as I can transpile). By using my json packet command library (via the socket) I can offload any web UI and most other computation to a much more capable machine.
Initially I figured on doing this all in CPP but the idea of basically have one code base for my json packet socket client/server is appealing. So even a little transpile bloat should be tolerable given I don't intend to run much code on esp32.
Mostly just need a few things like class syntax and promises/async/await (to avoid callbacks), arrow funcs, let/const/scope and a few of the native object improvements. Rollup already handles esm to cjs.
Great. Would be nice to see practical example when such development flow works. Please share the results. I wonder how the source and the generated result will look like and how much of original code it handles before it hits some limits.
@fanoush thanks for the link. Surprisingly V2 seems to already support most of what I would need so maybe don't need to transpile or just use buble for the one off requirements like block scoping which I can't tell from table is supported. I will report back to this thread whatever I had to do and its impact.
Great! I'd be interested in how buble works. Block scoping isn't supported but is on my to-do list for Espruino so should arrive soon I hope
I've put together a rollup starter repo with buble transforms for features not supported currently plus one pretty simple babal plugin for just async/await. Should work on any device (if you change the npm scripts). The starter currently runs a set of extended feature examples as a "test". With more work this could be made into something more generic which would allow noobs to get going faster with less pain. It will pretty much allow me to use my existing code es6/esm without too much modification nor too much transpiled bloat.
It is structured so that a user works on app.js coding the app class therein for their particular application.
Let me know if you successfully used it or what the issues are (can use github issue tracker). If the idea of a starter like this seems like a good idea then maybe others can help with improvements/upgrades.
Nice - thanks! I'm a bit busy at the moment but I'll try and give it a look in the next week or so.
This could end up being a nice way to also pull in typescript code I guess?
yes there is a rollup plugin for typescript so would be easy to add this.
Not sure if reducing to es6 and then following with what I have done (buble, etc) is best or just tell it to go all the way to es5. The later would include many superfluous transformations and defeat what I was trying to do which was only transform what was needed with buble and that single async/await.
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
For a full reference visit the Markdown syntax.
© Espruino, powered by microcosm.
Report a problem