Node 5 generator support incomplete
bmeck opened this issue ยท 8 comments
see jbach/babel-preset-es2015-node4#1 , same issue persists in Node 5
Hm... this is really odd issue.
Personally, I use ES6 generators natively since node 0.11 and before this day, I thought it has no problem and it's one of the nicest features implemented natively.
I don't like the fact of compiling generators with regenerator and including special runtime, because of return
bug. Also node's official documentation mentions generators as supported https://nodejs.org/en/docs/es6/.
Compact-table says node@5 covers 19/25 tests and babel+regenerator 22/25, and checks are a bit different, if we compile with regenerator, what's about generator.constructor
for example?
For this preset, I want to use an official node documentation as a reference, and don't go too much in specification details. If they claim, that generators support is not full or should not be used natively, I will add it.
If you rely on .return
and don't need native support, you can do:
{
"presets": [
"es2015-node5"
],
"plugins": [
"babel-plugin-transform-regenerator"
]
}
I think it's possible to write a special transformer which only patch return
for current V8 generators implementation, but I'm not sure I have enough time to do it now.
Agreed with @hax, special transformer similar to function-name would be a good solution.
Initial implementation: https://github.com/hax/babel-plugin-transform-es2015-generator-return
I will test and publish it soon. ๐
Tested and published!
You could add it to the preset ๐
Awesome! I've just tested this module, and it wraps every generator to try/catch block and patches GeneratorPrototype
. I still think, it should not be in a preset, since it may impact performance and make compiled code more verbose.
Maybe we should add a note to Readme instead?
Try-catch will impact performance to normal function, but generators in V8 are not fully optimized anyway.
Check https://github.com/petkaantonov/bluebird/wiki/Optimization-killers you will see let
/const
also stop the function optimization. Consider this preset do not use transform-block-scope either, I think it's ok to add this plugin to preset ๐
Node 5 also doesn't support yield *, iterator closing
. Which I believe is responsible for this issue: redux-saga/redux-saga#197