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

evanw opened this issue Aug 16, 2019 · 1 comment


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

This comment has been minimized.

Copy link

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();
    const next = this.scanner.lex();

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

Reviewed by Timothy Hatcher.

Address a few Esprima issues:

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

    Issue #1920 - Invalid Left Hand Side in for-in

* UserInterface/External/Esprima/esprima.js:

git-svn-id: 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
None yet
2 participants
You can’t perform that action at this time.