use super::{join_nodes, Node};
use boa_interner::{Interner, ToInternedString};
#[cfg(feature = "deser")]
use serde::{Deserialize, Serialize};
#[cfg(test)]
mod tests;
#[cfg_attr(feature = "deser", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct ArrayDecl {
arr: Box<[Node]>,
has_trailing_comma_spread: bool,
}
impl ArrayDecl {
pub(crate) fn new<A>(array: A, has_trailing_comma_spread: bool) -> Self
where
A: Into<Box<[Node]>>,
{
Self {
arr: array.into(),
has_trailing_comma_spread,
}
}
pub(crate) fn has_trailing_comma_spread(&self) -> bool {
self.has_trailing_comma_spread
}
}
impl AsRef<[Node]> for ArrayDecl {
fn as_ref(&self) -> &[Node] {
&self.arr
}
}
impl<T> From<T> for ArrayDecl
where
T: Into<Box<[Node]>>,
{
fn from(decl: T) -> Self {
Self {
arr: decl.into(),
has_trailing_comma_spread: false,
}
}
}
impl ToInternedString for ArrayDecl {
fn to_interned_string(&self, interner: &Interner) -> String {
format!("[{}]", join_nodes(interner, &self.arr))
}
}
impl From<ArrayDecl> for Node {
fn from(arr: ArrayDecl) -> Self {
Self::ArrayDecl(arr)
}
}