use crate::{
query::{adj_ast, get_node_by_path, label_text},
syntax::{
builders::variable_declaration::build_variable_declaration_node, SyntaxGraphArgs,
SyntaxGraphError,
},
utilities::text_nodes::node_to_str,
NodeId,
};
use alloc::borrow::ToOwned;
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let graph = args.ast_graph;
let var_name = get_node_by_path(graph, n_id, &["property_element", "variable_name", "name"])
.map_or_else(
|| node_to_str(graph, n_id),
|name_n_id| label_text(graph, name_n_id).unwrap_or("").to_owned(),
);
let val_id = get_node_by_path(graph, n_id, &["property_element", "property_initializer"])
.and_then(|val_p_id| adj_ast(graph, val_p_id, Some(1), &[]).get(1).copied());
build_variable_declaration_node(args, n_id, var_name, None, val_id, None, None).map(Some)
}