Unexpected token ILLEGAL

Posted on
  • My code:

    var foo = `bar`;

    If I paste it on the left side of the IDE (Web IDE version 0.70.6) it works fine, if I try to upload it from the edit panel it gives the error message "Error: Line 1: Unexpected token ILLEGAL".

    I'm using more complex strings also containing both single and double quotes, e.g.

    var foo = `console.log('This is "cool".');`; 
    var bar =`Line1
    //storage.write, storage.read

    A workaround would be var foo = 'console.log("This is \\\"cool\\\".");'; and
    bar="Line1\nLine2", but that's hard to write. What's the cause of this error?

  • Strange, works for me with 71.3.
    Do you have minification turned on? Esprima (offline) doesn't like the ` character: "TypeError: Cannot read property 'length' of undefined". Online (closure compiler) minification works.
    Try upgrading to the latest web ide :)

  • Sun 2019.08.04

    Strings are delimited with the double quote "

    Json name/value values and Html attributes delimited with the single quote '

    That character is the grave accent. ` Template Literal

    New Web IDE - testers

    Proper usage as you require explained in detail by @allObjects


    Single quotes go inside a double quoted string, (unless escaped as you show) not double embedded in a single quoted string.


  • Do you have minification turned on? Esprima (offline) doesn't like the ` character

    Hit. Without Esprima it works fine. Thanks!

  • Any chance of using a newer IDE version? If you installed the Chrome web app it should have updated to 0.71.3 weeks ago - I updated to a newer Esprima version some time ago which handles that fine.

    I guess you're on the native download? I've just updated that to the latest version now - but if you can use it the chrome app is preferable since it auto-updates.

  • I'm fine with the bug, I don't need any minfication in this case (it won't modify the contents of that string anyway).

    In 0.71.4 it says for foo=`bar`;
    using Esprima "TypeError: Cannot read property 'length' of undefined", or
    using Closure [Advanced] :"No errors. Minifying 10 bytes to 11 bytes".

  • TypeError: Cannot read property 'length' of undefined

    I know, that's a bit odd, but it still seems to work?

  • Yes, it seems to work. But I tested only simple, single strings.

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

Unexpected token ILLEGAL

Posted by Avatar for maze1980 @maze1980