Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 312
baao Avatar asked Oct 07 '15 14:10

baao


1 Answers

You could blacklist regenerator. If you're building with transform:

babel.transform(code, {blacklist:['regenerator']});

Or from command line with:

--blacklist regenerator
like image 60
Amit Avatar answered Sep 21 '22 12:09

Amit