Skip to content

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

@marcins

Description

@marcins

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issueThis issue is good for contributors who are getting started

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions