diff --git a/src/compiler/transformers/generators.ts b/src/compiler/transformers/generators.ts index 6fe3187bee184..f3a47f037cadd 100644 --- a/src/compiler/transformers/generators.ts +++ b/src/compiler/transformers/generators.ts @@ -552,6 +552,7 @@ namespace ts { const savedBlocks = blocks; const savedBlockOffsets = blockOffsets; const savedBlockActions = blockActions; + const savedBlockStack = blockStack; const savedLabelOffsets = labelOffsets; const savedLabelExpressions = labelExpressions; const savedNextLabelId = nextLabelId; @@ -566,6 +567,7 @@ namespace ts { blocks = undefined; blockOffsets = undefined; blockActions = undefined; + blockStack = undefined; labelOffsets = undefined; labelExpressions = undefined; nextLabelId = 1; @@ -591,6 +593,7 @@ namespace ts { blocks = savedBlocks; blockOffsets = savedBlockOffsets; blockActions = savedBlockActions; + blockStack = savedBlockStack; labelOffsets = savedLabelOffsets; labelExpressions = savedLabelExpressions; nextLabelId = savedNextLabelId; diff --git a/tests/baselines/reference/transformNestedGeneratorsWithTry.js b/tests/baselines/reference/transformNestedGeneratorsWithTry.js new file mode 100644 index 0000000000000..4ad1b2b7e88e1 --- /dev/null +++ b/tests/baselines/reference/transformNestedGeneratorsWithTry.js @@ -0,0 +1,101 @@ +//// [tests/cases/compiler/transformNestedGeneratorsWithTry.ts] //// + +//// [main.ts] +// https://github.com/Microsoft/TypeScript/issues/11177 +import * as Bluebird from 'bluebird'; +async function a(): Bluebird { + try { + const b = async function b(): Bluebird { + try { + await Bluebird.resolve(); // -- remove this and it compiles + } catch (error) { } + }; + + await b(); // -- or remove this and it compiles + } catch (error) { } +} + +//// [bluebird.d.ts] +declare module "bluebird" { + type Bluebird = Promise; + const Bluebird: typeof Promise; + export = Bluebird; +} + +//// [main.js] +"use strict"; +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()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t; + return { next: verb(0), "throw": verb(1), "return": verb(2) }; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [0, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +// https://github.com/Microsoft/TypeScript/issues/11177 +var Bluebird = require("bluebird"); +function a() { + return __awaiter(this, void 0, Bluebird, function () { + var b, error_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 2, , 3]); + b = function b() { + return __awaiter(this, void 0, Bluebird, function () { + var error_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 2, , 3]); + return [4 /*yield*/, Bluebird.resolve()]; + case 1: + _a.sent(); // -- remove this and it compiles + return [3 /*break*/, 3]; + case 2: + error_2 = _a.sent(); + return [3 /*break*/, 3]; + case 3: return [2 /*return*/]; + } + }); + }); + }; + return [4 /*yield*/, b()]; + case 1: + _a.sent(); // -- or remove this and it compiles + return [3 /*break*/, 3]; + case 2: + error_1 = _a.sent(); + return [3 /*break*/, 3]; + case 3: return [2 /*return*/]; + } + }); + }); +} diff --git a/tests/baselines/reference/transformNestedGeneratorsWithTry.symbols b/tests/baselines/reference/transformNestedGeneratorsWithTry.symbols new file mode 100644 index 0000000000000..e966202c2777a --- /dev/null +++ b/tests/baselines/reference/transformNestedGeneratorsWithTry.symbols @@ -0,0 +1,48 @@ +=== tests/cases/compiler/main.ts === +// https://github.com/Microsoft/TypeScript/issues/11177 +import * as Bluebird from 'bluebird'; +>Bluebird : Symbol(Bluebird, Decl(main.ts, 1, 6)) + +async function a(): Bluebird { +>a : Symbol(a, Decl(main.ts, 1, 37)) +>Bluebird : Symbol(Bluebird, Decl(main.ts, 1, 6)) + + try { + const b = async function b(): Bluebird { +>b : Symbol(b, Decl(main.ts, 4, 9)) +>b : Symbol(b, Decl(main.ts, 4, 13)) +>Bluebird : Symbol(Bluebird, Decl(main.ts, 1, 6)) + + try { + await Bluebird.resolve(); // -- remove this and it compiles +>Bluebird.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Bluebird : Symbol(Bluebird, Decl(main.ts, 1, 6)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + + } catch (error) { } +>error : Symbol(error, Decl(main.ts, 7, 15)) + + }; + + await b(); // -- or remove this and it compiles +>b : Symbol(b, Decl(main.ts, 4, 9)) + + } catch (error) { } +>error : Symbol(error, Decl(main.ts, 11, 11)) +} + +=== tests/cases/compiler/bluebird.d.ts === +declare module "bluebird" { + type Bluebird = Promise; +>Bluebird : Symbol(Bluebird, Decl(bluebird.d.ts, 0, 27), Decl(bluebird.d.ts, 2, 9)) +>T : Symbol(T, Decl(bluebird.d.ts, 1, 18)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>T : Symbol(T, Decl(bluebird.d.ts, 1, 18)) + + const Bluebird: typeof Promise; +>Bluebird : Symbol(Bluebird, Decl(bluebird.d.ts, 0, 27), Decl(bluebird.d.ts, 2, 9)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + export = Bluebird; +>Bluebird : Symbol(Bluebird, Decl(bluebird.d.ts, 0, 27), Decl(bluebird.d.ts, 2, 9)) +} diff --git a/tests/baselines/reference/transformNestedGeneratorsWithTry.types b/tests/baselines/reference/transformNestedGeneratorsWithTry.types new file mode 100644 index 0000000000000..3e4ef3f0852cf --- /dev/null +++ b/tests/baselines/reference/transformNestedGeneratorsWithTry.types @@ -0,0 +1,53 @@ +=== tests/cases/compiler/main.ts === +// https://github.com/Microsoft/TypeScript/issues/11177 +import * as Bluebird from 'bluebird'; +>Bluebird : PromiseConstructor + +async function a(): Bluebird { +>a : () => Promise +>Bluebird : Promise + + try { + const b = async function b(): Bluebird { +>b : () => Promise +>async function b(): Bluebird { try { await Bluebird.resolve(); // -- remove this and it compiles } catch (error) { } } : () => Promise +>b : () => Promise +>Bluebird : Promise + + try { + await Bluebird.resolve(); // -- remove this and it compiles +>await Bluebird.resolve() : void +>Bluebird.resolve() : Promise +>Bluebird.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Bluebird : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } + + } catch (error) { } +>error : any + + }; + + await b(); // -- or remove this and it compiles +>await b() : void +>b() : Promise +>b : () => Promise + + } catch (error) { } +>error : any +} + +=== tests/cases/compiler/bluebird.d.ts === +declare module "bluebird" { + type Bluebird = Promise; +>Bluebird : Promise +>T : T +>Promise : Promise +>T : T + + const Bluebird: typeof Promise; +>Bluebird : PromiseConstructor +>Promise : PromiseConstructor + + export = Bluebird; +>Bluebird : Promise +} diff --git a/tests/cases/compiler/transformNestedGeneratorsWithTry.ts b/tests/cases/compiler/transformNestedGeneratorsWithTry.ts new file mode 100644 index 0000000000000..7d57c17c7a390 --- /dev/null +++ b/tests/cases/compiler/transformNestedGeneratorsWithTry.ts @@ -0,0 +1,23 @@ +// @target: ES5 +// @lib: es5,es6 +// @filename: main.ts +// https://github.com/Microsoft/TypeScript/issues/11177 +import * as Bluebird from 'bluebird'; +async function a(): Bluebird { + try { + const b = async function b(): Bluebird { + try { + await Bluebird.resolve(); // -- remove this and it compiles + } catch (error) { } + }; + + await b(); // -- or remove this and it compiles + } catch (error) { } +} + +// @filename: bluebird.d.ts +declare module "bluebird" { + type Bluebird = Promise; + const Bluebird: typeof Promise; + export = Bluebird; +} \ No newline at end of file