mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(isolated-declarations): remove the async and generator keywords from MethodDefinition (#4130)
close: #4120
This commit is contained in:
parent
0b433108be
commit
cb1af043b8
5 changed files with 75 additions and 18 deletions
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
@ -13,4 +19,10 @@ async function asyncFunction() {
|
|||
|
||||
const asyncFunction2 = async () => {
|
||||
return "Hello, World!";
|
||||
}
|
||||
|
||||
class AsyncClassBad {
|
||||
async method() {
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
`----
|
||||
|
|
|
|||
|
|
@ -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…
Reference in a new issue