0

我已经更新到最新的 babel v6。但是我注意到在( https://github.com/bkonkle/babel-preset-es2015-loose/blob/master/index.js#L8transform-es2015-classes )上使用松散模式的插件会破坏异步/等待功能。例如:

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;
  }
}

在这条线上松散地休息:

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

Babelrc 看起来如下(我也通过在入口点导入它来使用再生器运行时import 'babel-runtime/regenerator/runtime';):

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

由于这个 Babel 错误,我需要使用松散模式 - https://phabricator.babeljs.io/T3041

任何解决方法?

4

1 回答 1

1

这是 Babel v6 中的一个错误,它已经在6.3.15更新你的包中得到修复,pr - https://github.com/babel/babel/pull/3135

于 2015-12-06T17:08:40.783 回答