fluidattacks-blends-domain 0.5.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::query::match_ast;
use crate::syntax::builders::do_statement::build_do_statement_node;
use crate::syntax::fields::javascript::do_statement;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::{CodeGraph, NodeId};

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let graph = args.ast_graph;
    let mut body_id = args.required_field_alt(n_id, do_statement::BODY)?;

    if graph.label_type(body_id) == Some("expression_statement") {
        if let Some(inner_id) = match_ast(graph, body_id, &[], None)
            .get("__0__")
            .copied()
            .flatten()
        {
            body_id = inner_id;
        }
    }

    let condition_id = args.required_field_alt(n_id, do_statement::CONDITION)?;

    build_do_statement_node(args, n_id, body_id, condition_id).map(Some)
}