piotrwitek / react-redux-typescript-jspm-starter

Futuristic, bundle-free, development environment for building Component-Driven SPA with React, Redux and TypeScript - powered by JSPM (SystemJS & Rollup with tree-shaking)
https://piotrwitek.github.io/react-redux-typescript-jspm-starter/
MIT License
231 stars 43 forks source link

Compile TS generators to ES5 without Babel? #23

Closed kdalgaard closed 7 years ago

kdalgaard commented 7 years ago

Resuming the discussion from here: https://github.com/Microsoft/TypeScript/issues/1564#issuecomment-252832787

I contend that the method below (from the docs of this starter) is not possible, due to the simple reason that it's not possible to compile TS with generators intact to an ES5 target in the first place.

Alternative solution to resolve Generator transformation to ES3/ES5: My solution prefer using only Facebook Regenerator Project instead of adding Babel as dependency (NOTE: Babel internally is using the same approach, running "regenerator runtime" internally for async and generator functions transformations - https://babeljs.io/docs/usage/caveats/)

When building for production use npm run regenerator CLI command just after a build command to apply transform to app.js bundle, or use an alias command npm run build:regenerator to run it automatically with each build.

piotrwitek commented 7 years ago

It is possible - it works because TypeScript compiler is emitting output files even if there are some errors during a compilation process. In case of generator functions, TSC will show an error about unknown syntax and it will omit this code block leaving it intact (NOTE: noEmitOnError flag should have default value - which is false)

piotrwitek commented 7 years ago

closing as this was already thoroughly explained here: https://github.com/Microsoft/TypeScript/issues/1564#issuecomment-252903932