diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 78723a045..bc369bc62 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -1387,24 +1387,18 @@ impl<'a> FunctionBody<'a> { #[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))] pub struct ArrowExpression<'a> { pub span: Span, + /// Is the function body an arrow expression? i.e. `() => expr` instead of `() => {}` pub expression: bool, pub generator: bool, pub r#async: bool, - pub params: Box<'a, FormalParameters<'a>>, // UniqueFormalParameters in spec + pub params: Box<'a, FormalParameters<'a>>, + /// See `expression` for whether this arrow expression returns an expression. pub body: Box<'a, FunctionBody<'a>>, pub type_parameters: Option>>, pub return_type: Option>>, } -impl<'a> ArrowExpression<'a> { - /// Is of form () => x without curly braces. - #[inline] - pub fn is_single_expression(&self) -> bool { - self.expression - } -} - /// Generator Function Definitions #[derive(Debug, Hash)] #[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] diff --git a/crates/oxc_hir/src/hir.rs b/crates/oxc_hir/src/hir.rs index 1b857e56d..5893cf282 100644 --- a/crates/oxc_hir/src/hir.rs +++ b/crates/oxc_hir/src/hir.rs @@ -1494,21 +1494,15 @@ impl<'a> FunctionBody<'a> { #[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))] pub struct ArrowExpression<'a> { pub span: Span, + /// Is the function body an arrow expression? i.e. `() => expr` instead of `() => {}` pub expression: bool, pub generator: bool, pub r#async: bool, pub params: Box<'a, FormalParameters<'a>>, // UniqueFormalParameters in spec + /// See `expression` for whether this arrow expression returns an expression. pub body: Box<'a, FunctionBody<'a>>, } -impl<'a> ArrowExpression<'a> { - /// Is of form () => x without curly braces. - #[inline] - pub fn is_single_expression(&self) -> bool { - self.expression - } -} - /// Generator Function Definitions #[derive(Debug, Hash)] #[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] diff --git a/crates/oxc_linter/src/rules/array_callback_return/mod.rs b/crates/oxc_linter/src/rules/array_callback_return/mod.rs index 35565d899..1f8ebed4a 100644 --- a/crates/oxc_linter/src/rules/array_callback_return/mod.rs +++ b/crates/oxc_linter/src/rules/array_callback_return/mod.rs @@ -86,7 +86,7 @@ impl Rule for ArrayCallbackReturn { // Async, generator, and single expression arrow functions // always have explicit return value AstKind::ArrowExpression(arrow) => { - (&arrow.body, arrow.r#async || arrow.generator || arrow.is_single_expression()) + (&arrow.body, arrow.r#async || arrow.generator || arrow.expression) } AstKind::Function(function) => { if let Some(body) = &function.body { diff --git a/crates/oxc_linter/src/rules/getter_return.rs b/crates/oxc_linter/src/rules/getter_return.rs index 57ebe341b..cd5e78b10 100644 --- a/crates/oxc_linter/src/rules/getter_return.rs +++ b/crates/oxc_linter/src/rules/getter_return.rs @@ -71,7 +71,7 @@ impl GetterReturn { return Some(span); } } - Expression::ArrowExpression(arrow) if !arrow.is_single_expression() => { + Expression::ArrowExpression(arrow) if !arrow.expression => { if !self.is_correct_getter(&arrow.body) { let span = Span::new(property.key.span().start, arrow.params.span.start); return Some(span);