Skip to content

Commit cb1af04

Browse files
committed
fix(isolated-declarations): remove the async and generator keywords from MethodDefinition (#4130)
close: #4120
1 parent 0b43310 commit cb1af04

File tree

5 files changed

+75
-18
lines changed

5 files changed

+75
-18
lines changed

crates/oxc_isolated_declarations/src/class.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ impl<'a> IsolatedDeclarations<'a> {
117117
FunctionType::TSEmptyBodyFunctionExpression,
118118
function.span,
119119
self.ast.copy(&function.id),
120-
function.generator,
121-
function.r#async,
120+
false,
121+
false,
122122
false,
123123
self.ast.copy(&function.type_parameters),
124124
self.ast.copy(&function.this_param),

crates/oxc_isolated_declarations/tests/fixtures/async-function.ts

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ const asyncFunctionGoo2 = async (): Promise<number> => {
55
}
66

77

8+
class AsyncClassGood {
9+
async method(): number {
10+
return 42;
11+
}
12+
}
13+
814
// Need to explicit return type for async functions
915
// Incorrect
1016
async function asyncFunction() {
@@ -13,4 +19,10 @@ async function asyncFunction() {
1319

1420
const asyncFunction2 = async () => {
1521
return "Hello, World!";
22+
}
23+
24+
class AsyncClassBad {
25+
async method() {
26+
return 42;
27+
}
1628
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
// Correct
22
function *generatorGood(): Generator<number> {}
33

4+
class GeneratorClassGood {
5+
*method(): Generator<number> {
6+
yield 50;
7+
return 42;
8+
}
9+
}
10+
11+
412

513
// Need to explicit return type for async functions
614
// Incorrect
7-
function *generatorGoodBad() {
15+
function *generatorBad() {
816
yield 50;
917
return 42;
18+
}
19+
20+
class GeneratorClassBad {
21+
*method() {
22+
yield 50;
23+
return 42;
24+
}
1025
}

crates/oxc_isolated_declarations/tests/snapshots/async-function.snap

+23-8
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,41 @@ input_file: crates/oxc_isolated_declarations/tests/fixtures/async-function.ts
66

77
declare function asyncFunctionGood(): Promise<number>;
88
declare const asyncFunctionGoo2: () => Promise<number>;
9+
declare class AsyncClassGood {
10+
method(): number;
11+
}
912
declare function asyncFunction();
1013
declare const asyncFunction2: unknown;
14+
declare class AsyncClassBad {
15+
method();
16+
}
1117

1218

1319
==================== Errors ====================
1420

1521
x TS9007: Function must have an explicit return type annotation with
1622
| --isolatedDeclarations.
17-
,-[10:16]
18-
9 | // Incorrect
19-
10 | async function asyncFunction() {
23+
,-[16:16]
24+
15 | // Incorrect
25+
16 | async function asyncFunction() {
2026
: ^^^^^^^^^^^^^
21-
11 | return 42;
27+
17 | return 42;
2228
`----
2329
2430
x TS9007: Function must have an explicit return type annotation with
2531
| --isolatedDeclarations.
26-
,-[14:30]
27-
13 |
28-
14 | const asyncFunction2 = async () => {
32+
,-[20:30]
33+
19 |
34+
20 | const asyncFunction2 = async () => {
2935
: ^^^^^^^
30-
15 | return "Hello, World!";
36+
21 | return "Hello, World!";
37+
`----
38+
39+
x TS9008: Method must have an explicit return type annotation with
40+
| --isolatedDeclarations.
41+
,-[25:9]
42+
24 | class AsyncClassBad {
43+
25 | async method() {
44+
: ^^^^^^
45+
26 | return 42;
3146
`----

crates/oxc_isolated_declarations/tests/snapshots/generator.snap

+22-7
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,31 @@ input_file: crates/oxc_isolated_declarations/tests/fixtures/generator.ts
55
==================== .D.TS ====================
66

77
declare function generatorGood(): Generator<number>;
8-
declare function generatorGoodBad();
8+
declare class GeneratorClassGood {
9+
method(): Generator<number>;
10+
}
11+
declare function generatorBad();
12+
declare class GeneratorClassBad {
13+
method();
14+
}
915

1016

1117
==================== Errors ====================
1218

1319
x TS9007: Function must have an explicit return type annotation with
1420
| --isolatedDeclarations.
15-
,-[7:11]
16-
6 | // Incorrect
17-
7 | function *generatorGoodBad() {
18-
: ^^^^^^^^^^^^^^^^
19-
8 | yield 50;
20-
`----
21+
,-[15:11]
22+
14 | // Incorrect
23+
15 | function *generatorBad() {
24+
: ^^^^^^^^^^^^
25+
16 | yield 50;
26+
`----
27+
28+
x TS9008: Method must have an explicit return type annotation with
29+
| --isolatedDeclarations.
30+
,-[21:4]
31+
20 | class GeneratorClassBad {
32+
21 | *method() {
33+
: ^^^^^^
34+
22 | yield 50;
35+
`----

0 commit comments

Comments
 (0)