babel/kneden

Incorrect result with async arrow functions when not using `babel-preset-es2015`

Open

#19 aperta il 14 feb 2016

Vedi su GitHub
 (6 commenti) (0 reazioni) (0 assegnatari)JavaScript (37 fork)batch import
enhancementhelp wanted

Metriche repository

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

Descrizione

I tried kneden out on some test files where I was previously using babel-transform-async-to-generator and came across a failing case.

In this project I wasn't using babel-preset-es2015 as I just wanted to compile async/await down to es6.

I've simplified the test case down to this:

.babelrc

{
  "plugins": ["../../../src"]
}

actual.js

function test() {
  let server;
  before(async () => server = await TestServer.start());
}

The output I get from running the test is:

function test() {
  let server;
  before(() => {
    return Promise.resolve();
  });
}

which is definitely not right :)

If I add "presets": ["es2015"] to .babelrc in the fixture dir I get the more correct looking:

function test() {
  var server = undefined;
  before(function () {
    return Promise.resolve().then(function () {
      return TestServer.start();
    }).then(function (_resp) {
      return server = _resp;
    });
  });
}

Guida contributor