Suboptimal minification when safe logical assignments are possible
- Dominant language
- Go
- Stars
- 40.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
[Repro](https://esbuild.github.io/try/#dAAwLjI4LjEALS1taW5pZnkgLS10YXJnZXQ9ZXNuZXh0AGxldCBmb287CmZvbyA9IGZvbyB8fCAxOwpleHBvcnQge2Zvb30).
Basically using these flags:
```
--minify --target=esnext
```
And this input code:
```js
let foo;
foo = foo || 1;
export {foo}
```
We get this output code:
```js
let o;o=o||1;export{o as foo};
```
But I think we should really be getting this:
```js
let o;o||=1;export{o as foo};
```
I understand in the presence of setters and proxies this may lead to slightly different execution, but there are some basic cases where we are sure we are not triggering a setter nor a proxy trap, like this one, so presumably the better minification should be emitted.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the linked esbuild reproduction using --minify --target=esnext and the JavaScript input shown. Trace the minifier's handling of logical assignments and determine the safety conditions described in the issue; done means the safe case emits ||= while preserving behavior where setters or proxy traps may differ.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100