Skip to main content

Module module

Module module 

Source
Expand description

The module system: records, linking, namespaces, and evaluation.

The design follows §16.2 closely but leans on one thing this engine already has. A module’s top-level bindings compile as closure variables of the module body — ClosureType::ModuleDecl for its own declarations, ClosureType::ModuleImport for what it imports — so reading one is an ordinary get_var_ref. What makes modules interesting is then entirely a question of who fills the cells:

  • a declaration gets a fresh cell, created here;
  • an import gets the exporting module’s cell, not a copy.

Sharing the cell is what makes bindings live (export let x; x = 1 is visible to the importer) and what makes cyclic imports work: linking wires cells before anything evaluates, so a.js importing from a b.js that imports back from a.js resolves to cells on both sides without either body having run.

The three phases are the spec’s: load (read and compile), link (resolve imports, validate exports), evaluate (run bodies depth-first, once each).

Structs§

LoadedModule
A host-supplied module, before it is compiled.
ModuleInner
Everything a module record holds; see ModuleRecord.
ModuleRecord
One loaded module.

Enums§

ModuleKind
How a module’s source became a module.
ModuleStatus
Where a module is in its lifetime.

Traits§

ModuleLoader
How the host turns a specifier into bytes.