fluidattacks-blends-domain 0.4.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use alloc::vec::Vec;

use crate::query::adj_ast;
use crate::syntax::builders::object::build_object_node;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::{CodeGraph, NodeId};

const VALID_PARAMETERS: &[&str] = &[
    "method_definition",
    "pair",
    "property_signature",
    "shorthand_property_identifier",
    "shorthand_property_identifier_pattern",
    "spread_element",
];

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let graph = args.ast_graph;
    let c_ids: Vec<NodeId> = adj_ast(graph, n_id, None, &[])
        .into_iter()
        .filter(|c_id| {
            graph
                .label_type(*c_id)
                .is_some_and(|label| VALID_PARAMETERS.contains(&label))
        })
        .collect();
    build_object_node(args, n_id, &c_ids, None, None).map(Some)
}