microsoft / microsoft/TypeScript
support customisable externalHelpersModuleNameText for --importHelpers flag
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dal riferimento hardcoded a tslib in src/compiler/utilities.ts e segui come vengono analizzati compilerOptions e come --importHelpers emette gli import. Il lavoro è completato quando viene accettato ed emesso un nome di modulo configurabile per --importHelpers, mantenendo al contempo il supporto per il comportamento predefinito esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100