Skip to main content

implicit_esm_imports_for

Function implicit_esm_imports_for 

Source
pub fn implicit_esm_imports_for(
    module: &AIRModule,
    public_symbols: &HashMap<String, EsmSymbol>,
    own_path: &str,
) -> Vec<ImplicitEsmImport>
Expand description

Compute the implicit cross-module imports for module: public symbols declared in other reachable modules that module references but neither declares locally nor imports explicitly.

“References” is a conservative structural scan of the module’s debug rendering for the symbol name as a quoted identifier token. It can only over-import a name the program does not really use (a harmless dead import), never under-import — so it cannot reintroduce the unresolved reference it exists to fix.

An enum variant needs a second probe. Its map key is the emitted value-name (Category_Electronics), but a glob-imported (use models.*) variant is referenced in AIR by its bare source name (Identifier { name: "Electronics" }) — the Enum_Variant joining happens only at emit time. So for a variant we also scan for the bare source name (EsmSymbol::variant_bare_name) and, on a match, import the symbol under its emitted key (the identifier the backends actually emit and need bound). Without this the per-module JS/TS file omits the variant import and ReferenceErrors / TS2304s at every bare-variant use site.