microsoft / microsoft/TypeScript
support customisable externalHelpersModuleNameText for --importHelpers flag
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
src/compiler/utilities.ts にあるハードコードされた tslib 参照から始め、compilerOptions がどのように解析され、--importHelpers がどのように import を出力するかを追ってください。--importHelpers に対して設定可能なモジュール名が受け付けられ、出力され、既存のデフォルト動作も引き続きサポートされれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100