 translateIr = (ctx, irAst) ->
   walkIr irAst, (ast) ->
     if ast.ir
-      ast.ir ctx, ast
+        ast.ir ctx, ast
     else
       walked = {}
       for name, node of ast when name isnt 'js'

  toInject = requiresFor moduleName
  ctx = injectedContext toInject
  ctx.typedModulePath = typedModulePath
  {request, ir, js} = compileCtxAstToJs topLevelModule, ctx, ast
  if request
    if not allInjected request, requiredMap
      return compileModuleTopLevelAst ast, typedModulePath, request
    else
      {js} = compileCtxIrToJs ctx, ir
  errors = checkTypes ctx
  # (finalizeTypes ctx, ast) # TODO: this doesn't work when the AST includes multiple modules with different contexts than the current one
  replaceOrAddToMap compiledModules, moduleName,
    declared: (subtractContexts ctx, (injectedContext toInject)) # must recompute because ctx is mutated
    js: js
  js: js
  ast: ast
  # types: typeEnumaration ctx

    labelConflict conflict.ref.val
  else
    conflict.error = yes

lookupCompiledDefinitions = (moduleName) ->
  compiled = (lookupCompiledModule moduleName)
  if not compiled
    console.error "#{moduleName} not found"
  else
    {compiledDefinitions} = compiled
    # TODO:
    # if not js?
    #   {js} = compileModuleTopLevelAst ast, moduleName
    compiledDefinitions

lookupJs = (moduleName) ->
  compiled = (lookupCompiledModule moduleName)
