fluidattacks-blends-domain 0.6.1

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

use alloc::string::String;

use crate::syntax::builders::utils::{bound_import_symbol, register_symbol_in_scope};
use crate::syntax::SyntaxGraphArgs;
use crate::syntax::SyntaxNode;
use crate::NodeId;

pub fn build_import_module_node(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
    expression: String,
    alias: Option<String>,
) -> NodeId {
    let bound = bound_import_symbol(&expression, alias.as_deref());

    args.syntax_graph.add_node(
        n_id,
        SyntaxNode::ModuleImport {
            expression,
            alias: alias.filter(|value| !value.is_empty()),
        },
    );

    if !bound.is_empty() {
        register_symbol_in_scope(args.syntax_graph, args.metadata, bound, n_id);
    }

    n_id
}