'How to prevent babel from transpiling generator functions
I have kind of a weird problem with babel. When I use a simple generator function in one of my classes, babel creates a function out of it containing a call to regeneratorRuntime
.
var marked3$0 = [getQueryDummy].map(regeneratorRuntime.mark);
function getQueryDummy(start, end, step) {
return regeneratorRuntime.wrap(function getQueryDummy$(context$4$0) {
Bad thing is, it doesn't create this function which always results in an error when I forget to manually replace the compiled generator with the original one (which happens all the time)
I know I can add
require('babel/polyfill')
to my file. The polyfill holds the regeneratorRuntime
function. And here is where it's getting really weird. Even though I place the require(...)
at the very top of the file, babel calls regeneratorRuntime
before the polyfill is included, which again leads to the same error.
For completeness sake, here's the generator
function *getQueryDummy(start, end, step) {
while (start < end) {
yield [start, '@dummy'];
start += step;
}
}
I'm using babel version 5.8.23
.
Is there a way to tell babel to not touch generators
at all? node supports them natively and there's no need for me to compile it...
Solution 1:[1]
You could blacklist regenerator
. If you're building with transform
:
babel.transform(code, {blacklist:['regenerator']});
Or from command line with:
--blacklist regenerator
Solution 2:[2]
We can also use exclude https://babeljs.io/docs/en/babel-preset-env#exclude
And make use of .babelrc
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Pranay Dutta |