   else
     fileLocation
 
+# Map of filenames -> sourceMap object.
+sourceMaps = {}
+
+# Generates the source map for a coffee file and stores it in the local cache variable.
+getSourceMap = (filename) ->
+  return sourceMaps[filename] if sourceMaps[filename]
+  return unless path.extname(filename) in extensions
+  answer = compileFile filename, true
+  sourceMaps[filename] = answer.sourceMap
+
+# Based on [michaelficarra/CoffeeScriptRedux](http://goo.gl/ZTx1p)
+# NodeJS / V8 have no support for transforming positions in stack traces using
+# sourceMap, so we must monkey-patch Error to display CoffeeScript source
+# positions.
+Error.prepareStackTrace = (err, stack) ->
+  getSourceMapping = (filename, line, column) ->
+    sourceMap = getSourceMap filename
+    answer = sourceMap.sourceLocation [line - 1, column - 1] if sourceMap
+    if answer then [answer[0] + 1, answer[1] + 1] else null
+
+  frames = for frame in stack
+    break if frame.getFunction() is exports.run
+    "  at #{formatSourcePosition frame, getSourceMapping}"
+
+  "#{err.name}: #{err.message ? ''}\n#{frames.join '\n'}\n"
+

      else
        "#{fileName}:#{line}:#{column}"


  functionName = frame.getFunctionName()
  isConstructor = frame.isConstructor()
  isMethodCall = not (frame.isToplevel() or isConstructor)

  else
    vm.runInContext js, sandbox

compileFile = (filename, sourceMap) ->
  raw = fs.readFileSync filename, 'utf8'
  stripped = if raw.charCodeAt(0) is 0xFEFF then raw.substring 1 else raw

  try
    answer = compile(stripped, {filename, sourceMap, literate: helpers.isLiterate filename})
  catch err
    # As the filename and code of a dynamically loaded file will be different
    # from the original file compiled with CoffeeScript.run, add that
