Skip to content

Commit 80a84c3

Browse files
TypeScript Bota-tarasyuk
TypeScript Bot
andauthored
Cherry-pick PR #37010 into release-3.8 (#37072)
Component commits: 4605c34 fix(36989): omit 'async' modifier for methods in declaration files. c144e5e Merge branch 'master' of https://github.com/Microsoft/TypeScript into bug/36989 fb7fd42 remove useless condition c2b709a Merge branch 'master' of https://github.com/Microsoft/TypeScript into bug/36989 Co-authored-by: Alexander T. <alexander.tarasyuk@outlook.com>
1 parent 6def346 commit 80a84c3

File tree

5 files changed

+152
-1
lines changed

5 files changed

+152
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6192,7 +6192,7 @@ namespace ts {
61926192
&& isTypeIdenticalTo(getTypeOfSymbol(p), getTypeOfPropertyOfType(baseType, p.escapedName)!))) {
61936193
return [];
61946194
}
6195-
const flag = modifierFlags | (isStatic ? ModifierFlags.Static : 0);
6195+
const flag = (modifierFlags & ~ModifierFlags.Async) | (isStatic ? ModifierFlags.Static : 0);
61966196
const name = getPropertyNameNodeForSymbol(p, context);
61976197
const firstPropertyLikeDecl = find(p.declarations, or(isPropertyDeclaration, isAccessor, isVariableDeclaration, isPropertySignature, isBinaryExpression, isPropertyAccessExpression));
61986198
if (p.flags & SymbolFlags.Accessor && useAccessors) {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//// [a.js]
2+
class Foo {
3+
async a() {
4+
await Promise.resolve(1);
5+
}
6+
7+
b = async () => {
8+
await Promise.resolve(1);
9+
}
10+
}
11+
12+
13+
//// [a.js]
14+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16+
return new (P || (P = Promise))(function (resolve, reject) {
17+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20+
step((generator = generator.apply(thisArg, _arguments || [])).next());
21+
});
22+
};
23+
var __generator = (this && this.__generator) || function (thisArg, body) {
24+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
25+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26+
function verb(n) { return function (v) { return step([n, v]); }; }
27+
function step(op) {
28+
if (f) throw new TypeError("Generator is already executing.");
29+
while (_) try {
30+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
31+
if (y = 0, t) op = [op[0] & 2, t.value];
32+
switch (op[0]) {
33+
case 0: case 1: t = op; break;
34+
case 4: _.label++; return { value: op[1], done: false };
35+
case 5: _.label++; y = op[1]; op = [0]; continue;
36+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
37+
default:
38+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42+
if (t[2]) _.ops.pop();
43+
_.trys.pop(); continue;
44+
}
45+
op = body.call(thisArg, _);
46+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48+
}
49+
};
50+
var Foo = /** @class */ (function () {
51+
function Foo() {
52+
var _this = this;
53+
this.b = function () { return __awaiter(_this, void 0, void 0, function () {
54+
return __generator(this, function (_a) {
55+
switch (_a.label) {
56+
case 0: return [4 /*yield*/, Promise.resolve(1)];
57+
case 1:
58+
_a.sent();
59+
return [2 /*return*/];
60+
}
61+
});
62+
}); };
63+
}
64+
Foo.prototype.a = function () {
65+
return __awaiter(this, void 0, void 0, function () {
66+
return __generator(this, function (_a) {
67+
switch (_a.label) {
68+
case 0: return [4 /*yield*/, Promise.resolve(1)];
69+
case 1:
70+
_a.sent();
71+
return [2 /*return*/];
72+
}
73+
});
74+
});
75+
};
76+
return Foo;
77+
}());
78+
79+
80+
//// [a.d.ts]
81+
declare class Foo {
82+
a(): Promise<void>;
83+
b: () => Promise<void>;
84+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== tests/cases/compiler/a.js ===
2+
class Foo {
3+
>Foo : Symbol(Foo, Decl(a.js, 0, 0))
4+
5+
async a() {
6+
>a : Symbol(Foo.a, Decl(a.js, 0, 11))
7+
8+
await Promise.resolve(1);
9+
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
10+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
11+
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
12+
}
13+
14+
b = async () => {
15+
>b : Symbol(Foo.b, Decl(a.js, 3, 5))
16+
17+
await Promise.resolve(1);
18+
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
19+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
20+
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
21+
}
22+
}
23+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
=== tests/cases/compiler/a.js ===
2+
class Foo {
3+
>Foo : Foo
4+
5+
async a() {
6+
>a : () => Promise<void>
7+
8+
await Promise.resolve(1);
9+
>await Promise.resolve(1) : number
10+
>Promise.resolve(1) : Promise<number>
11+
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
12+
>Promise : PromiseConstructor
13+
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
14+
>1 : 1
15+
}
16+
17+
b = async () => {
18+
>b : () => Promise<void>
19+
>async () => { await Promise.resolve(1); } : () => Promise<void>
20+
21+
await Promise.resolve(1);
22+
>await Promise.resolve(1) : number
23+
>Promise.resolve(1) : Promise<number>
24+
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
25+
>Promise : PromiseConstructor
26+
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
27+
>1 : 1
28+
}
29+
}
30+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @declaration: true
2+
// @allowJs: true
3+
// @outDir: ./out
4+
// @lib: es2015
5+
// @filename: a.js
6+
class Foo {
7+
async a() {
8+
await Promise.resolve(1);
9+
}
10+
11+
b = async () => {
12+
await Promise.resolve(1);
13+
}
14+
}

0 commit comments

Comments
 (0)