use crate::ns::*; use serde::{Serialize, Deserialize}; use std::rc::Rc; #[derive(Clone, Serialize, Deserialize)] pub struct VariableDefinition { pub location: Location, pub jetdoc: Option>, pub attributes: Vec, pub kind: (VariableDefinitionKind, Location), pub bindings: Vec>, } #[derive(Copy, Clone, Serialize, Deserialize, PartialEq, Eq)] pub enum VariableDefinitionKind { Var, Const, } #[derive(Clone, Serialize, Deserialize)] pub struct SimpleVariableDefinition { pub location: Location, pub kind: (VariableDefinitionKind, Location), pub bindings: Vec>, } #[derive(Clone, Serialize, Deserialize)] pub struct VariableBinding { pub destructuring: TypedDestructuring, pub initializer: Option>, } impl VariableBinding { pub fn location(&self) -> Location { self.initializer.as_ref().map_or(self.destructuring.location.clone(), |init| self.destructuring.location.combine_with(init.location())) } }