Skip to content

Commit 14d95ed

Browse files
committed
Test:Block-scoped definition of Promise works
Previously, a block-scoped definition of Promise like `class Promise<T>` in a script would cause a crash
1 parent a8846bf commit 14d95ed

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//// [promiseDefinitionTest.ts]
2+
class Promise<T> {}
3+
async function foo() {}
4+
const x = foo();
5+
6+
7+
//// [promiseDefinitionTest.js]
8+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9+
return new (P || (P = Promise))(function (resolve, reject) {
10+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
13+
step((generator = generator.apply(thisArg, _arguments || [])).next());
14+
});
15+
};
16+
var __generator = (this && this.__generator) || function (thisArg, body) {
17+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
18+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
19+
function verb(n) { return function (v) { return step([n, v]); }; }
20+
function step(op) {
21+
if (f) throw new TypeError("Generator is already executing.");
22+
while (_) try {
23+
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
24+
if (y = 0, t) op = [0, t.value];
25+
switch (op[0]) {
26+
case 0: case 1: t = op; break;
27+
case 4: _.label++; return { value: op[1], done: false };
28+
case 5: _.label++; y = op[1]; op = [0]; continue;
29+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
30+
default:
31+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
32+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
33+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
34+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
35+
if (t[2]) _.ops.pop();
36+
_.trys.pop(); continue;
37+
}
38+
op = body.call(thisArg, _);
39+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
40+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
41+
}
42+
};
43+
var Promise = (function () {
44+
function Promise() {
45+
}
46+
return Promise;
47+
}());
48+
function foo() {
49+
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
50+
return [2 /*return*/];
51+
}); });
52+
}
53+
var x = foo();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/promiseDefinitionTest.ts ===
2+
class Promise<T> {}
3+
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --), Decl(promiseDefinitionTest.ts, 0, 0))
4+
>T : Symbol(T, Decl(lib.d.ts, --, --), Decl(promiseDefinitionTest.ts, 0, 14))
5+
6+
async function foo() {}
7+
>foo : Symbol(foo, Decl(promiseDefinitionTest.ts, 0, 19))
8+
9+
const x = foo();
10+
>x : Symbol(x, Decl(promiseDefinitionTest.ts, 2, 5))
11+
>foo : Symbol(foo, Decl(promiseDefinitionTest.ts, 0, 19))
12+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/promiseDefinitionTest.ts ===
2+
class Promise<T> {}
3+
>Promise : Promise<T>
4+
>T : T
5+
6+
async function foo() {}
7+
>foo : () => Promise<void>
8+
9+
const x = foo();
10+
>x : Promise<void>
11+
>foo() : Promise<void>
12+
>foo : () => Promise<void>
13+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @target: es5
2+
class Promise<T> {}
3+
async function foo() {}
4+
const x = foo();

0 commit comments

Comments
 (0)