arrow function does not work

Posted on
  • if you try this simple example

    let p = 0;
    
    function onInit() {
      setInterval(() => {
        //allume la led 50ms
        digitalPulse(LED2, 1, 20);
        console.log((Math.sin(p)+1)/2);//, (Math.cos(p)+1)/2, tab.BUTTONS.NONE);
        p += 0.02;
      },
      50);
    }
    USB.setConsole();
    

    and upload, i receive :

    Uncaught SyntaxError: Got ';' expected ','
    at line 1 col 79
    ...((Math.sin(p)+1)/2),p+=0.02;,50);

    in function called from system

  • Thr 2020.03.05

    Hi @@Mrbbp I just tried the snippet in post #1, commenting out L12, running on a MDBT42Q breakout board and get the following:

     2v03 (c) 2018 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    >
    >onInit()
    =undefined
    0.5
    0.50999933334
    0.51999466709
    0.52998200323
    0.53995734698
    0.54991670832
    0.55985610364
    0.56977155732
    0.57965910330
    0.58951478671
    0.59933466539
    0.60911481154
    0.61885131321
    0.62854027594
    0.63817782428
    0.64776010333
    0.65728328030
    0.66674354607
    



    First, try commenting out L6 and re-run the test. If successful, then it is most likely the first argument's value for the 'pin' parameter.

    http://www.espruino.com/Reference#l__glo­bal_digitalPulse



    Second, the Uncaught SyntaxError output is parsed different than L7    Are we sure the Exact code block is being supplied, or was this a trimmed down version for demonstration?

    console.log((Math.sin(p)+1)/2);//, (Math.cos(p)+1)/2, tab.BUTTONS.NONE);
    ...((Math.sin(p)+1)/2),p+=0.02;,50);

    comma vs semi-colon allowing the comment to be treated as code



    Third, Please post the results of process.env so that we may understand the environment better.



    Full set of reference links to check out at:

    Writing an effective forum post
    http://forum.espruino.com/conversations/­335009/

  • @robin

    this is the exact code... copy/paste
    the pb does not come from the digitalPulse. If i comment all the. line in the block the error stay...

    i use minification (esprima), if i remove it, it works.
    with or without checked option, it does not work!

    é.

    VERSION: "2v04",
      GIT_COMMIT: "3956264e",
      BOARD: "PICO_R1_3",
      FLASH: 393216, RAM: 98304,
      SERIAL: "5a004e00-04513634-30323836",
      CONSOLE: "USB",
      MODULES: "Flash,Storage,hea" ... "v,crypto,neopixel",
      EXPTR: 536871212 }
    
  • Yes, Esprima doesn't like arrow functions :/
    Try closure compiler with remove-whitespace or simple optimizations.

  • @AkosLukacs
    the other minification are online... i'm coding in train (now) and there is lot of "white zone" :/
    online access can't be a statement! sorry :)

    i don't minify the code

  • Are you using the 'Chrome App' (or native) IDE, rather than https://www.espruino.com/ide/? (the website still works offline!)

    Exactly this error has been fixed in https://www.espruino.com/ide/ for a while, but the changes may not have made it into the Chrome app yet.

    i don't minify the code

    I'd check your settings again. The code in the error message ..((Math.sin(p)+1)/2),p+=0.02;,50); has definitely been minified.

    If you turn off minification it'll work.

  • Hello @Gordon

    i use the Chrome App... (since the first time...) sometime i open the IDE whitout an internet connection, therefore i got into my habits to use the Chrome app.

    In an old project i have to minify code to put all the code in the pico, i checked the minify option on and never unchecked.

    As my skills level increase in js, i want to write code in the same way in espruino and web... and arrow function are really cool feature (for me)
    I've unchecked the minify option for the moment...to avoid the esprima error...

    regards

  • Glad that fixed it! The Chrome app will be updated soon, but I'm afraid in about 2-3 months Google will actually remove the Chrome app completely, so you won't have the option!

  • Oh that’s a bad news!

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

arrow function does not work

Posted by Avatar for Mrbbp @Mrbbp

Actions