Skip to content

[Bug] pure_getters: false still removes optional property access #1632

Open

Description

@boris-petrov

On current master (5.43.1) and try.terser.org with the default settings, the following code:

this.foo?.bar;

Is reduced to:

this.foo;

Which is of course wrong.

Activity

  1. fabiosantoscode commented on Jul 23, 2025

    @fabiosantoscode
    Collaborator

    The value of that property is unused. If it's used somewhere, the property access will be retained.

    For example: console.log(this.foo?.bar)

    The incomplete this.foo remains, because this might be undefined, and Terser doesn't remove code that might crash.

  2. boris-petrov commented on Jul 23, 2025

    @boris-petrov
    Author
  3. fabiosantoscode commented on Jul 23, 2025

    @fabiosantoscode
    Collaborator

    I see! In that case, set the compress option pure_getters to true. When set to true, it doesn't remove unused property access.

  4. boris-petrov commented on Jul 25, 2025

    @boris-petrov
    Author

    @fabiosantoscode - I believe pure_getters being set to true does the opposite. And trying it in the REPL confirms it. this.foo?.bar; becomes empty - i.e. it's completely removed. Perhaps you meant side_effects: false?

  5. fabiosantoscode commented on Jul 26, 2025

    @fabiosantoscode
    Collaborator

    I meant pure_getters: false because your getter isn't pure. But, it appears that it doesn't do what we would expect.

  6. changed the title [-][Bug] terser removes optional-chaining in statements[/-] [+][Bug] pure_getters: false still removes optional property access[/+] on Jul 26, 2025
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