microsoft / microsoft/TypeScript
[Feature] make generated codes from enum could be minified when not used
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Search Terms
For now TypeScript will transform enum from
enum Test {
Key = 1
}
to
var Test;
(function (Test) {
Test[Test["Key"] = 1] = "Key";
})(Test || (Test = {}));
This result is not friendly for uglyify or tree-shaking.
When Test is not be used, the generated code block always remain as dead codes.
Suggestion
prefer to generate codes below:
var Test = /*#__PURE__*/(function () {
var e = {}
e[e["Key"] = 1] = "Key";
return e
})();
Examples

The suggestion version will be removed.
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript / JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. new expression-level syntax)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file, test, or entry point is named. Begin by locating TypeScript's enum emitter and existing enum-output tests, then compare the emitted form with minifier and tree-shaking behavior. Done means an agreed emission strategy is covered by regression tests without changing runtime behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100