Skip to content

Modularize polyfills  #8854

Description

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);
    // ...

Activity

  1. kitsonk commented on May 27, 2016

    @kitsonk
    Contributor
    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?

  2. nippur72 commented on May 27, 2016

    @nippur72
    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.

  3. kitsonk commented on May 27, 2016

    @kitsonk
    Contributor

    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.

  4. nippur72 commented on May 27, 2016

    @nippur72
    Author

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

  5. kitsonk commented on May 29, 2016

    @kitsonk
    Contributor

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

  6. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions