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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modularize polyfills #8854

Closed
nippur72 opened this issue May 27, 2016 · 5 comments
Closed

Modularize polyfills #8854

nippur72 opened this issue May 27, 2016 · 5 comments

Comments

@nippur72
Copy link

As far as I know, polyfill functions are repeated in each file they are needed, resulting in lot of duplicate code.

I suggest to optionally emit them as a module, so that they appear once in a bundled project.

E.g. instead of:

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 __());
};

var myclass= (function (_super) {
    __extends(myclass, _super);
    // ...

emit this:

var __extends = require("typescript-polyfills").extends;

var myclass= (function (_super) {
    __extends(myclass, _super);
    // ...
@kitsonk
Copy link
Contributor

kitsonk commented May 27, 2016

var __extends = require("typescript-polyfills").extends;

This assumes everyone is using the Common JS module loader. What about those using an AMD loader, a SystemJS loader, etc?

@nippur72
Copy link
Author

oh that was just an example, I guess we could actually use the existing TypeScript capability of turning any import code into the chosen module loader. E.g. a sort of intermediate compilation with:

import { extends as __extends } from "typescript-polyfills";

var myclass= (function (_super) {
    __extends(myclass, _super);
    // ...

The basic idea here is to put polyfills into modules to save space. But perhaps that work might be delegated to the bundlers (webpack/browserify/etc...) by the use of a specific plugin.

@kitsonk
Copy link
Contributor

kitsonk commented May 27, 2016

Still doesn't deal with how the module will be resolvable...

Anyways a quick search shows that this is a dupe of #1350 which was discussed and the solution was #2901 (noEmitHelpers) flag.

@nippur72
Copy link
Author

thanks and sorry for the dupe--I always check but sometimes you don't know what terms to look for.

@kitsonk
Copy link
Contributor

kitsonk commented May 29, 2016

Also, for completeness, #3364 is delivering the helpers as a module for TS2.0 as per the roadmap.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants