Skip to content

Commit

Permalink
fix(isolated-declarations): should stripe async and generator keyword…
Browse files Browse the repository at this point in the history
… after transformed
  • Loading branch information
Dunqing committed Jun 20, 2024
1 parent 0f89748 commit 07fb853
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/oxc_isolated_declarations/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions crates/oxc_isolated_declarations/src/inferrer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions crates/oxc_isolated_declarations/tests/fixtures/async-function.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions crates/oxc_isolated_declarations/tests/fixtures/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Correct
function *generatorGood(): Generator<number> {}


// Need to explicit return type for async functions
// Incorrect
function *generatorGoodBad() {
yield 50;
return 42;
}
Original file line number Diff line number Diff line change
@@ -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!";
`----
20 changes: 20 additions & 0 deletions crates/oxc_isolated_declarations/tests/snapshots/generator.snap
Original file line number Diff line number Diff line change
@@ -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;
`----

0 comments on commit 07fb853

Please sign in to comment.