Skip to content

Commit de8bc1c

Browse files
committed
CLJS-1369: eval-str should support compiled output caching
1 parent 3fd748f commit de8bc1c

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/main/cljs/cljs/js.cljs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -672,15 +672,21 @@
672672
:name name
673673
:path (ns->relpath name)
674674
:source js-source
675-
:cache (get-in env/*compiler*
676-
[::ana/namespaces name])}]
677-
(when (:verbose opts)
678-
(debug-prn js-source))
679-
(let [res (try
680-
{:ns ns :value (*eval-fn* evalm)}
681-
(catch :default cause
682-
(wrap-error (ana/error aenv "ERROR" cause))))]
683-
(cb res))))))))))
675+
:cache (get-in env/*compiler* [::ana/namespaces name])}
676+
complete (fn [res]
677+
(if (:error res)
678+
(cb res)
679+
(do
680+
(when (:verbose opts)
681+
(debug-prn js-source))
682+
(let [res (try
683+
{:ns ns :value (*eval-fn* evalm)}
684+
(catch :default cause
685+
(wrap-error (ana/error aenv "ERROR" cause))))]
686+
(cb res)))))]
687+
(if-let [f (:cache-source opts)]
688+
(f evalm complete)
689+
(complete {:value nil}))))))))))
684690
(:*cljs-ns* bound-vars))))
685691

686692
(defn eval-str
@@ -698,9 +704,15 @@
698704
opts (map)
699705
compilation options.
700706
701-
:eval - eval function to invoke, see *eval-fn*
702-
:load - library resolution function, see *load-fn*
703-
:source-map - set to true to generate inline source map information
707+
:eval - eval function to invoke, see *eval-fn*
708+
:load - library resolution function, see *load-fn*
709+
:source-map - set to true to generate inline source map information
710+
:cache-source - optional, a function to run side-effects with the
711+
compilation result prior to actual evalution. This function
712+
takes two arguments, the first is the eval map, the source
713+
will be under :source. The second argument is a callback of
714+
one argument. If an error occurs an :error key should be
715+
supplied.
704716
705717
cb (function)
706718
callback, will be invoked with a map. If succesful the map will contain

0 commit comments

Comments
 (0)