babel/kneden

Unnecessary extra tick

Aperta

#47 aperta il 10 apr 2016

 (4 commenti) (3 reazioni) (0 assegnatari)JavaScript (37 fork)batch import
bughelp wanted

Metriche repository

Star
 (519 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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.

Guida contributor