       js: ''
     }
   else
-    module = lookupCompiledModule moduleName
-    {modules, ctx} = contextWithDependencies moduleDependencies moduleName
     [expression] = _terms ast
-    compilationFn = (topLevelExpressionInModule importsFor moduleDependencies moduleName)
-    {js} = compileCtxAstToJs compilationFn, ctx, expression
-    (finalizeTypes ctx, expression)
-    js: library + immutable + (listOfLines map lookupJs, (setToArray runtimeDependencies moduleName)) + '\n;' + js
-    ast: ast
-    errors: checkTypes ctx
-    malformed: ctx.isMalformed
+    result = compileExpressionFromAst expression, moduleName
+    result.ast = ast
+    result
+
+compileExpressionFromAst = (expression, moduleName) ->
+  module = lookupCompiledModule moduleName
+  {modules, ctx} = contextWithDependencies moduleDependencies moduleName
+  compilationFn = (topLevelExpressionInModule importsFor moduleDependencies moduleName)
+  {js} = compileCtxAstToJs compilationFn, ctx, expression
+  (finalizeTypes ctx, expression)
+  js: library + immutable + (listOfLines map lookupJs, (setToArray runtimeDependencies moduleName)) + '\n;' + js
+  errors: checkTypes ctx
+  malformed: ctx.isMalformed
 
 importsFor = (moduleSet) ->
   lookupDefinitions = (name) ->


# end of Utils

# Unit tests
test = (testName, teaSource, result) ->
  try

#   exports"""

exports.library = library
exports.runtime = runtime

exports.originOf = originOf
exports.sortedArgs = sortedArgs
