This repository was archived by the owner on Jun 10, 2019. It is now read-only.
Description Hello,
I've encountered a case when kneden incorrectly adds extra .then(function () {}); call at the end of the generated async function.
Consider this code:
async function handler() {
const response = await fetch('http://address');
if (!response.ok) {
return null; // 1
}
const json = await response.json(); // 2
return {
a: 3
};
}
It produces the following code:
'use strict';
function handler() {
var response, json;
return Promise.resolve().then(function () {
return fetch('http://address');
}).then(function (_resp) {
response = _resp;
if (!response.ok) {
return null; // 1
} else {
return Promise.resolve().then(function () {
return response.json();
}).then(function (_resp) {
json = _resp; // 2
return {
a: 3
};
});
}
}).then(function () {});
}
The last .then call swallows the last return statement. If you comment out line 1 or 2 then the generated code is correct (no extra .then).
I'm using:
require('babel-core').transform(source, { presets: "es2015", plugins: ["kneden"]}).code
with these dependencies:
"dependencies": {
"babel-core": "^6.5.2",
"babel-preset-es2015": "^6.5.0",
"kneden": "^1.0.1"
}
Oh, by the way thanks for this awesome library! The generated code is perfectly readable.
Reactions are currently unavailable
Hello,
I've encountered a case when kneden incorrectly adds extra
.then(function () {});call at the end of the generated async function.Consider this code:
It produces the following code:
The last
.thencall swallows the lastreturnstatement. If you comment out line 1 or 2 then the generated code is correct (no extra.then).I'm using:
require('babel-core').transform(source, { presets: "es2015", plugins: ["kneden"]}).codewith these dependencies:
Oh, by the way thanks for this awesome library! The generated code is perfectly readable.