boa_ast/expression/
await.rs1use core::ops::ControlFlow;
4
5use super::Expression;
6use crate::{
7 Span, Spanned,
8 visitor::{VisitWith, Visitor, VisitorMut},
9};
10use boa_interner::{Interner, ToIndentedString, ToInternedString};
11
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
22#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
23#[derive(Clone, Debug, PartialEq)]
24pub struct Await {
25 target: Box<Expression>,
26 span: Span,
27}
28
29impl Await {
30 #[must_use]
32 pub const fn new(target: Box<Expression>, span: Span) -> Self {
33 Self { target, span }
34 }
35
36 #[inline]
38 #[must_use]
39 pub const fn target(&self) -> &Expression {
40 &self.target
41 }
42}
43
44impl Spanned for Await {
45 #[inline]
46 fn span(&self) -> Span {
47 self.span
48 }
49}
50
51impl ToInternedString for Await {
52 #[inline]
53 fn to_interned_string(&self, interner: &Interner) -> String {
54 format!("await {}", self.target.to_indented_string(interner, 0))
55 }
56}
57
58impl From<Await> for Expression {
59 #[inline]
60 fn from(awaitexpr: Await) -> Self {
61 Self::Await(awaitexpr)
62 }
63}
64
65impl VisitWith for Await {
66 fn visit_with<'a, V>(&'a self, visitor: &mut V) -> ControlFlow<V::BreakTy>
67 where
68 V: Visitor<'a>,
69 {
70 visitor.visit_expression(&self.target)
71 }
72
73 fn visit_with_mut<'a, V>(&'a mut self, visitor: &mut V) -> ControlFlow<V::BreakTy>
74 where
75 V: VisitorMut<'a>,
76 {
77 visitor.visit_expression_mut(&mut self.target)
78 }
79}