swc/.changeset
CPunisher 8513816139
Some checks are pending
CI / Cargo fmt (push) Waiting to run
CI / Cargo clippy (push) Waiting to run
CI / Check license of dependencies (push) Waiting to run
CI / Check (macos-latest) (push) Waiting to run
CI / Check (ubuntu-latest) (push) Waiting to run
CI / Check (windows-latest) (push) Waiting to run
CI / Test wasm (binding_core_wasm) (push) Waiting to run
CI / Test wasm (binding_minifier_wasm) (push) Waiting to run
CI / Test wasm (binding_typescript_wasm) (push) Waiting to run
CI / List crates (push) Waiting to run
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Blocked by required conditions
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Waiting to run
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Waiting to run
CI / Test with @swc/cli (push) Waiting to run
CI / Miri (better_scoped_tls) (push) Waiting to run
CI / Miri (string_enum) (push) Waiting to run
CI / Miri (swc) (push) Waiting to run
CI / Miri (swc_bundler) (push) Waiting to run
CI / Miri (swc_ecma_codegen) (push) Waiting to run
CI / Miri (swc_ecma_minifier) (push) Waiting to run
CI / Done (push) Blocked by required conditions
Benchmark / Bench everything (push) Waiting to run
fix(es/minifier): Prevent removing side effects from accessing getter (#9530)
Closes https://github.com/swc-project/swc/issues/9500

Caused by
c7fdd6b69b/crates/swc_ecma_minifier/src/compress/pure/misc.rs (L1547).
When the object with getters pass to `self.ignore_return_value`,

c7fdd6b69b/crates/swc_ecma_minifier/src/compress/pure/misc.rs (L966)
converts the object to `0` because the object is side-effect-free
according to

c7fdd6b69b/crates/swc_ecma_utils/src/lib.rs (L1496)

We should skip this process to fix the issue.

As is known only accessing getters and setters may cause side effect, we
can safely do the transformation when none of them appears in the
object. More precision is possible if comparing the lit prop names. I
also collect computed keys of getters and setters in the object, is
there any bad case?

The reason why only numeric (string) key removes the statement is that
string key (`Computed`) is converted to `Ident` in other phases, e.g.
`{}['a']` => `{}.a`, which does not matching the pattern.
2024-09-04 12:28:46 +00:00
..
fresh-zoos-act.md fix(es/typescript): Handle enum in single statement (#9532) 2024-09-04 20:56:11 +09:00
six-hounds-hammer.md fix(es/minifier): typeof class should be function (#9522) 2024-09-03 08:04:44 +00:00
stale-poets-cover.md fix(es/minifier): Prevent removing side effects from accessing getter (#9530) 2024-09-04 12:28:46 +00:00