mod arrow_function;
mod async_arrow_function;
mod async_function;
mod async_generator;
mod class;
mod generator;
mod ordinary_function;
mod parameters;
use std::ops::ControlFlow;
pub use arrow_function::ArrowFunction;
pub use async_arrow_function::AsyncArrowFunction;
pub use async_function::{AsyncFunctionDeclaration, AsyncFunctionExpression};
pub use async_generator::{AsyncGeneratorDeclaration, AsyncGeneratorExpression};
use boa_interner::{Interner, ToIndentedString};
pub use class::{
ClassDeclaration, ClassElement, ClassElementName, ClassExpression, ClassFieldDefinition,
ClassMethodDefinition, PrivateFieldDefinition, PrivateName, StaticBlockBody,
};
pub use generator::{GeneratorDeclaration, GeneratorExpression};
pub use ordinary_function::{FunctionDeclaration, FunctionExpression};
pub use parameters::{FormalParameter, FormalParameterList, FormalParameterListFlags};
use crate::{
LinearPosition, Span, Spanned, StatementList, StatementListItem,
visitor::{VisitWith, Visitor, VisitorMut},
};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Clone, Debug, PartialEq)]
pub struct FunctionBody {
pub(crate) statements: StatementList,
span: Span,
}
impl FunctionBody {
#[inline]
#[must_use]
pub fn new(statements: StatementList, span: Span) -> Self {
Self { statements, span }
}
#[inline]
#[must_use]
pub const fn statements(&self) -> &[StatementListItem] {
self.statements.statements()
}
#[inline]
#[must_use]
pub const fn statement_list(&self) -> &StatementList {
&self.statements
}
#[inline]
#[must_use]
pub const fn strict(&self) -> bool {
self.statements.strict()
}
#[inline]
#[must_use]
pub const fn linear_pos_end(&self) -> LinearPosition {
self.statements.linear_pos_end()
}
}
impl Spanned for FunctionBody {
#[inline]
fn span(&self) -> Span {
self.span
}
}
impl ToIndentedString for FunctionBody {
fn to_indented_string(&self, interner: &Interner, indentation: usize) -> String {
self.statements.to_indented_string(interner, indentation)
}
}
impl VisitWith for FunctionBody {
fn visit_with<'a, V>(&'a self, visitor: &mut V) -> ControlFlow<V::BreakTy>
where
V: Visitor<'a>,
{
for statement in &*self.statements {
visitor.visit_statement_list_item(statement)?;
}
ControlFlow::Continue(())
}
fn visit_with_mut<'a, V>(&'a mut self, visitor: &mut V) -> ControlFlow<V::BreakTy>
where
V: VisitorMut<'a>,
{
for statement in &mut *self.statements.statements {
visitor.visit_statement_list_item_mut(statement)?;
}
ControlFlow::Continue(())
}
}