我已经更新到最新的 babel v6。但是我注意到,在( https://github.com/bkonkle/babel-preset-es2015-loose/blob/master/index.js#L8 )上使用松散模式的 transform-es2015-classes
插件会破坏 async/await 函数。例如:
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 结果 = wait _asyncFunc(returnValue);
^^^^^^^^^^
语法错误:意外的标识符
Babelrc 如下所示(我还通过在入口点导入它来使用再生器运行时import 'babel-runtime/regenerator/runtime';
):
{
"presets": [
"es2015-loose",
"react",
"stage-0"
]
}
由于 Babel 错误,我需要使用松散模式 - https://phabricator.babeljs.io/T3041
有什么解决办法吗?
最佳答案
这是 Babel v6 中的一个错误,它已在 6.3.15
中修复,只需更新您的软件包即可,pr - https://github.com/babel/babel/pull/3135
关于javascript - Babel v6 - 宽松模式下的transform-es2015-classes插件抛出SyntaxError : Unexpected identifier for async/await,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34117980/