fluidattacks-blends-domain 0.6.1

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::query::pred_ast;
use crate::syntax::builders::parameter::build_parameter_node;
use crate::syntax::builders::symbol_lookup::build_symbol_lookup_node;
use crate::syntax::builders::variable_declaration::build_variable_declaration_node;
use crate::syntax::fields::javascript::arrow_function;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::utilities::text_nodes::node_to_str;
use crate::{CodeGraph, NodeId};

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let graph = args.ast_graph;
    let parent_id = *pred_ast(graph, n_id, None)
        .first()
        .ok_or(SyntaxGraphError::UnexpectedAstShape)?;
    let symbol = node_to_str(graph, n_id);
    match graph.label_type(parent_id) {
        Some("formal_parameters") => {
            build_parameter_node(args, n_id, Some(symbol), None, None, &[], None, None).map(Some)
        }
        Some("arrow_function")
            if args.optional_field_alt(parent_id, arrow_function::PARAMETER) == Some(n_id) =>
        {
            build_parameter_node(args, n_id, Some(symbol), None, None, &[], None, None).map(Some)
        }
        Some("object_pattern")
            if pred_ast(graph, parent_id, None)
                .first()
                .is_some_and(|gp_id| graph.label_type(*gp_id) == Some("variable_declarator")) =>
        {
            build_variable_declaration_node(args, n_id, symbol, None, None, None, None).map(Some)
        }
        _ => Ok(Some(build_symbol_lookup_node(args, n_id, symbol))),
    }
}