$await放在条件中,似乎编译出来的代码不正确
Closed this issue · 0 comments
chenfengyuan commented
代码
eval(Wind.compile('async',function(){
if($await(Wind.Async.sleep(1000)))
console.log('true')
else
console.log('false')
console.log('done')
}))
产生
function () {
var _builder_$0 = Wind.builders["async"];
return _builder_$0.Start(this,
_builder_$0.Delay(function () {
/* if ($await(Wind.Async.sleep(1000))) */ if ($await(Wind.Async.sleep(1000)))
/* console.log("true"); */ console.log("true");
/* else */ else
/* console.log("false"); */ console.log("false");
/* console.log("done"); */ console.log("done");
return _builder_$0.Normal();
})
);
/* } */
$await没有被特殊处理,运行此函数,报错
Uncaught ReferenceError: $await is not defined
而如果先把结果存在变量中,再去判断就没问题了,
eval(Wind.compile('async',function(){
var tmp = $await(Wind.Async.sleep(1000))
if(tmp)
console.log('true')
else
console.log('false')
console.log('done')
}))
产生:
function () {
var _builder_$0 = Wind.builders["async"];
return _builder_$0.Start(this,
_builder_$0.Delay(function () {
/* var tmp = $await(Wind.Async.sleep(1000)); */ return _builder_$0.Bind(Wind.Async.sleep(1000), function (tmp) {
/* if (tmp) */ if (tmp)
/* console.log("true"); */ console.log("true");
/* else */ else
/* console.log("false"); */ console.log("false");
/* console.log("done"); */ console.log("done");
return _builder_$0.Normal();
});
})
);
/* } */ }
能正常运行。