use crate::{
query::adj_ast,
syntax::{
builders::switch_section::build_switch_section_node, SyntaxGraphArgs, SyntaxGraphError,
},
CodeGraph, NodeId,
};
use alloc::borrow::ToOwned;
use alloc::vec::Vec;
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let graph = args.ast_graph;
let mut execution_ids = Vec::new();
for &id in adj_ast(graph, n_id, Some(1), &[]).iter().skip(2) {
if graph.label_type(id) == Some("expression_statement") {
if let Some(&first) = adj_ast(graph, id, Some(1), &[]).first() {
execution_ids.push(first);
continue;
}
}
execution_ids.push(id);
}
build_switch_section_node(args, n_id, "Default".to_owned(), &execution_ids).map(Some)
}