babel/kneden

Unnecessary extra tick

開放

#47 建立於 2016年4月10日

 (4 則留言) (3 個反應) (0 位負責人)JavaScript (37 個分叉)batch import
bughelp wanted

倉庫指標

星標
 (519 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

var foo = async () => {
  console.log(1);
  return (await 1) + 2;
}
foo();
console.log(2);

should transpile to:

var foo = function foo() {
  return new Promise(function (resolve) {
    console.log(1);
    resolve(1);
  }).then(function (_resp) {
    return _resp + 2;
  });
};
foo();
console.log(2);

which should log 1, then 2.

but instead transpiles to:

var foo = function foo() {
  return Promise.resolve().then(function () {
    console.log(1);
    return 1;
  }).then(function (_resp) {
    return _resp + 2;
  });
};
foo();
console.log(2);

This difference means the async function takes an extra tick - which results in logging 2, then 1.

貢獻者指南