     else
       optimizedCode = optimized
     if optimizedMap?
-      json = optimizedMap.toJSON()
       newMap = SourceMapGenerator.fromSourceMap new SourceMapConsumer optimizedMap
-      newMap._sources.add path
-      newMap._mappings.forEach (mapping) ->
-        mapping.source = path
       newMap._sourcesContents ?= {}
-      newMap._sourcesContents["$#{path}"] = ''  # data
-      newMap.applySourceMap smConsumer
+      sourceFiles.forEach ({path, source}) ->
+        newMap._sourcesContents["$#{path}"] = source
     else
       newMap = map
-    next error, {data: optimizedCode, code: optimizedCode, map: newMap, path}
+    next error, {data: optimizedCode, code: optimizedCode, map: newMap, path, sourceFiles}
 
   optimizer.optimize.apply optimizer, optimizerArgs
 
-optimize = (data, map, path, optimizers, callback) ->
-  initial = {data, code: data, map, path}
+optimize = (data, map, path, optimizers, sourceFiles, callback) ->
+  initial = {data, code: data, map, path, sourceFiles}
   first = (next) -> next null, initial
   waterfall [first].concat(optimizers.map mapOptimizerChain), callback
 

  root.toStringWithSourceMap file: path

mapOptimizerChain = (optimizer) -> (params, next) ->
  {data, code, map, path} = params
  debug "Optimizing '#{path}' with '#{optimizer.constructor.name}'"

  optimizerArgs = if optimizer.optimize.length is 2

  withMaps = (map and config.sourceMaps)
  mapPath = "#{path}.map"

  optimize code, map, path, optimizers, sourceFiles, (error, data) ->
    return callback error if error?

    if withMaps
