Open jods4 opened 6 years ago
I think I'm ok with the dependency on tslib. How large is it?
@EisenbergEffect The whole thing is 200 lines, 10K, before minification and gzip. Quite small: https://github.com/Microsoft/tslib/blob/master/tslib.js
There's even a smaller one when targetting es6.
I use tslib in my aurelia projects, it really cuts down on code size and makes the transpiled code much more readable since you don't have to scroll through the 50 lines of helpers otherwise emitted for say an async *
.
It works out of the box with both the 0.19.x and 0.20.x forks of SystemJS as of 1.8.0.
Per @StrahilKazlachev request:
We need to settle how we want to handle TS helpers in codegen.
When compiling to ES5 -- or even ES6 (e.g. decorators) -- TS makes use of a few helper functions, for example
__extends
when using class inheritance in ES5,__rest
when using rest properties,__decorate
when using decorators.By default, used helpers are emitted at the top of each output file (only helpers used in that file, of course). Aurelia is made of many files and it really adds up to a lot of redundant code. Even more so if we use
__awaiter
or__generator
, which are large.Fortunately, Typescript has two options to address this problem:
--noEmitHelpers
does what it says. The generated code won't run unless your provide helpers in some way (likely a set of global variables).--importHelpers
imports the required helpers fromtslib
at the top of generated file. Moduletslib
is distributed and maintained by MS.I think the
importHelpers
solution is the simplest, is maintained by MS (when there's a new helper or one needs changing), optimizes with bundlers like Webpack or Rollup and works along other TS code compiled withimportHelpers
(e.g. app code or other libs).The main drawback that @EisenbergEffect doesn't like is that this means Aurelia would have an external dependency on
tslib
, whereas today it has none.I would point out that all serious projects today use a bundler and that if someone doesn't want to use
tslib
, it's easy to map the name to another arbitrary module, even one distributed with Aurelia if we really want to go this route.