babel/kneden

Unnecessary extra tick

オープン

#47 opened on 2016/04/10

 (4 件のコメント) (3 件のリアクション) (0 人の担当者)JavaScript (37 件のフォーク)batch import
bughelp wanted

Repository metrics

Stars
 (519 個のスター)
PR merge metrics
 (30d に merged 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.

コントリビューターガイド