diff --git a/crates/oxc_isolated_declarations/src/class.rs b/crates/oxc_isolated_declarations/src/class.rs index 5dfab8a13..d16b35439 100644 --- a/crates/oxc_isolated_declarations/src/class.rs +++ b/crates/oxc_isolated_declarations/src/class.rs @@ -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), diff --git a/crates/oxc_isolated_declarations/tests/fixtures/async-function.ts b/crates/oxc_isolated_declarations/tests/fixtures/async-function.ts index 3927f10d1..b1a8d9a6a 100644 --- a/crates/oxc_isolated_declarations/tests/fixtures/async-function.ts +++ b/crates/oxc_isolated_declarations/tests/fixtures/async-function.ts @@ -5,6 +5,12 @@ const asyncFunctionGoo2 = async (): Promise => { } +class AsyncClassGood { + async method(): number { + return 42; + } +} + // Need to explicit return type for async functions // Incorrect async function asyncFunction() { @@ -13,4 +19,10 @@ async function asyncFunction() { const asyncFunction2 = async () => { return "Hello, World!"; +} + +class AsyncClassBad { + async method() { + return 42; + } } \ No newline at end of file diff --git a/crates/oxc_isolated_declarations/tests/fixtures/generator.ts b/crates/oxc_isolated_declarations/tests/fixtures/generator.ts index c09739a26..2666ea029 100644 --- a/crates/oxc_isolated_declarations/tests/fixtures/generator.ts +++ b/crates/oxc_isolated_declarations/tests/fixtures/generator.ts @@ -1,10 +1,25 @@ // Correct function *generatorGood(): Generator {} +class GeneratorClassGood { + *method(): Generator { + 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; + } } \ No newline at end of file diff --git a/crates/oxc_isolated_declarations/tests/snapshots/async-function.snap b/crates/oxc_isolated_declarations/tests/snapshots/async-function.snap index 3af230361..7e275fdae 100644 --- a/crates/oxc_isolated_declarations/tests/snapshots/async-function.snap +++ b/crates/oxc_isolated_declarations/tests/snapshots/async-function.snap @@ -6,26 +6,41 @@ input_file: crates/oxc_isolated_declarations/tests/fixtures/async-function.ts declare function asyncFunctionGood(): Promise; declare const asyncFunctionGoo2: () => Promise; +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; `---- diff --git a/crates/oxc_isolated_declarations/tests/snapshots/generator.snap b/crates/oxc_isolated_declarations/tests/snapshots/generator.snap index b72acbc6c..8a0dd9ed5 100644 --- a/crates/oxc_isolated_declarations/tests/snapshots/generator.snap +++ b/crates/oxc_isolated_declarations/tests/snapshots/generator.snap @@ -5,16 +5,31 @@ input_file: crates/oxc_isolated_declarations/tests/fixtures/generator.ts ==================== .D.TS ==================== declare function generatorGood(): Generator; -declare function generatorGoodBad(); +declare class GeneratorClassGood { + method(): Generator; +} +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; + `----