use crate::{
query::{label_text, match_ast_d},
syntax::{
builders::import_statement::{build_import_node, ImportElement},
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 expression = match_ast_d(graph, n_id, "name", None)
.and_then(|exp_n_id| label_text(graph, exp_n_id))
.filter(|s| !s.is_empty())
.map_or_else(|| node_to_str(graph, n_id), str::to_owned);
build_import_node(
args,
n_id,
&ImportElement {
expression: Some(expression),
..ImportElement::default()
},
)
.map(Some)
}