Skip to content

Commit 992b385

Browse files
authored
Merge pull request #11130 from Microsoft/fix11031
Fix downlevel async hoisting
2 parents 95c3ecc + b21a739 commit 992b385

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/compiler/transformers/generators.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,11 @@ namespace ts {
573573
operationLocations = undefined;
574574
state = createTempVariable(/*recordTempVariable*/ undefined);
575575

576-
const statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor);
577-
578576
// Build the generator
579577
startLexicalEnvironment();
580578

579+
const statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor);
580+
581581
transformAndEmitStatements(body.statements, statementOffset);
582582

583583
const buildResult = build();
@@ -615,6 +615,11 @@ namespace ts {
615615
return undefined;
616616
}
617617
else {
618+
// Do not hoist custom prologues.
619+
if (node.emitFlags & NodeEmitFlags.CustomPrologue) {
620+
return node;
621+
}
622+
618623
for (const variable of node.declarationList.declarations) {
619624
hoistVariableDeclaration(<Identifier>variable.name);
620625
}

tests/baselines/reference/asyncArrowFunction7_es5.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var bar = async (): Promise<void> => {
99
//// [asyncArrowFunction7_es5.js]
1010
var _this = this;
1111
var bar = function () { return __awaiter(_this, void 0, void 0, function () {
12-
_this = this;
12+
var _this = this;
1313
var foo;
1414
return __generator(this, function (_a) {
1515
foo = function (a) {
@@ -22,4 +22,4 @@ var bar = function () { return __awaiter(_this, void 0, void 0, function () {
2222
};
2323
return [2 /*return*/];
2424
});
25-
}); var _this; };
25+
}); };

0 commit comments

Comments
 (0)