use crate::{
Expression,
statement::Statement,
visitor::{VisitWith, Visitor, VisitorMut},
};
use boa_interner::{Interner, ToInternedString};
use core::ops::ControlFlow;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Clone, Debug, PartialEq)]
pub struct Throw {
target: Expression,
}
impl Throw {
#[must_use]
pub const fn target(&self) -> &Expression {
&self.target
}
#[must_use]
pub const fn new(target: Expression) -> Self {
Self { target }
}
}
impl ToInternedString for Throw {
fn to_interned_string(&self, interner: &Interner) -> String {
format!("throw {}", self.target.to_interned_string(interner))
}
}
impl From<Throw> for Statement {
fn from(trw: Throw) -> Self {
Self::Throw(trw)
}
}
impl VisitWith for Throw {
fn visit_with<'a, V>(&'a self, visitor: &mut V) -> ControlFlow<V::BreakTy>
where
V: Visitor<'a>,
{
visitor.visit_expression(&self.target)
}
fn visit_with_mut<'a, V>(&'a mut self, visitor: &mut V) -> ControlFlow<V::BreakTy>
where
V: VisitorMut<'a>,
{
visitor.visit_expression_mut(&mut self.target)
}
}