Variable assignment could not be repeated
- Dominant language
- Go
- Stars
- 40.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Think I looked through existing issues, sorry if I missed this, and thanks for esbuild :) When a variable is set in a bunch of if statements, with nothing else, would it be possible for the assignment to be done once rather than in each conditional? Here's a cut down example:
```
$ cat foo.js
if (code === 1) {
link = "1";
} else if (code === 2) {
link = "2";
} else if (code === 3) {
link = "3";
} else {
link = "0";
}
$ cat foo.js | node_modules/.bin/esbuild --minify
code===1?link="1":code===2?link="2":code===3?link="3":link="0";
```
I think this is equivalent to the shorter `link=code===1?"1":code===2?"2":code===3?"3":"0";` - every part sets link, so it can be extracted and used once at the start. Hope that's of interest, though realise might not be possible/easy/worth it
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.