Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(isolated-declarations): remove the async and generator keywords from MethodDefinition #4130

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/oxc_isolated_declarations/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ impl<'a> IsolatedDeclarations<'a> {
FunctionType::TSEmptyBodyFunctionExpression,
function.span,
self.ast.copy(&function.id),
function.generator,
function.r#async,
false,
false,
false,
self.ast.copy(&function.type_parameters),
self.ast.copy(&function.this_param),
Expand Down
12 changes: 12 additions & 0 deletions crates/oxc_isolated_declarations/tests/fixtures/async-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const asyncFunctionGoo2 = async (): Promise<number> => {
}


class AsyncClassGood {
async method(): number {
return 42;
}
}

// Need to explicit return type for async functions
// Incorrect
async function asyncFunction() {
Expand All @@ -13,4 +19,10 @@ async function asyncFunction() {

const asyncFunction2 = async () => {
return "Hello, World!";
}

class AsyncClassBad {
async method() {
return 42;
}
}
17 changes: 16 additions & 1 deletion crates/oxc_isolated_declarations/tests/fixtures/generator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
// Correct
function *generatorGood(): Generator<number> {}

class GeneratorClassGood {
*method(): Generator<number> {
yield 50;
return 42;
}
}



// Need to explicit return type for async functions
// Incorrect
function *generatorGoodBad() {
function *generatorBad() {
yield 50;
return 42;
}

class GeneratorClassBad {
*method() {
yield 50;
return 42;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,41 @@ input_file: crates/oxc_isolated_declarations/tests/fixtures/async-function.ts

declare function asyncFunctionGood(): Promise<number>;
declare const asyncFunctionGoo2: () => Promise<number>;
declare class AsyncClassGood {
method(): number;
}
declare function asyncFunction();
declare const asyncFunction2: unknown;
declare class AsyncClassBad {
method();
}


==================== Errors ====================

x TS9007: Function must have an explicit return type annotation with
| --isolatedDeclarations.
,-[10:16]
9 | // Incorrect
10 | async function asyncFunction() {
,-[16:16]
15 | // Incorrect
16 | async function asyncFunction() {
: ^^^^^^^^^^^^^
11 | return 42;
17 | return 42;
`----

x TS9007: Function must have an explicit return type annotation with
| --isolatedDeclarations.
,-[14:30]
13 |
14 | const asyncFunction2 = async () => {
,-[20:30]
19 |
20 | const asyncFunction2 = async () => {
: ^^^^^^^
15 | return "Hello, World!";
21 | return "Hello, World!";
`----

x TS9008: Method must have an explicit return type annotation with
| --isolatedDeclarations.
,-[25:9]
24 | class AsyncClassBad {
25 | async method() {
: ^^^^^^
26 | return 42;
`----
29 changes: 22 additions & 7 deletions crates/oxc_isolated_declarations/tests/snapshots/generator.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,31 @@ input_file: crates/oxc_isolated_declarations/tests/fixtures/generator.ts
==================== .D.TS ====================

declare function generatorGood(): Generator<number>;
declare function generatorGoodBad();
declare class GeneratorClassGood {
method(): Generator<number>;
}
declare function generatorBad();
declare class GeneratorClassBad {
method();
}


==================== Errors ====================

x TS9007: Function must have an explicit return type annotation with
| --isolatedDeclarations.
,-[7:11]
6 | // Incorrect
7 | function *generatorGoodBad() {
: ^^^^^^^^^^^^^^^^
8 | yield 50;
`----
,-[15:11]
14 | // Incorrect
15 | function *generatorBad() {
: ^^^^^^^^^^^^
16 | yield 50;
`----

x TS9008: Method must have an explicit return type annotation with
| --isolatedDeclarations.
,-[21:4]
20 | class GeneratorClassBad {
21 | *method() {
: ^^^^^^
22 | yield 50;
`----
Loading