boa_ast/statement/iteration/
continue.rs1use crate::statement::Statement;
2use crate::visitor::{VisitWith, Visitor, VisitorMut};
3use boa_interner::{Interner, Sym, ToInternedString};
4use core::ops::ControlFlow;
5
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
20#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
21#[derive(Clone, Copy, Debug, PartialEq, Eq)]
22pub struct Continue {
23 label: Option<Sym>,
24}
25
26impl Continue {
27 #[must_use]
29 pub const fn new(label: Option<Sym>) -> Self {
30 Self { label }
31 }
32
33 #[must_use]
35 pub const fn label(&self) -> Option<Sym> {
36 self.label
37 }
38}
39
40impl ToInternedString for Continue {
41 fn to_interned_string(&self, interner: &Interner) -> String {
42 self.label.map_or_else(
43 || "continue".to_owned(),
44 |label| format!("continue {}", interner.resolve_expect(label)),
45 )
46 }
47}
48
49impl From<Continue> for Statement {
50 fn from(cont: Continue) -> Self {
51 Self::Continue(cont)
52 }
53}
54
55impl VisitWith for Continue {
56 fn visit_with<'a, V>(&'a self, visitor: &mut V) -> ControlFlow<V::BreakTy>
57 where
58 V: Visitor<'a>,
59 {
60 if let Some(sym) = &self.label {
61 visitor.visit_sym(sym)
62 } else {
63 ControlFlow::Continue(())
64 }
65 }
66
67 fn visit_with_mut<'a, V>(&'a mut self, visitor: &mut V) -> ControlFlow<V::BreakTy>
68 where
69 V: VisitorMut<'a>,
70 {
71 if let Some(sym) = &mut self.label {
72 visitor.visit_sym_mut(sym)
73 } else {
74 ControlFlow::Continue(())
75 }
76 }
77}