mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +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,
|
FunctionType::TSEmptyBodyFunctionExpression,
|
||||||
function.span,
|
function.span,
|
||||||
self.ast.copy(&function.id),
|
self.ast.copy(&function.id),
|
||||||
function.generator,
|
false,
|
||||||
function.r#async,
|
false,
|
||||||
false,
|
false,
|
||||||
self.ast.copy(&function.type_parameters),
|
self.ast.copy(&function.type_parameters),
|
||||||
self.ast.copy(&function.this_param),
|
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
|
// Need to explicit return type for async functions
|
||||||
// Incorrect
|
// Incorrect
|
||||||
async function asyncFunction() {
|
async function asyncFunction() {
|
||||||
|
|
@ -14,3 +20,9 @@ async function asyncFunction() {
|
||||||
const asyncFunction2 = async () => {
|
const asyncFunction2 = async () => {
|
||||||
return "Hello, World!";
|
return "Hello, World!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AsyncClassBad {
|
||||||
|
async method() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,25 @@
|
||||||
// Correct
|
// Correct
|
||||||
function *generatorGood(): Generator<number> {}
|
function *generatorGood(): Generator<number> {}
|
||||||
|
|
||||||
|
class GeneratorClassGood {
|
||||||
|
*method(): Generator<number> {
|
||||||
|
yield 50;
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Need to explicit return type for async functions
|
// Need to explicit return type for async functions
|
||||||
// Incorrect
|
// Incorrect
|
||||||
function *generatorGoodBad() {
|
function *generatorBad() {
|
||||||
yield 50;
|
yield 50;
|
||||||
return 42;
|
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 function asyncFunctionGood(): Promise<number>;
|
||||||
declare const asyncFunctionGoo2: () => Promise<number>;
|
declare const asyncFunctionGoo2: () => Promise<number>;
|
||||||
|
declare class AsyncClassGood {
|
||||||
|
method(): number;
|
||||||
|
}
|
||||||
declare function asyncFunction();
|
declare function asyncFunction();
|
||||||
declare const asyncFunction2: unknown;
|
declare const asyncFunction2: unknown;
|
||||||
|
declare class AsyncClassBad {
|
||||||
|
method();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
==================== Errors ====================
|
==================== Errors ====================
|
||||||
|
|
||||||
x TS9007: Function must have an explicit return type annotation with
|
x TS9007: Function must have an explicit return type annotation with
|
||||||
| --isolatedDeclarations.
|
| --isolatedDeclarations.
|
||||||
,-[10:16]
|
,-[16:16]
|
||||||
9 | // Incorrect
|
15 | // Incorrect
|
||||||
10 | async function asyncFunction() {
|
16 | async function asyncFunction() {
|
||||||
: ^^^^^^^^^^^^^
|
: ^^^^^^^^^^^^^
|
||||||
11 | return 42;
|
17 | return 42;
|
||||||
`----
|
`----
|
||||||
|
|
||||||
x TS9007: Function must have an explicit return type annotation with
|
x TS9007: Function must have an explicit return type annotation with
|
||||||
| --isolatedDeclarations.
|
| --isolatedDeclarations.
|
||||||
,-[14:30]
|
,-[20:30]
|
||||||
13 |
|
19 |
|
||||||
14 | const asyncFunction2 = async () => {
|
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 ====================
|
==================== .D.TS ====================
|
||||||
|
|
||||||
declare function generatorGood(): Generator<number>;
|
declare function generatorGood(): Generator<number>;
|
||||||
declare function generatorGoodBad();
|
declare class GeneratorClassGood {
|
||||||
|
method(): Generator<number>;
|
||||||
|
}
|
||||||
|
declare function generatorBad();
|
||||||
|
declare class GeneratorClassBad {
|
||||||
|
method();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
==================== Errors ====================
|
==================== Errors ====================
|
||||||
|
|
||||||
x TS9007: Function must have an explicit return type annotation with
|
x TS9007: Function must have an explicit return type annotation with
|
||||||
| --isolatedDeclarations.
|
| --isolatedDeclarations.
|
||||||
,-[7:11]
|
,-[15:11]
|
||||||
6 | // Incorrect
|
14 | // Incorrect
|
||||||
7 | function *generatorGoodBad() {
|
15 | function *generatorBad() {
|
||||||
: ^^^^^^^^^^^^^^^^
|
: ^^^^^^^^^^^^
|
||||||
8 | yield 50;
|
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