|
200 | 200 | (doseq [ns (distinct requires)]
|
201 | 201 | (load-namespace repl-env ns opts))))
|
202 | 202 |
|
203 |
| -(defn read-source-map |
204 |
| - "Return the source map for the JavaScript source file." |
205 |
| - [f] |
206 |
| - (let [smf (io/file (str f ".map"))] |
207 |
| - (when (.exists smf) |
208 |
| - (as-> @env/*compiler* compiler-env |
209 |
| - (let [t (util/last-modified smf)] |
210 |
| - (if (> t (get-in compiler-env [::source-maps f :last-modified] 0)) |
211 |
| - (swap! env/*compiler* assoc-in [::source-maps f] |
212 |
| - {:last-modified t |
213 |
| - :source-map (sm/decode (json/read-str (slurp smf) :key-fn keyword))}) |
214 |
| - compiler-env)) |
215 |
| - (get-in compiler-env [::source-maps f :source-map]))))) |
216 |
| - |
217 | 203 | (defn ^File js-src->cljs-src
|
218 | 204 | "Map a JavaScript output file back to the original ClojureScript source
|
219 | 205 | file."
|
|
223 | 209 | name (.getName f)]
|
224 | 210 | (io/file dir (string/replace name ".js" ".cljs"))))
|
225 | 211 |
|
| 212 | +(defn read-source-map |
| 213 | + "Return the source map for the JavaScript source file." |
| 214 | + [f] |
| 215 | + (when-let [smf (util/file-or-resource (str f ".map"))] |
| 216 | + (let [ns (if (= f "cljs/core.aot.js") |
| 217 | + 'cljs.core |
| 218 | + (:ns (ana/parse-ns (js-src->cljs-src f))))] |
| 219 | + (as-> @env/*compiler* compiler-env |
| 220 | + (let [t (util/last-modified smf)] |
| 221 | + (if (> t (get-in compiler-env [::source-maps ns :last-modified] 0)) |
| 222 | + (swap! env/*compiler* assoc-in [::source-maps ns] |
| 223 | + {:last-modified t |
| 224 | + :source-map (sm/decode (json/read-str (slurp smf) :key-fn keyword))}) |
| 225 | + compiler-env)) |
| 226 | + (get-in compiler-env [::source-maps ns :source-map]))))) |
| 227 | + |
226 | 228 | (defn ns-info
|
227 | 229 | "Given a path to a js source file return the ns info for the corresponding
|
228 | 230 | ClojureScript file if it exists."
|
|
734 | 736 | :source-map-inline source-map-inline})))
|
735 | 737 | done? (atom false)]
|
736 | 738 | (env/with-compiler-env (or compiler-env (env/default-compiler-env opts))
|
| 739 | + (when (:source-map opts) |
| 740 | + (.start (Thread. (bound-fn [] (read-source-map "cljs/core.aot.js"))))) |
737 | 741 | (binding [*err* (if bind-err
|
738 | 742 | (cond-> *out*
|
739 | 743 | (not (instance? PrintWriter *out*)) (PrintWriter.))
|
|
0 commit comments