Skip to content

Commit 3fd748f

Browse files
committed
add cljs.js/load-source-map!, extend *load-fn* support so that
source maps for pre-compiled ClojureScript works
1 parent d516268 commit 3fd748f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/main/cljs/cljs/js.cljs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@
6262
respected). Upon resolution the callback should be invoked with a map
6363
containing the following keys:
6464
65-
:lang - the language, :clj or :js
66-
:source - the source of the library (a string)
67-
:cache - optional, if a :clj namespace has been precompiled to :js, can give
68-
an analysis cache for faster loads.
65+
:lang - the language, :clj or :js
66+
:source - the source of the library (a string)
67+
:cache - optional, if a :clj namespace has been precompiled to :js, can
68+
give an analysis cache for faster loads.
69+
:source-map - optional, if a :clj namespace has been precompiled to :js, can
70+
give a V3 source map JSON
6971
7072
If the resource could not be resolved, the callback should be invoked with
7173
nil."
@@ -113,6 +115,10 @@
113115
(defn load-analysis-cache! [state ns cache]
114116
(swap! state assoc-in [::ana/namespaces ns] cache))
115117

118+
(defn load-source-map! [state ns sm-json]
119+
(let [sm (sm/decode (.parse js/JSON sm-json))]
120+
(swap! state assoc-in [:source-maps ns] sm)))
121+
116122
(defn sm-data []
117123
(atom
118124
{:source-map (sorted-map)
@@ -182,7 +188,7 @@
182188
(assert (or (map? resource) (nil? resource))
183189
"*load-fn* may only return a map or nil")
184190
(if resource
185-
(let [{:keys [lang source cache]} resource]
191+
(let [{:keys [lang source cache source-map]} resource]
186192
(condp = lang
187193
:clj (eval-str* bound-vars source name opts
188194
(fn [res]
@@ -194,6 +200,9 @@
194200
(when cache
195201
(load-analysis-cache!
196202
(:*compiler* bound-vars) name cache))
203+
(when source-map
204+
(load-source-map!
205+
(:*compiler* bound-vars) name source-map))
197206
(catch :default cause
198207
(wrap-error
199208
(ana/error env

0 commit comments

Comments
 (0)