Skip to content

Commit 3fffee0

Browse files
committed
add closure/add-implicit-options to share more logic between compiler
and REPLs
1 parent 8ea4530 commit 3fffee0

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

src/clj/cljs/closure.clj

+14-9
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,19 @@ should contain the source for the given namespace name."
13101310
(and (satisfies? deps/IJavaScript js)
13111311
(deps/-foreign? js)))
13121312

1313+
(defn add-implicit-options [opts]
1314+
(let [{:keys [libs foreign-libs externs]} (get-upstream-deps)]
1315+
(cond->
1316+
(-> opts
1317+
(assoc
1318+
:ups-libs libs
1319+
:ups-foreign-libs foreign-libs
1320+
:ups-externs externs)
1321+
(update-in [:preamble] #(into (or % []) ["cljs/imul.js"])))
1322+
(:target opts)
1323+
(assoc-in [:closure-defines "cljs.core.target"]
1324+
(name (:target opts))))))
1325+
13131326
(defn build
13141327
"Given a source which can be compiled, produce runnable JavaScript."
13151328
([source opts]
@@ -1320,15 +1333,7 @@ should contain the source for the given namespace name."
13201333
([source opts compiler-env]
13211334
(env/with-compiler-env compiler-env
13221335
(let [compiler-stats (:compiler-stats opts)
1323-
ups-deps (get-upstream-deps)
1324-
all-opts (cond->
1325-
(-> opts
1326-
(assoc
1327-
:ups-libs (:libs ups-deps)
1328-
:ups-foreign-libs (:foreign-libs ups-deps)
1329-
:ups-externs (:externs ups-deps))
1330-
(update-in [:preamble] #(into (or % []) ["cljs/imul.js"])))
1331-
(:target opts) (assoc-in [:closure-defines "cljs.core.target"] (name (:target opts))))
1336+
all-opts (add-implicit-options opts)
13321337
emit-constants (or (and (= (:optimizations opts) :advanced)
13331338
(not (false? (:optimize-constants opts))))
13341339
(:optimize-constants opts))]

src/clj/cljs/repl.clj

+14-16
Original file line numberDiff line numberDiff line change
@@ -638,25 +638,23 @@
638638
source-map-inline true}
639639
:as opts}]
640640
(print "To quit, type:" :cljs/quit)
641-
(let [ups-deps (cljsc/get-upstream-deps)
642-
{:keys [analyze-path repl-verbose warn-on-undeclared special-fns static-fns] :as opts
641+
(let [{:keys [analyze-path repl-verbose warn-on-undeclared special-fns static-fns] :as opts
643642
:or {warn-on-undeclared true}}
644643
(merge
645644
{:cache-analysis true :source-map true}
646-
(assoc (merge (-repl-options repl-env) opts)
647-
:init init
648-
:need-prompt prompt
649-
:flush flush
650-
:read read
651-
:print print
652-
:caught caught
653-
:reader reader
654-
:print-no-newline print-no-newline
655-
:source-map-inline source-map-inline
656-
:output-dir (or (:output-dir opts)
657-
(:default-output-dir repl-env))
658-
:ups-libs (:libs ups-deps)
659-
:ups-foreign-libs (:foreign-libs ups-deps)))]
645+
(cljsc/add-implicit-options
646+
(assoc (merge (-repl-options repl-env) opts)
647+
:init init
648+
:need-prompt prompt
649+
:flush flush
650+
:read read
651+
:print print
652+
:caught caught
653+
:reader reader
654+
:print-no-newline print-no-newline
655+
:source-map-inline source-map-inline
656+
:output-dir (or (:output-dir opts)
657+
(:default-output-dir repl-env)))))]
660658
(env/with-compiler-env
661659
(or (::env/compiler repl-env) (env/default-compiler-env opts))
662660
(binding [ana/*cljs-ns* 'cljs.user

0 commit comments

Comments
 (0)