google / google/closure-compiler

`@pureOrBreakMyCode` can't handle when left-hand side is array pattern

Open
#4,178 8 comments 1 reaction 0 assignees View on GitHub
triage-done
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

command `java -jar closure-compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --formatting PRETTY_PRINT --js input.js --js_output_file compiled.js`

the example code is trimmed from tc39 stage 3 decorator compiled by swc.
in the example,`@pureOrBreakMyCode` is added manually to `({ e: [_init_p3] } = /** @pureOrBreakMyCode */_apply_decs_2203_r(...)`

however, because left-hand side is destructuring assignment, so closure-compiler need to traverse the `lhs` and `valueNode` respectively, it can't eliminate the pure valueNode.
![image](https://github.com/google/closure-compiler/assets/14803931/9c9b3bc2-2287-4be8-a340-e76fe77d6769)

reproducible code
```
/** @noinline */
const applyDecs2203RFactory = () => { return () => {} }
/** @noinline */
const _apply_decs_2203_r = applyDecs2203RFactory()
var _init_p3;

class A {
constructor(){
this.p3 = /** @pureOrBreakMyCode */_init_p3(this, "3");
}
}
({ e: [_init_p3] } = /** @pureOrBreakMyCode */_apply_decs_2203_r(1, 2, 3));
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.