Skip to content

[Bug] Terser removes reassignment to const #1284

Open

Description

@p51lee

Bug report

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

$ terser -V
terser 5.15.1

Complete CLI command or minify() options used
I turned off the unsafe option.

$ terser input.js -c unsafe=false

terser input

try { const x = 0; x = x; } catch { console.log("caught"); }

terser output or error

try{}catch{console.log("caught")}

Expected result
Executing the output code, caught is expected to be printed since catch block is executed in the input code (assignment to constant variable).
However, nothing is printed running the output code.
It seems that Terser compresses assignment expressions which might have side effects.

$ node -e 'try { const x = 0; x = x; } catch { console.log("caught"); }' // input code
caught
$ node -e 'try{}catch{console.log("caught")}' // output code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions