Skip to content

Commit

Permalink
feat(isolated-declarations): shrink span for arrow function that need…
Browse files Browse the repository at this point in the history
…s an explicit return type
  • Loading branch information
Dunqing committed Jun 19, 2024
1 parent 6e24ed7 commit fe8515b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crates/oxc_isolated_declarations/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use oxc_ast::ast::{
TSTypeOperatorOperator,
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_span::{GetSpan, SPAN};
use oxc_span::{GetSpan, Span, SPAN};

use crate::{
diagnostics::{
Expand Down Expand Up @@ -41,7 +41,10 @@ impl<'a> IsolatedDeclarations<'a> {
let return_type = self.infer_arrow_function_return_type(func);

if return_type.is_none() {
self.error(function_must_have_explicit_return_type(func.span));
self.error(function_must_have_explicit_return_type(Span::new(
func.params.span.start,
func.body.span.start + 1,
)));
}

let params = self.transform_formal_parameters(&func.params);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function A() {
return () => {
return C;
}
}

const B = () => { return B };

const C = function () {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/arrow-function-return-type.ts
---
==================== .D.TS ====================

declare function A(): unknown;
declare const B: unknown;
declare const C: unknown;


==================== Errors ====================

x Function must have an explicit return type annotation with
| --isolatedDeclarations.
,-[2:10]
1 | function A() {
2 | return () => {
: ^^^^^^^
3 | return C;
`----
x Function must have an explicit return type annotation with
| --isolatedDeclarations.
,-[7:11]
6 |
7 | const B = () => { return B };
: ^^^^^^^
8 |
`----

x Function must have an explicit return type annotation with
| --isolatedDeclarations.
,-[9:20]
8 |
9 | const C = function () {}
: ^
`----

0 comments on commit fe8515b

Please sign in to comment.