-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11291 from Microsoft/fix11177
Fix crash with nested generators
- Loading branch information
Showing
5 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
tests/baselines/reference/transformNestedGeneratorsWithTry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void> { | ||
try { | ||
const b = async function b(): Bluebird<void> { | ||
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<T> = Promise<T>; | ||
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*/]; | ||
} | ||
}); | ||
}); | ||
} |
48 changes: 48 additions & 0 deletions
48
tests/baselines/reference/transformNestedGeneratorsWithTry.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void> { | ||
>a : Symbol(a, Decl(main.ts, 1, 37)) | ||
>Bluebird : Symbol(Bluebird, Decl(main.ts, 1, 6)) | ||
|
||
try { | ||
const b = async function b(): Bluebird<void> { | ||
>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<T> = Promise<T>; | ||
>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)) | ||
} |
53 changes: 53 additions & 0 deletions
53
tests/baselines/reference/transformNestedGeneratorsWithTry.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void> { | ||
>a : () => Promise<void> | ||
>Bluebird : Promise<T> | ||
|
||
try { | ||
const b = async function b(): Bluebird<void> { | ||
>b : () => Promise<void> | ||
>async function b(): Bluebird<void> { try { await Bluebird.resolve(); // -- remove this and it compiles } catch (error) { } } : () => Promise<void> | ||
>b : () => Promise<void> | ||
>Bluebird : Promise<T> | ||
|
||
try { | ||
await Bluebird.resolve(); // -- remove this and it compiles | ||
>await Bluebird.resolve() : void | ||
>Bluebird.resolve() : Promise<void> | ||
>Bluebird.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; } | ||
>Bluebird : PromiseConstructor | ||
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; } | ||
|
||
} catch (error) { } | ||
>error : any | ||
|
||
}; | ||
|
||
await b(); // -- or remove this and it compiles | ||
>await b() : void | ||
>b() : Promise<void> | ||
>b : () => Promise<void> | ||
|
||
} catch (error) { } | ||
>error : any | ||
} | ||
|
||
=== tests/cases/compiler/bluebird.d.ts === | ||
declare module "bluebird" { | ||
type Bluebird<T> = Promise<T>; | ||
>Bluebird : Promise<T> | ||
>T : T | ||
>Promise : Promise<T> | ||
>T : T | ||
|
||
const Bluebird: typeof Promise; | ||
>Bluebird : PromiseConstructor | ||
>Promise : PromiseConstructor | ||
|
||
export = Bluebird; | ||
>Bluebird : Promise<T> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void> { | ||
try { | ||
const b = async function b(): Bluebird<void> { | ||
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<T> = Promise<T>; | ||
const Bluebird: typeof Promise; | ||
export = Bluebird; | ||
} |