Closed
Description
TypeScript Version: 2.6.2, 2.7.0-dev.20171203, target: es2015
Code
async function test(url) {
console.log(url);
}
async function fn(url) {
await test(url);
var url;
}
fn("test");
Expected behavior:
"test" should be logged
Actual behavior:
undefined is logged
The generated code clobbers the var declaration in the outer function, by adding another function around the code:
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
function test(url) {
return __awaiter(this, void 0, void 0, function* () {
console.log(url);
});
}
function fn(url) {
return __awaiter(this, void 0, void 0, function* () {
yield test(url);
var url;
});
}
fn("test");