use crate::query::{adj_ast, match_ast};
use crate::syntax::builders::spread_element::build_spread_element_node;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::NodeId;
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let graph = args.ast_graph;
let identifier_id = if let Some(id) = match_ast(graph, n_id, &["..."], None)
.get("__0__")
.copied()
.flatten()
{
id
} else {
let c_ids = adj_ast(graph, n_id, None, &[]);
*c_ids.first().ok_or(SyntaxGraphError::UnexpectedAstShape)?
};
build_spread_element_node(args, n_id, identifier_id).map(Some)
}