Uncaught SyntaxError: Got ?[198] expected ID

Posted on
  • Mon 2021.09.06

    During development, attempted to create shortened two letter function names that maintained alignment.

    Significantly shortened statement:

    function of() { }
    

    Throws error:

    Uncaught SyntaxError: Got ?[198] expected ID
    

    There is no immediate rush to resolve this for me as I've created a temporary workaround. More curious as to what is causing this.

    >process.env
    ={
      VERSION: "2v00",
      GIT_COMMIT: "ff35517",
      BOARD: "ESP8266_4MB",
      FLASH: 0, RAM: 81920,
      MODULES: "Flash,Storage,hea" ... "r,crypto,neopixel",
    


    of is not a reserved word:

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_keywords_as_of_ecmascript_2015

    However, I did find a reference used within a for loop:

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of

    I'm making the assumption that 'of' might be parsed as part of the statement syntax in this case, but really doesn't answer why a function may not have the same name as it isn't a reserved keyword.

  • Thanks! In Espruino, of is a reserved word because of for (var i of foo) so I'm surprised it's actually not in the JS spec.

    I'd been having issues with the Layout.js file when pretokenised, so it's actually possible you're having the same issue. I just filed a bug for this so I can track it https://github.com/espruino/Espruino/issues/2047

    This particular one should be an easy fix (changing the pretokeniser to ignore 'of') but there are definitely other cases like this where it could be a problem.

  • Turns out the pretokeniser issue is unrelated, so this issue is very specifically just if you decide to call a function of.

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

Uncaught SyntaxError: Got ?[198] expected ID

Posted by Avatar for Robin @Robin

Actions