Classes with constant computed property names aren't three-shaken
- Dominant language
- Go
- Stars
- 40.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
The following code is not being tree shaken awy:
```
const prop = "prop";
class Money {
[prop] = true;
constructor() {
}
}
```
`.bin/esbuild test.ts --minify --bundle --format=esm --target=esnext` returns: `var c="prop",r=class{[c]=!0;constructor(){}};` - I'd expect nothing
Setting the prop to a Symbol() or Symbol.for(...) (which is what I was actually trying to do) doesn't work either
If I replace prop with a constant it does work:
```
class Money {
["prop"] = true;
constructor() {
}
}
```
(no output)
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the issue with the provided test.ts input and the .bin/esbuild command, then trace the tree-shaking behavior for classes with computed property names. Done means unused classes are removed when the property name is a constant or computed from a constant, including the reported Symbol cases, without regressing the literal-property case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100