0

I've updated to latest babel v6. However I noticed that using transform-es2015-classes plugin with loose mode on (https://github.com/bkonkle/babel-preset-es2015-loose/blob/master/index.js#L8) breaks async/await functions. For example:

function _asyncFunc (value) {
  return new Promise((resolve) => {
    setTimeout(() => resolve(value), 10);
  });
}

class TestActions {
  async asyncAction(returnValue) {
    const result = await _asyncFunc(returnValue); // exception here
    return result;
  }
}

Breaks with loose on this line:

var result = await _asyncFunc(returnValue); ^^^^^^^^^^ SyntaxError: Unexpected identifier

Babelrc looks as follows (also I'm using regenerator runtime by importing it in entry point import 'babel-runtime/regenerator/runtime';):

{
  "presets": [
    "es2015-loose",
    "react",
    "stage-0"
  ]
}

I need to use loose mode because of this Babel bug - https://phabricator.babeljs.io/T3041

Any workarounds?

Kosmetika
  • 20,774
  • 37
  • 108
  • 172
  • I don't know if i would be help to you, refer to it [using-es7-asyncawait-today-with-babel.html](http://masnun.com/2015/11/11/using-es7-asyncawait-today-with-babel.html). – Alfred Dec 06 '15 at 16:54
  • it was a bug in Babel, already solved.. – Kosmetika Dec 06 '15 at 17:08

1 Answers1

1

It was a bug in Babel v6 and it was already fixed in 6.3.15 just update your packages, pr - https://github.com/babel/babel/pull/3135

Kosmetika
  • 20,774
  • 37
  • 108
  • 172