     conflict.error = yes
 
 lookupJs = (moduleName) ->
-  js = (lookupCompiledModule moduleName)?.js
-  if not js
+  compiled = (lookupCompiledModule moduleName)
+  if not compiled
     console.error "#{moduleName} not found"
   else
+    {js, ast} = compiled
+    if not js?
+      {js} = compileModuleTopLevelAst ast, moduleName
     js
 
 allInjected = (required, injected) ->

    if doDeclare
      replaceOrAddToMap compiledModules, moduleName,
        declared: (subtractContexts ctx, (injectedContext requiresFor moduleName))
        # TODO: this hack relies on JS overwriting values
        js: ((lookupInMap compiledModules, moduleName)?.js or '') + js
    ast: originalAst
    errors: errors
    malformed: ctx.isMalformed



compileModuleTopLevel = (source, moduleName = '@unnamed', requiredMap = newMap()) ->
  compileModuleTopLevelAst (astFromSource "(#{source})", -1, -1), moduleName, requiredMap

compileModuleTopLevelAst = (ast, moduleName = '@unnamed', requiredMap = newMap()) ->
  addToMap requiredMap, 'Prelude', yes # TODO: Hardcoded prelude dependency
  removeFromMap requiredMap, moduleName
  for requiredModuleName of values requiredMap
