question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Emit /*@__PURE__*/ before class declaration

See original GitHub issue

Based on this research, I believe that if we were able to emit a newly supported /*@__PURE__*/ annotation in front of class declaration and ensure that it gets preserved in the final down-leveled output, @angular/cli and any other Uglify-based build tool chains would be able to use dead-code elimination tricks to remove all unused classes (pipes, directives and components) with the exception of unused services.

There is a feature request Microsoft/TypeScript#13721 to add this functionality to tsc, but it’s unclear when/if it’s going to be implemented, so I wonder how easy it would be to implement this kind of feature in tsickle so that we can experiment.

What I’d like is given the following input:

export class SomeClass {}

I’d like tsc + tscikle to output downleveled es5 code that looks like this:

var SomeClass = /*@__PURE__*/(function () {
  function SomeClass() {}
  return SomeClass;
}());

If for some reason we have a concern that /*@__PURE__*/ could cause headaches for Closure, we can also use /*#__PURE__*/, which is equally supported by Uglify.

More info:

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:24 (19 by maintainers)

github_iconTop GitHub Comments

3reactions
IgorMinarcommented, Mar 30, 2017

It depends on the app but basically all classes down leveled by tsc are retained by uglify without this fix. Our code is mostly classes, so is rxjs and material. So you can do the math. We are talking double digits. 60-70% in some cases.

On Thu, Mar 30, 2017, 10:01 AM Martin Probst notifications@github.com wrote:

Igor: just out of curiosity, what are the size gains like?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/angular/tsickle/issues/452#issuecomment-290475081, or mute the thread https://github.com/notifications/unsubscribe-auth/AANM6NFyxOxTeyH3jd-Do45uY0E4rjNWks5rq9_WgaJpZM4Mp04Q .

1reaction
IgorMinarcommented, May 26, 2017

I’m going to close this issue, because if we were to implement this in tsickle, we’d be missing out on annotating anything that comes into the app from node_modules that has not been processed by tsickle. Instead we are either going to rely on tsc to do this (Microsoft/TypeScript#13721 ), or in the short term we’ll have our own tool integrated into the angular-cli that would prefix all the ts and js code that makes up an application be annotated in this way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Declaring events in a TypeScript class which extends ...
How can I declare the on method with specific event name and listener signature? class MyClass extends events.EventEmitter { emitHello(name: ...
Read more >
Pure Virtual Destructor in C++ - GeeksforGeeks
A pure virtual destructor can be declared in C++. After a destructor has been created as a pure virtual object(instance of a class), ......
Read more >
CXXRecordDecl Class Reference - Clang
This flag is a workaround for an issue with parsing, where default arguments are parsed before their enclosing function declarations have been created....
Read more >
Common Function Attributes (Using the GNU Compiler ...
Declaring such functions with the pure attribute allows GCC to avoid emitting some calls in repeated invocations of the function with the same...
Read more >
Component Events | Vue.js
Read that first if you are new to components. Watch a free video lesson on Vue School. Emitting and Listening to Events #....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found