Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected token ILLEGAL with function literal in template literal #1991

Closed
evanw opened this issue Aug 16, 2019 · 1 comment

Comments

@evanw
Copy link

commented Aug 16, 2019

Steps to reproduce

Attempting to parse this code causes an error:

`${function() { let {x} = y; }}`

This is a reduced test case from a real app. We were using a string like this to create the source code for a web worker.

Expected output

This should be able to parse fine. The code parses fine with other parsers and works fine in the Chrome Developer Tools console.

Actual output

I get this instead:

Error: Line 1: Unexpected token ILLEGAL
@JosephPecoraro

This comment has been minimized.

Copy link
Contributor

commented Aug 20, 2019

This appears to be because scanner saveState and restoreState do not save and restore the curlyStack array.

So when parsing in isLexicalDeclaration:

isLexicalDeclaration() {
    const state = this.scanner.saveState();
    this.scanner.scanComments();
    const next = this.scanner.lex();
    this.scanner.restoreState(state);
    ...
}

This lex can add a curly brace to the stack, and when the lex happens again re-adds a curly brace to the stack.

Making saveState and restoreState hold a copy of curlyStack gets this to parse properly.

ashkulz pushed a commit to qtwebkit/webkit-mirror that referenced this issue Aug 21, 2019
…g of resources

https://bugs.webkit.org/show_bug.cgi?id=200935

Reviewed by Timothy Hatcher.

Address a few Esprima issues:

    Issue #1991 - Failure to parse template literal with destructuring assignment expression
    jquery/esprima#1991

    Issue #1920 - Invalid Left Hand Side in for-in
    jquery/esprima#1920

* UserInterface/External/Esprima/esprima.js:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@248923 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JosephPecoraro added a commit to JosephPecoraro/esprima that referenced this issue Sep 11, 2019
@ariya ariya closed this in 3f9dc14 Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.