Skip to content

"__extends" function repeats multiple times inside compiled code. #101

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

Closed
logashoff opened this issue Dec 2, 2015 · 4 comments
Closed

Comments

@logashoff
Copy link

The following piece of code is being included into each compiled module whenever a class is extended inside that module:

var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};

So if you have 10 modules that have a class in each one of them that extends some other class, you'll have 10 exactly the same __extends functions in your compiled code.

@smrq
Copy link
Member

smrq commented Dec 2, 2015

That's just how the TS compiler works. Deduplicating that code is way, way outside the scope of this project.

I suppose it's possible that some sort of clever minifier could deal with it, but it would be quite tricky.

@logashoff
Copy link
Author

Is it possible to put all TypeScript boilerplate code above compiled modules? Maybe wrap everything in a function so it doesn't become part of the global scope.

Is this issue part of tsify functionality or should it be handled by some other 3rd party post-processor?

@smrq
Copy link
Member

smrq commented Dec 2, 2015

The problem is that TypeScript compiles each file as its own separate chunk, including the boilerplate in each one. It would be untenable to try and detect what's boilerplate vs. what's not on a per-file basis.

Post-processing might work... I sure wouldn't want to try and maintain it, though. Better would be a TS compiler feature to do some sort of boilerplate extraction.

Either way, definitely not going to happen at this level. It's too far removed from what this package does. It's not a bad idea, though.

@smrq smrq closed this as completed Dec 2, 2015
@logashoff
Copy link
Author

Pull-request regarding this issue has already been merged: microsoft/TypeScript#2901

There is --noEmitHelpers compiler flag which won't generate __extends function, but it can be included separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants