Esprima Mangle bug?

Posted on
  • I've narrowed down a bug to when I use Esprima's Mangle to shorten variable names (other minification options don't generate the error).

    I'm seeing an error in the Bangle emulator when I execute this:

    // works fine
    g.clear();
    
    function dothis() {
      g.clear();
    }
    
    function test(one, two, three, four, five) {
      let arrTmp = 0; //new Uint8Array(12);
      for(let i=0; i<1; i++) {}
      
      // fails
      g.clear();
      dothis();
    }
    
    test();
    

    I'm getting this error:

    >Uncaught Error: Function "clear" not found!
     at line 1 col 23
    let a=0;for(let g=0;g<1;g++);g.clear(),dothis()
                                   ^
    in function "test" called from line 1 col 92
    ...(),dothis()}g.clear(),test()
                                  ^
    

    You can see that it changed the loop variable to 'g' , which should still be a local variable, but it clearly affects Bangle's 'g'.

    However, if you do any one of the following, the error goes away and the Bangle 'g' is fine:

    • if you comment out g.clear() and use the "dothis()" function instead
    • if you comment out the "let arrTmp" assignment
    • if you comment out the empty for loop
    • if you reduce the argument list to 4 items

    Just thought I'd share; not sure whether this is an Esprima bug, or an interpreter bug (a "let g=" within a for loop should be its own scope and not interfere with global context?)

  • It was a missing feature/bug in Espruino (let and const were treated like var), which apparently was fixed yesterday (nice!).

  • which apparently was fixed yesterday (nice!).

    Actually this post reminded me that for loops should have their own scope, so while this got added yesterday, as of builds right now the code you've got will actually work :)

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

Esprima Mangle bug?

Posted by Avatar for yngv126399 @yngv126399

Actions