-
• #2
Ok, just checked this out, you can reproduce it just with:
setWatch(function (ptt) { if (ptt.state) { LED.set(); print(32, () => {}); } else { LED.reset(); print(0, () => {}); } }, BTN, {edge: "both", debounce: 50, repeat: true});
It says:
Uncaught SyntaxError: Got ';' expected EOF at line 1 col 33 ...te?(LED.set(),print(32,()=>;)):(LED.reset(),print(0,()=>;));... ^
Basically Espruino doesn't like the minification to
()=>;
- which seems fair. If you try runningconsole.log(32,()=>;)
in the browser or node.js then it returns an error - so this seems to be a bug in the minifier!If you really do want to keep minifying (although there really isn't any need for what you have right now) teh try changing
() => {}
to_=>0
- it'll save a few characters and will minify properly. -
• #3
This is known issue with Esprima https://github.com/espruino/EspruinoTools/issues/64
I hit it very quickly when using lambdas too so I am currently torn between not using lambdas and switching to closure online minifier (which is sometimes slow).The bug is from december 2018 and last comment suggests using terser in WebIDE in future. Terser is used e.g. in webpack.
-
• #4
It's an odd one actually - I updated Esprima pretty recently and the vast majority of lambda issues disappeared - I thought it had been sorted but there are obviously some bugs left.
I haven't yet shipped terser in the IDE as it until @opichals recent commits it wouldn't have worked in the standalone version -so for now you're basically left with Closure.
But again, for what you're doing minification really isn't saving you much effort, and it messes up any stack traces you might get from errors.
-
• #5
One example is this short code
E.enableWatchdog(6, false); var wdint=setInterval(()=>{if(!D1.read())E.kickWatchdog();},1000);
produces
Uncaught SyntaxError: Got ';' expected ',' at line 1 col 77 ...D1.read()||E.kickWatchdog();,1000);
It happens also with more complex lambdas with parameters like (x,y)=>
Hi at all!
The following program has a button connected to pin D25 (MDBT42Q firmware 2v03). When the button is pressed, the "volumeUp" command is sent to the device connected by BLE. Only when button is pressed.
I have tried the program in both Puck.js and MDBT42Q.
However, when loading the code with WebIDE with the option of "Minification" Esprima (offline) an error occurs when the button is pressed for the first time. The program keeps sending the "volumeUp" command continuously.
This is the minimized code that returns
dump ()
:For now, the size of the code is not a problem but I would like to apply the best possible optimization.
Any ideas?
Thanks in advance