Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(isolated-declarations): should stripe async and generator keyword after transformed #3790

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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;
`----
Loading