Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize ES2015 static fields #13487

Closed
filipesilva opened this issue Jan 21, 2019 · 1 comment 路 Fixed by #13496
Closed

Optimize ES2015 static fields #13487

filipesilva opened this issue Jan 21, 2019 · 1 comment 路 Fixed by #13496
Labels
area: devkit/build-optimizer feature Issue that requests a new feature
Milestone

Comments

@filipesilva
Copy link
Contributor

filipesilva commented Jan 21, 2019

馃殌 Feature request

Description

Using the ES2015 target, TypeScript transpiles classes with static fields as a class plus the assignment of the static fields over the class itself.

As an example, the TemplateRef class in https://github.com/angular/angular/blob/73dcd72afbd782161c1674f1e647a1b357a78a67/packages/core/src/linker/template_ref.ts#L34-L62:

export abstract class TemplateRef<C> {
  abstract get elementRef(): ElementRef;

  abstract createEmbeddedView(context: C): EmbeddedViewRef<C>;

  static __NG_ELEMENT_ID__:
      () => TemplateRef<any>| null = () => SWITCH_TEMPLATE_REF_FACTORY(TemplateRef, ElementRef)
}

Is transpiled to ES2015 as:

class TemplateRef {
}
TemplateRef.__NG_ELEMENT_ID__ = () => SWITCH_TEMPLATE_REF_FACTORY(TemplateRef, ElementRef);

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 static fields in such a way that they are not retained after minification.

@filipesilva filipesilva added feature Issue that requests a new feature area: devkit/build-optimizer labels Jan 21, 2019
@ngbot ngbot bot added this to the Backlog milestone Jan 21, 2019
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 22, 2019
Although ES5 classes had their static properties folded in, ES2015 ones did not.

This PR adds that new functionality.

It should also make this particular transform a bit faster, since it will stop early.

Fix angular#13487
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 22, 2019
Although ES5 classes had their static properties folded in, ES2015 ones did not.

This PR adds that new functionality.

It should also make this particular transform a bit faster since it will stop early.

Fix angular#13487
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 22, 2019
Although ES5 classes had their static properties folded in, ES2015 ones did not.

This PR adds that new functionality.

It should also make this particular transform a bit faster since it will stop early.

Fix angular#13487
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 22, 2019
Although ES5 classes had their static properties folded in, ES2015 ones did not.

This PR adds that new functionality.

It should also make this particular transform a bit faster since it will stop early.

Fix angular#13487
mgechev pushed a commit that referenced this issue Jan 22, 2019
Although ES5 classes had their static properties folded in, ES2015 ones did not.

This PR adds that new functionality.

It should also make this particular transform a bit faster since it will stop early.

Fix #13487
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: devkit/build-optimizer feature Issue that requests a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant