microsoft / microsoft/TypeScript

support customisable externalHelpersModuleNameText for --importHelpers flag

Offen
#12,502 2 Kommentare 17 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

In Discussion Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

TypeScript Version: 2.1.1

Currently we can use --noEmitHelpers with --importHelpers to mitigate generation of bloated code in ever file which uses TS helpers ( extends, decorate ... etc ).
To make this work, currently only official tslib is supported which is hardcoded here

if I wanna override any of these helpers I cannot use --importHelpers, instead I need to import whole tslib and override helpers that I need before any code in app is executed, which is not very convenient, like here:

import 'tslib';

// Babel implementation of _inherits
function _inherits(subClass, superClass) {
  if (typeof superClass !== "function" && superClass !== null) {
    throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  }
  subClass.prototype = Object.create(superClass && superClass.prototype, {
    constructor: {
      value: subClass,
      enumerable: false,
      writable: true,
      configurable: true
    }
  });
  if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
}

(window as any).__extends = _inherits;

What I would like to have is flag in compilerOptions for setting node_module library name which should be used for --importHelpers.

Something like:

npm install --save my-tslib

{
  "compilerOptions": {
     "module": "es2105",
     "target": "es5",
     "noEmitHelpers": true,
     "importHelpers": true,
     "importHelpersLibrary": "my-tslib"
  }
}
// Hello.tsx
import * as React from 'react';
class Hello extends React.Component {}

will compile to:

// Hello.jsx
import * as tslib_1 from 'my-tslib';
import * as React from 'react';

var Hello = (function (_super) {
  tslib_1.__extends(Counter, _super);
  function Counter() {
        var _this = _super.apply(this, arguments) || this;
        return _this;
  }
  return Hello;
}(React.Component));

This will also help to support libraries like skate.js and use for instance Babel extends behaviour to make it work https://github.com/skatejs/skatejs/issues/936

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne bei der fest codierten tslib-Referenz in src/compiler/utilities.ts und verfolge, wie compilerOptions geparst werden und wie --importHelpers Imports ausgibt. Als abgeschlossen gilt die Änderung, wenn ein konfigurierbarer Modulname für --importHelpers akzeptiert und ausgegeben wird, während das bestehende Standardverhalten weiterhin unterstützt wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.