-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] make generated codes from enum could be minified when not used #27604
Comments
Well I guess this is blocked because we need to be able to extend enums as well. The only way I can think of this is doing something like: var ABC = /*@__PURE__*/(function (ABC) {
ABC["A"] = "abc";
ABC["B"] = "bcd";
ABC["C"] = "cde";
return ABC;
})(ABC || {});
ABC = /*@__PURE__*/(function (ABC) {
ABC["D"] = "def";
return ABC;
})(ABC || {}); for input: enum ABC {
A = "abc",
B = "bcd",
C = "cde"
}
enum ABC {
D = "def"
} Though terser will still not be able to remove both if we are extending the enum but atleast it would be able to remove it if we have only one declaration of the enum. Am here because my "tree-shakeability" tests just failed. 😅 (anarock/pebble#219) |
@azizhk |
That's a neat trick @morlay, |
@azizhk since babel support typescript. we could compile all through babel. @azizhk since babel support typescript. we could compile all through babel.
my babel configuration bellow
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": true
}
}
]
],
"plugins": [
"babel-plugin-typescript-iife-enum",
"@babel/plugin-transform-typescript",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
"babel-plugin-pure-calls-annotation"
]
}
|
This is indeed a very needed feature. We have a lot of packages and we are using enums extensively. Right now, all enums from all packages are getting added to the final application bundle, even if we are not using them at all, or using only a very small subset of all possible values. I guess, one workaround would be to use constant enums instead, if possible. |
Hey folks, any updates on this one? We are changing most of the types to be union types because of tree-shaking issues, would appreciate some support on the topic. |
Hey folks! We just ran into this as well where esbuild won't tree shake our unused enums. It would be a really nice feature to have 🙂 |
Search Terms
For now TypeScript will transform enum from
to
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:
Examples
The suggestion version will be removed.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: