2015-12-06 39 views
0

我已经更新到最新的通天V6。但是我注意到,使用transform-es2015-classes插件松散模式上(https://github.com/bkonkle/babel-preset-es2015-loose/blob/master/index.js#L8)打破异步/等待功能。例如:巴贝尔V6 - 变换 - ES2015类的松散模式插件会引发SyntaxError:对于异步意外标识符/等待

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" 
    ] 
} 

我需要使用松散模式,因为这个巴别塔的bug - https://phabricator.babeljs.io/T3041

任何变通办法?

+0

我不知道我是否对您有所帮助,参考一下吧[使用-es7- asyncawait-今天与-babel.html(http://masnun.com/2015/11/11/using-es7-asyncawait-today-with-babel.html)。 –

+0

这是巴贝尔的一个bug,已经解决了。 – Kosmetika

回答