-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Optimize ES2015 enums #13488
Comments
You could try const enum. They are not available at runtime, and can only be used by the reference. |
I've seen this happen on the Angular core @michaeljota we want to be able to do these transformations on arbitrary third party code, where a user most likely not has the option to change underlying source. |
…mitted by tsickle tsickle emits es2015 enums with an object literal followed by an export declaration Example: ``` const RendererStyleFlags3 = { Important: 1, DashCase: 2, }; export { RendererStyleFlags3 }; RendererStyleFlags3[RendererStyleFlags3.Important] = 'Important'; RendererStyleFlags3[RendererStyleFlags3.DashCase] = 'DashCase'; ``` This PR adds support for the enums to be optimized by wrapping them in an iife and marks them as pure. Fixes #13488
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🚀 Feature request
Description
Using the ES2015 target, TypeScript transpiles enums as consts plus property assignments.
As an example, the
ChangeDetectionStrategy
enum in https://github.com/angular/angular/blob/13eb57a59fd4db27e88edb188947297b6637177f/packages/compiler/src/core.ts#L82-L85:Is transpiled to ES2015 as:
The property assignment in the transpiled code prevents the class from being removed by minifiers such as terser.
Describe the solution you'd like
Build Optimizer converts ES2015 enums in such a way that they are not retained after minification.
The text was updated successfully, but these errors were encountered: