mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(isolated-declarations): should stripe async and generator keyword after transformed (#3790)
This commit is contained in:
parent
dc8e2b8dc0
commit
7d47fc3fcc
6 changed files with 79 additions and 6 deletions
|
|
@ -26,8 +26,8 @@ impl<'a> IsolatedDeclarations<'a> {
|
|||
func.r#type,
|
||||
func.span,
|
||||
self.ast.copy(&func.id),
|
||||
func.generator,
|
||||
func.r#async,
|
||||
false,
|
||||
false,
|
||||
self.ast.copy(&func.this_param),
|
||||
params,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -120,10 +120,6 @@ impl<'a> IsolatedDeclarations<'a> {
|
|||
return None;
|
||||
}
|
||||
|
||||
if function.r#async {
|
||||
return None;
|
||||
}
|
||||
|
||||
if function.expression {
|
||||
if let Some(Statement::ExpressionStatement(stmt)) = function.body.statements.first() {
|
||||
return self
|
||||
|
|
|
|||
16
crates/oxc_isolated_declarations/tests/fixtures/async-function.ts
vendored
Normal file
16
crates/oxc_isolated_declarations/tests/fixtures/async-function.ts
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Correct
|
||||
async function asyncFunctionGood(): Promise<number> {}
|
||||
const asyncFunctionGoo2 = async (): Promise<number> => {
|
||||
return Promise.resolve(0);
|
||||
}
|
||||
|
||||
|
||||
// Need to explicit return type for async functions
|
||||
// Incorrect
|
||||
async function asyncFunction() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
const asyncFunction2 = async () => {
|
||||
return "Hello, World!";
|
||||
}
|
||||
10
crates/oxc_isolated_declarations/tests/fixtures/generator.ts
vendored
Normal file
10
crates/oxc_isolated_declarations/tests/fixtures/generator.ts
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// Correct
|
||||
function *generatorGood(): Generator<number> {}
|
||||
|
||||
|
||||
// Need to explicit return type for async functions
|
||||
// Incorrect
|
||||
function *generatorGoodBad() {
|
||||
yield 50;
|
||||
return 42;
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
source: crates/oxc_isolated_declarations/tests/mod.rs
|
||||
input_file: crates/oxc_isolated_declarations/tests/fixtures/async-function.ts
|
||||
---
|
||||
==================== .D.TS ====================
|
||||
|
||||
declare function asyncFunctionGood(): Promise<number>;
|
||||
declare const asyncFunctionGoo2: () => Promise<number>;
|
||||
declare function asyncFunction();
|
||||
declare const asyncFunction2: unknown;
|
||||
|
||||
|
||||
==================== Errors ====================
|
||||
|
||||
x TS9007: Function must have an explicit return type annotation with
|
||||
| --isolatedDeclarations.
|
||||
,-[10:16]
|
||||
9 | // Incorrect
|
||||
10 | async function asyncFunction() {
|
||||
: ^^^^^^^^^^^^^
|
||||
11 | return 42;
|
||||
`----
|
||||
|
||||
x TS9007: Function must have an explicit return type annotation with
|
||||
| --isolatedDeclarations.
|
||||
,-[14:30]
|
||||
13 |
|
||||
14 | const asyncFunction2 = async () => {
|
||||
: ^^^^^^^
|
||||
15 | return "Hello, World!";
|
||||
`----
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
source: crates/oxc_isolated_declarations/tests/mod.rs
|
||||
input_file: crates/oxc_isolated_declarations/tests/fixtures/generator.ts
|
||||
---
|
||||
==================== .D.TS ====================
|
||||
|
||||
declare function generatorGood(): Generator<number>;
|
||||
declare function generatorGoodBad();
|
||||
|
||||
|
||||
==================== Errors ====================
|
||||
|
||||
x TS9007: Function must have an explicit return type annotation with
|
||||
| --isolatedDeclarations.
|
||||
,-[7:11]
|
||||
6 | // Incorrect
|
||||
7 | function *generatorGoodBad() {
|
||||
: ^^^^^^^^^^^^^^^^
|
||||
8 | yield 50;
|
||||
`----
|
||||
Loading…
Reference in a new issue