Skip to content

Optimize ES2015 enums #13488

Closed
Closed
@filipesilva

Description

@filipesilva

🚀 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:

export enum ChangeDetectionStrategy {
  OnPush = 0,
  Default = 1
}

Is transpiled to ES2015 as:

const ChangeDetectionStrategy = {
    OnPush: 0,
    Default: 1
};
ChangeDetectionStrategy[ChangeDetectionStrategy.OnPush] = "OnPush";
ChangeDetectionStrategy[ChangeDetectionStrategy.Default] = "Default";

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIssue that requests a new feature

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions