   "Create a CompilerOptions object and set options from opts map."
   [opts]
   (let [level (case (:optimizations opts)
-                    :advanced CompilationLevel/ADVANCED_OPTIMIZATIONS
-                    :whitespace CompilationLevel/WHITESPACE_ONLY
-                    :simple CompilationLevel/SIMPLE_OPTIMIZATIONS)
+                :advanced CompilationLevel/ADVANCED_OPTIMIZATIONS
+                :whitespace CompilationLevel/WHITESPACE_ONLY
+                :simple CompilationLevel/SIMPLE_OPTIMIZATIONS)
         compiler-options (doto (CompilerOptions.)
                            (.setCodingConvention (ClosureCodingConvention.)))]
+    (when (contains? opts :source-map)
+      (set! (.sourceMapOutputPath compiler-options)
+            (:source-map opts))
+      (set! (.sourceMapDetailLevel compiler-options)
+            SourceMap$DetailLevel/ALL)
+      (set! (.sourceMapFormat compiler-options)
+            SourceMap$Format/V3))
     (do (.setOptionsForCompilationLevel level compiler-options)
         (set-options opts compiler-options)
         compiler-options)))

           com.google.common.collect.ImmutableList
           com.google.javascript.jscomp.CompilerOptions
           com.google.javascript.jscomp.CompilationLevel
           com.google.javascript.jscomp.ClosureCodingConvention
           com.google.javascript.jscomp.JSSourceFile
           com.google.javascript.jscomp.Result

        inputs (map #(js-source-file (javascript-name %) %) sources)
        result ^Result (.compile closure-compiler externs inputs compiler-options)]
    (if (.success result)
      ;; compiler.getSourceMap().reset()
      (let [source (.toSource closure-compiler)]
        (when-let [name (:source-map opts)]
          (let [out (io/writer name)]
            (.appendTo (.getSourceMap closure-compiler) out name)
            (.close out)))
        source)
      (report-failure result))))

(comment
