chore(ast): document ArrowExpression.expression

This commit is contained in:
Boshen 2023-06-20 21:52:56 +08:00
parent 19b839efe9
commit 993c171547
No known key found for this signature in database
GPG key ID: 9C7A8C8AB22BEBD1
4 changed files with 7 additions and 19 deletions

View file

@ -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"))]

View file

@ -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"))]

View file

@ -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 {

View file

@ -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);