       js: ''
     }
   else
-    module = lookupInMap compiledModules, moduleName
-    toInject = concatSets (collectRequiresFor moduleName), (newSetWith moduleName)
-    ctx = injectedContext toInject
+    module = lookupCompiledModule moduleName
+    {modules, ctx} = contextWithDependencies moduleName
     [expression] = _terms ast
     {js} = compileCtxAstToJs topLevelExpression, ctx, expression
     (finalizeTypes ctx, expression)
-    js: library + immutable + (listOfLines map lookupJs, setToArray toInject) + js
+    js: library + immutable + (listOfLines map lookupJs, modules) + js
     ast: ast
     errors: checkTypes ctx
+
+contextWithDependencies = (moduleName) ->
+  toInject = concatSets (collectRequiresFor moduleName), (newSetWith moduleName)
+  ctx: injectedContext toInject
+  modules: setToArray toInject
 
 # Primitive type checking for now
 checkTypes = (ctx) ->

  typeNames = subtractMaps ctx._scope().typeNames, what._scope().typeNames
  classes = subtractMaps ctx._scope().classes, what._scope().classes
  macros = subtractMaps (objectToMap ctx._macros), (objectToMap what._macros)
  {definitions, typeNames, classes, macros}

injectedContext = (modulesToInject) ->
  ctx = new Context
  for name of values modulesToInject when compiled = lookupInMap compiledModules, name
    injectContext ctx, compiled.declared
  ctx


      expression.tea = substitute ctx.substitution, expression.tea
    return
  return


# end of API

