0
votes

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?

1
I don't know if i would be help to you, refer to it using-es7-asyncawait-today-with-babel.html.aluc
it was a bug in Babel, already solved..Kosmetika

1 Answers

1
votes

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