GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — How to overwrite __extends emitter? · Issue #2487 · microsoft/TypeScript

How to overwrite __extends emitter? #2487

New issue
Copy link
New issue
Copy link
Closed
Closed
How to overwrite __extends emitter?#2487
Copy link
Labels
DuplicateAn existing issue was already createdAn existing issue was already created

Description

@streamich
Va Da (streamich)
opened on Mar 25, 2015
Issue body actions

Currently TypeScripts emits in every file something like this:

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

Which is only some 300 bytes, but it is in every file. If my web app has hundreds of files, this adds up.

Instead what is the easiest modification to do to make it emit the following in every file:

var __extends = Object.create;

Can I do something like this?

typescript.settings.emitter.extends = "var __extends = Object.create;"

And leave it up to me to make sure Object.create actually exists.

Activity

  1. DickvdBrink commented on Mar 25, 2015

    @DickvdBrink
    Dick van den Brink (DickvdBrink)
    on Mar 25, 2015
    Contributor
    More actions

    I think this issue is covered by issue #2009
    And this PR would have fixed it (I think) #1356 but it is closed.

  2. danquirk commented on Mar 25, 2015

    @danquirk
    Dan Quirk (danquirk)
    on Mar 25, 2015
    Member
    More actions

    Yeah, dupe. If I recall correctly the referenced PR ended up not being a sufficient fix and the full fix was more complex.

  3. Dan Quirk (danquirk)
    added
    DuplicateAn existing issue was already createdAn existing issue was already created
    on Mar 25, 2015
  4. Dan Quirk (danquirk)
    closed this as completedon Mar 25, 2015
  5. streamich commented on Mar 25, 2015

    @streamich
    Va Da (streamich)
    on Mar 25, 2015
    Author
    More actions

    Well, this is kinda important. This code is emitted in every file. An average web app has some 1,000 files: 300 bytes x 1,000 files = 300Kb for every page view.

  6. streamich commented on Mar 25, 2015

    @streamich
    Va Da (streamich)
    on Mar 25, 2015
    Author
    More actions

    Maybe you could consider a hot fix, like something below:

    if(you_want_a_slow_huge_web_app_with_hundreds_of_redundant__extends_functions_that_will_never_execute) {
        writeLine();
        write("var __extends = this.__extends || function (d, b) {");
        increaseIndent();
        writeLine();
        write("for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];");
        writeLine();
        write("function __() { this.constructor = d; }");
        writeLine();
        write("__.prototype = b.prototype;");
        writeLine();
        write("d.prototype = new __();");
        decreaseIndent();
        writeLine();
        write("};");
    } else {
        write("var __extends = " + some_very_short_global_var);
    }
    
  7. RyanCavanaugh commented on Mar 25, 2015

    @RyanCavanaugh
    Ryan Cavanaugh (RyanCavanaugh)
    on Mar 25, 2015
    Member
    More actions

    This code is emitted in every file.

    If you compile with --out, you're only going to get it once. If you don't have any derived classes in a file, that file will not have an __extends function.

    An average web app has some 1,000 files: 300 bytes x 1,000 files = 300Kb for every request.

    If you really believe this is a huge problem, please spend the 10 minutes to write a step in your build pipeline to run a simple regex against the generated .js. If you're really serving 1,000 JS files on every request, you need to re-examine your caching policies. If you're serving them over separate HTTP calls then you're spending way more than that amount of bandwidth in HTTP headers anyway and it you should be serving it as a single bundled file. Since 1,000 files worth of JS is going to be several megabytes, you're going to want to gzip it anyway, which means that repeated text is going to be highly compressed. This can't conceivably be the blocker you make it out to be.

  8. microsoft
    locked and limited conversation to collaborators on Jun 18, 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

    DuplicateAn existing issue was already createdAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.