1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use super::{Node, StatementList};
use boa_gc::{Finalize, Trace};
use boa_interner::{Interner, Sym, ToInternedString};
use rustc_hash::FxHashSet;
#[cfg(feature = "deser")]
use serde::{Deserialize, Serialize};
#[cfg(test)]
mod tests;
#[cfg_attr(feature = "deser", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "deser", serde(transparent))]
#[derive(Clone, Debug, Trace, Finalize, PartialEq)]
pub struct Block {
#[cfg_attr(feature = "deser", serde(flatten))]
statements: StatementList,
}
impl Block {
pub(crate) fn items(&self) -> &[Node] {
self.statements.items()
}
pub(crate) fn lexically_declared_names(&self, interner: &Interner) -> FxHashSet<Sym> {
self.statements.lexically_declared_names(interner)
}
pub(crate) fn var_declared_named(&self) -> FxHashSet<Sym> {
self.statements.var_declared_names()
}
pub(super) fn to_indented_string(&self, interner: &Interner, indentation: usize) -> String {
format!(
"{{\n{}{}}}",
self.statements
.to_indented_string(interner, indentation + 1),
" ".repeat(indentation)
)
}
}
impl<T> From<T> for Block
where
T: Into<StatementList>,
{
fn from(list: T) -> Self {
Self {
statements: list.into(),
}
}
}
impl ToInternedString for Block {
fn to_interned_string(&self, interner: &Interner) -> String {
self.to_indented_string(interner, 0)
}
}
impl From<Block> for Node {
fn from(block: Block) -> Self {
Self::Block(block)
}
}