Skip to main content

merged_unit_helpers

Function merged_unit_helpers 

Source
pub fn merged_unit_helpers(
    name: &str,
    indices: &[usize],
    parsed: &[ParsedFile],
    barrel_loc: &Path,
    import_ext: ImportExt,
    module_of: impl Fn(&Path) -> PathBuf,
    surface: bool,
) -> (Vec<TsStmt>, Vec<String>)
Expand description

#1844 review: the barrel’s own definitions of the helpers every file of a multi-file context generates for itself. User names are unique across a unit, but these are not: each file with agents exports __resetAgents (over its own agents), and each file with services exports __makeSurface and the context’s __<Ctx>Deps (over its own services). Two files of either kind made the barrel’s export * ambiguous (TS2308), and at runtime the ambiguous name is dropped from the namespace, so a test’s __resetAgents() was undefined. Where two or more files contribute one, the barrel exports a merged definition, which takes precedence over the star exports: reset every file’s agents; combine every file’s surface over the intersection of their deps.

module_of maps a file’s source path to the path its module is emitted at, relative to which barrel_loc imports it: the identity for a bundle barrel, the file’s own module under handlers/ for a Worker’s handlers.ts (#1820). surface says whether each file exports a surface at all: a Worker’s files do not, since its composition root (compose.ts) builds the surface over the whole context.