WebIDE problem with the minification

Posted on
  • 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.

    var controls = require("ble_hid_controls");
    // Clean all previous watches
    // Configure PIN D25 with internal pulldown resistence
    // Wiring to VCC.
    pinMode(D25, "input_pulldown");
    NRF.setServices(undefined, {hid: controls.report});
    setWatch(function (ptt) {
      if (ptt.state) {
        NRF.sendHIDReport(32, () => {});
      } else {
        NRF.sendHIDReport(0, () => {});
    }, D25, {edge: "both", debounce: 50, repeat: true});

    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 ():

    // Code saved with E.setBootCode
    Modules.addCached('ble_hid_controls','fu­nction b(a,b){NRF.sendHIDReport(a,function(){NR­F.sendHIDReport(0,b)})}exports.report=ne­w Uint8Array([5,12,9,1,161,1,21,0,37,1,117­,1,149,5,9,181,9,182,9,183,9,205,9,226,1­29,6,149,2,9,233,9,234,129,2,149,1,129,1­,192]);exports.next=function(a){b(1,a)};­exports.prev=function(a){b(2,a)};exports­.stop=function(a){b(4,a)};exports.playpa­use=function(a){b(8,a)};exports.mute=fun­ction(a){b(16,a)};exports.volumeUp=funct­ion(a){b(32,a)};exports.volumeDown=funct­ion(a){b(64,a)}');var controls=require('ble_hid_controls');cle­arWatch(),pinMode(D25,'input_pulldown'),­NRF.setServices(undefined,{hid:controls.­report}),setWatch(function(a){a.state?(L­ED.set(),NRF.sendHIDReport(32,()=>;)):(L­ED.reset(),NRF.sendHIDReport(0,()=>;));}­,D25,{edge:'both',debounce:50,repeat:!0}­);

    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

  • Ok, just checked this out, you can reproduce it just with:

    setWatch(function (ptt) {
      if (ptt.state) {
        print(32, () => {});
      } else {
        print(0, () => {});
    }, BTN, {edge: "both", debounce: 50, repeat: true});

    It says:

    Uncaught SyntaxError: Got ';' expected EOF
     at line 1 col 33

    Basically Espruino doesn't like the minification to ()=>; - which seems fair. If you try running console.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.

  • This is known issue with Esprima https://github.com/espruino/EspruinoTool­s/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.

  • 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.

  • One example is this short code

    E.enableWatchdog(6, false);
    var wdint=setInterval(()=>{if(!D1.read())E.k­ickWatchdog();},1000);


    Uncaught SyntaxError: Got ';' expected ','
     at line 1 col 77

    It happens also with more complex lambdas with parameters like (x,y)=>

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

WebIDE problem with the minification

Posted by Avatar for migsanvi @migsanvi