Skip to content

[Bug] terser incorrectly removes ReferenceError for computed property using class name #1593

Open

Description

@p51lee

Terser incorrectly optimizes a class with a computed property key when the key references the class name itself. This results in an output that no longer throws a ReferenceError.

terser input:

I used terser REPL to reproduce the bug with the following input:

class x { [ ! { x } ] ; }
new x

This input script throws ReferenceError:

❯ node input.js
class x { [ ! { x } ] ; }
                ^

ReferenceError: Cannot access 'x' before initialization

Node.js v22.9.0

terser output

class s{[!1]}new s;

The output executes normally without throwing an error.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions