use crate::syntax::ast::node::Node;
use boa_interner::{Interner, ToInternedString};
#[cfg(feature = "deser")]
use serde::{Deserialize, Serialize};
#[cfg_attr(feature = "deser", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct GetField {
obj: Box<Node>,
field: Box<Node>,
}
impl GetField {
pub fn obj(&self) -> &Node {
&self.obj
}
pub fn field(&self) -> &Node {
&self.field
}
pub fn new<V, F>(value: V, field: F) -> Self
where
V: Into<Node>,
F: Into<Node>,
{
Self {
obj: Box::new(value.into()),
field: Box::new(field.into()),
}
}
}
impl ToInternedString for GetField {
fn to_interned_string(&self, interner: &Interner) -> String {
format!(
"{}[{}]",
self.obj.to_interned_string(interner),
self.field.to_interned_string(interner)
)
}
}
impl From<GetField> for Node {
fn from(get_field: GetField) -> Self {
Self::GetField(get_field)
}
}