fluidattacks-blends-domain 0.3.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
//! Counterpart of `blends/syntax/builders/export_statement.py` (the
//! `StackGraph` default-export pop wiring is excluded: the migration covers
//! only AST, Syntax and CFG).

use alloc::string::String;

use crate::syntax::builders::import_module::build_import_module_node;
use crate::syntax::SyntaxNode;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::NodeId;

#[allow(
    dead_code,
    reason = "wired when a consuming language reader lands, #26623"
)]
#[allow(
    clippy::too_many_arguments,
    reason = "mirrors the Python build_export_statement_node inputs"
)]
pub fn build_export_statement_node(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
    expression: Option<String>,
    exported_block: Option<NodeId>,
    reexport_specifiers: &[(NodeId, String, Option<String>)],
    default_export: Option<NodeId>,
) -> Result<NodeId, SyntaxGraphError> {
    args.syntax_graph.add_node(
        n_id,
        SyntaxNode::Export {
            expression: expression.filter(|value| !value.is_empty()),
            declaration_id: exported_block,
        },
    );

    if let Some(exported_block) = exported_block {
        let built = args.generic(exported_block)?;
        args.syntax_graph.add_ast_edge(n_id, built);
    }

    for (spec_n_id, spec_expression, spec_alias) in reexport_specifiers {
        build_import_module_node(
            args,
            *spec_n_id,
            spec_expression.clone(),
            spec_alias.clone(),
        );
    }

    if let Some(default_keyword_nid) = default_export {
        args.syntax_graph
            .add_node(default_keyword_nid, SyntaxNode::Default);
    }

    Ok(n_id)
}