Navigation Menu

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

Terser fails to parse code with nested template strings and comma delimited expressions #1204

Closed
marcins opened this issue Jun 2, 2022 · 4 comments
Labels
bug good first issue This issue is good for contributors who are getting started

Comments

@marcins
Copy link

marcins commented Jun 2, 2022

Bug report

Terser fails to minify code where a nested template string, with an expression with a comma, is followed by another template string. (This is based on real code generated by Parcel with Emotion css template strings).

Version (complete output of terser -V or specific git commit)

5.14.0

Complete CLI command or minify() options used

echo '`${`${0,0}`} ${0}`' | bin/terser

Note that this is definitely valid JS:

❯ echo 'console.log(`${`${0,0}`} ${0}`)' | node
0 0

terser input

`${`${0,0}`} ${0}`

terser output or error

Parse error at 0:1,11
`${`${0,0}`} ${0}`
           ^
ERROR: Unexpected token: template_substitution ( )
    at js_error (/terser/lib/parse.js:385:11)
    at croak (/terser/lib/parse.js:1109:9)
    at token_error (/terser/lib/parse.js:1117:9)
    at unexpected (/terser/lib/parse.js:1123:9)
    at expr_atom (/terser/lib/parse.js:2362:9)
    at maybe_unary (/terser/lib/parse.js:3147:19)
    at expr_ops (/terser/lib/parse.js:3198:24)
    at maybe_conditional (/terser/lib/parse.js:3203:20)
    at maybe_assign (/terser/lib/parse.js:3280:20)
    at expression (/terser/lib/parse.js:3305:24)

Expected result

Successful minification.

@marcins
Copy link
Author

marcins commented Jun 2, 2022

After running a git bisect it appears that this is regression introduced by commit 83c027e.

@fabiosantoscode
Copy link
Collaborator

Thanks for reporting and bisecting!

@fabiosantoscode fabiosantoscode added bug good first issue This issue is good for contributors who are getting started labels Jun 2, 2022
@fabiosantoscode
Copy link
Collaborator

This was caused by the desire to save RAM. token.raw was turned into LATEST_RAW, yet LATEST_RAW is incorrectly reset. Might also be the template string end indicator.

@marcins
Copy link
Author

marcins commented Jun 5, 2022

Thanks for fixing this so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue This issue is good for contributors who are getting started
Projects
None yet
Development

No branches or pull requests

2 participants