mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
chore(ast): document ArrowExpression.expression
This commit is contained in:
parent
19b839efe9
commit
993c171547
4 changed files with 7 additions and 19 deletions
|
|
@ -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<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
pub return_type: Option<Box<'a, TSTypeAnnotation<'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"))]
|
||||
|
|
|
|||
|
|
@ -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"))]
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue