Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix downlevel async hoisting #11130

Merged
merged 1 commit into from
Sep 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/compiler/transformers/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,11 @@ namespace ts {
operationLocations = undefined;
state = createTempVariable(/*recordTempVariable*/ undefined);

const statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor);

// Build the generator
startLexicalEnvironment();

const statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor);

transformAndEmitStatements(body.statements, statementOffset);

const buildResult = build();
Expand Down Expand Up @@ -615,6 +615,11 @@ namespace ts {
return undefined;
}
else {
// Do not hoist custom prologues.
if (node.emitFlags & NodeEmitFlags.CustomPrologue) {
return node;
}

for (const variable of node.declarationList.declarations) {
hoistVariableDeclaration(<Identifier>variable.name);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/asyncArrowFunction7_es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var bar = async (): Promise<void> => {
//// [asyncArrowFunction7_es5.js]
var _this = this;
var bar = function () { return __awaiter(_this, void 0, void 0, function () {
_this = this;
var _this = this;
var foo;
return __generator(this, function (_a) {
foo = function (a) {
Expand All @@ -22,4 +22,4 @@ var bar = function () { return __awaiter(_this, void 0, void 0, function () {
};
return [2 /*return*/];
});
}); var _this; };
}); };