Skip to content

Commit 300e326

Browse files
Deraenswannodette
authored andcommitted
CLJS-2294: Always use opts with implicit opts added
This fixes e.g. cases where opts checkers presume that :optimizations is always set. add-implicit-opts adds for example :optimization :none. Two test cases used :target :nodejs without :main which is against assertion, but previously the assertion didn't catch this, because tests don't have :optimizations set.
1 parent d450122 commit 300e326

File tree

2 files changed

+49
-46
lines changed

2 files changed

+49
-46
lines changed

src/main/clojure/cljs/closure.clj

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,37 +2517,38 @@
25172517
(add-externs-sources (dissoc opts :foreign-libs))))))
25182518
([source opts compiler-env]
25192519
(env/with-compiler-env compiler-env
2520-
;; we want to warn about NPM dep conflicts before installing the modules
2521-
(when (:install-deps opts)
2522-
(check-npm-deps opts)
2523-
(swap! compiler-env update-in [:npm-deps-installed?]
2524-
(fn [installed?]
2525-
(when-not installed?
2526-
(maybe-install-node-deps! opts)))))
2527-
(let [compiler-stats (:compiler-stats opts)
2520+
(let [opts (add-implicit-options opts)
2521+
;; we want to warn about NPM dep conflicts before installing the modules
2522+
_ (when (:install-deps opts)
2523+
(check-npm-deps opts)
2524+
(swap! compiler-env update-in [:npm-deps-installed?]
2525+
(fn [installed?]
2526+
(when-not installed?
2527+
(maybe-install-node-deps! opts)))))
2528+
2529+
compiler-stats (:compiler-stats opts)
25282530
checked-arrays (or (:checked-arrays opts)
25292531
ana/*checked-arrays*)
25302532
static-fns? (or (and (= (:optimizations opts) :advanced)
25312533
(not (false? (:static-fns opts))))
25322534
(:static-fns opts)
25332535
ana/*cljs-static-fns*)
2534-
sources (-find-sources source opts)
2535-
all-opts (add-implicit-options opts)]
2536+
sources (-find-sources source opts)]
25362537
(check-output-to opts)
25372538
(check-output-dir opts)
25382539
(check-source-map opts)
25392540
(check-source-map-path opts)
25402541
(check-output-wrapper opts)
25412542
(check-node-target opts)
2542-
(check-preloads all-opts)
2543+
(check-preloads opts)
25432544
(check-cache-analysis-format opts)
25442545
(swap! compiler-env
25452546
#(-> %
2546-
(update-in [:options] merge all-opts)
2547+
(update-in [:options] merge opts)
25472548
(assoc :target (:target opts))
2548-
;; Save the current js-dependency index once we have computed all-opts
2549+
;; Save the current js-dependency index once we have computed opts
25492550
;; or the analyzer won't be able to find upstream dependencies - Antonio
2550-
(assoc :js-dependency-index (deps/js-dependency-index all-opts))
2551+
(assoc :js-dependency-index (deps/js-dependency-index opts))
25512552
;; Save list of sources for cljs.analyzer/locate-src - Juho Teperi
25522553
(assoc :sources sources)))
25532554
(binding [comp/*recompiled* (when-not (false? (:recompile-dependents opts))
@@ -2571,76 +2572,76 @@
25712572
(repeat warnings))
25722573
warnings)))
25732574
ana/*verbose* (:verbose opts)]
2574-
(let [one-file? (and (:main all-opts)
2575-
(#{:advanced :simple :whitespace} (:optimizations all-opts)))
2575+
(let [one-file? (and (:main opts)
2576+
(#{:advanced :simple :whitespace} (:optimizations opts)))
25762577
source (if one-file?
2577-
(let [main (:main all-opts)
2578+
(let [main (:main opts)
25782579
uri (:uri (cljs-source-for-namespace main))]
25792580
(assert uri (str "No file for namespace " main " exists"))
25802581
uri)
25812582
source)
25822583
compile-opts (if one-file?
2583-
(assoc all-opts :output-file (:output-to all-opts))
2584-
all-opts)
2584+
(assoc opts :output-file (:output-to opts))
2585+
opts)
25852586
_ (load-data-readers! compiler-env)
25862587
;; reset :js-module-index so that ana/parse-ns called by -find-sources
25872588
;; can find the missing JS modules
25882589
js-sources (env/with-compiler-env (dissoc @compiler-env :js-module-index)
2589-
(-> (-find-sources source all-opts)
2590+
(-> (-find-sources source opts)
25902591
(add-dependency-sources compile-opts)))
2591-
all-opts (handle-js-modules all-opts js-sources compiler-env)
2592-
_ (swap! env/*compiler* update-in [:options] merge all-opts)
2592+
opts (handle-js-modules opts js-sources compiler-env)
2593+
_ (swap! env/*compiler* update-in [:options] merge opts)
25932594
js-sources (-> js-sources
25942595
deps/dependency-order
25952596
(compile-sources compiler-stats compile-opts)
25962597
(#(map add-core-macros-if-cljs-js %))
2597-
(add-js-sources all-opts)
2598-
(cond-> (= :nodejs (:target all-opts)) (concat [(-compile (io/resource "cljs/nodejs.cljs") all-opts)]))
2598+
(add-js-sources opts)
2599+
(cond-> (= :nodejs (:target opts)) (concat [(-compile (io/resource "cljs/nodejs.cljs") opts)]))
25992600
deps/dependency-order
2600-
(add-preloads all-opts)
2601+
(add-preloads opts)
26012602
add-goog-base
2602-
(cond-> (= :nodejs (:target all-opts)) (concat [(-compile (io/resource "cljs/nodejscli.cljs") all-opts)]))
2603-
(->> (map #(source-on-disk all-opts %)) doall)
2604-
(compile-loader all-opts))
2605-
_ (when (:emit-constants all-opts)
2603+
(cond-> (= :nodejs (:target opts)) (concat [(-compile (io/resource "cljs/nodejscli.cljs") opts)]))
2604+
(->> (map #(source-on-disk opts %)) doall)
2605+
(compile-loader opts))
2606+
_ (when (:emit-constants opts)
26062607
(comp/emit-constants-table-to-file
26072608
(::ana/constant-table @env/*compiler*)
2608-
(constants-filename all-opts)))
2609-
_ (when (:infer-externs all-opts)
2609+
(constants-filename opts)))
2610+
_ (when (:infer-externs opts)
26102611
(comp/emit-inferred-externs-to-file
26112612
(reduce util/map-merge {}
26122613
(map (comp :externs second)
26132614
(get @compiler-env ::ana/namespaces)))
2614-
(str (util/output-directory all-opts) "/inferred_externs.js")))
2615-
optim (:optimizations all-opts)
2615+
(str (util/output-directory opts) "/inferred_externs.js")))
2616+
optim (:optimizations opts)
26162617
ret (if (and optim (not= optim :none))
26172618
(do
2618-
(when-let [fname (:source-map all-opts)]
2619-
(assert (or (nil? (:output-to all-opts)) (:modules opts) (string? fname))
2619+
(when-let [fname (:source-map opts)]
2620+
(assert (or (nil? (:output-to opts)) (:modules opts) (string? fname))
26202621
(str ":source-map must name a file when using :whitespace, "
26212622
":simple, or :advanced optimizations with :output-to")))
2622-
(if (:modules all-opts)
2623+
(if (:modules opts)
26232624
(->>
26242625
(util/measure compiler-stats
26252626
(str "Optimizing " (count js-sources) " sources")
2626-
(apply optimize-modules all-opts js-sources))
2627-
(output-modules all-opts js-sources))
2628-
(let [fdeps-str (foreign-deps-str all-opts
2627+
(apply optimize-modules opts js-sources))
2628+
(output-modules opts js-sources))
2629+
(let [fdeps-str (foreign-deps-str opts
26292630
(filter foreign-source? js-sources))
2630-
all-opts (assoc all-opts
2631+
opts (assoc opts
26312632
:foreign-deps-line-count
26322633
(- (count (.split #"\r?\n" fdeps-str -1)) 1))]
26332634
(->>
26342635
(util/measure compiler-stats
26352636
(str "Optimizing " (count js-sources) " sources")
2636-
(apply optimize all-opts
2637+
(apply optimize opts
26372638
(remove foreign-source? js-sources)))
2638-
(add-wrapper all-opts)
2639-
(add-source-map-link all-opts)
2639+
(add-wrapper opts)
2640+
(add-source-map-link opts)
26402641
(str fdeps-str)
2641-
(add-header all-opts)
2642-
(output-one-file all-opts)))))
2643-
(apply output-unoptimized all-opts js-sources))]
2642+
(add-header opts)
2643+
(output-one-file opts)))))
2644+
(apply output-unoptimized opts js-sources))]
26442645
;; emit Node.js bootstrap script for :none & :whitespace optimizations
26452646
(when (and (= (:target opts) :nodejs)
26462647
(not= (:optimizations opts) :whitespace))

src/test/clojure/cljs/build_api_tests.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
[{:file (str (io/file root "thirdparty" "add.js"))
155155
:provides ["thirdparty.add"]}]
156156
:output-dir (str out)
157+
:main 'foreign-libs.core
157158
:target :nodejs}]
158159
(test/delete-out-files out)
159160
(build/build (build/inputs (io/file root "foreign_libs") (io/file root "thirdparty")) opts)
@@ -416,6 +417,7 @@
416417
(let [out (io/file (test/tmp-dir) "cljs-2249-out")
417418
root (io/file "src" "test" "cljs_build")
418419
opts {:output-dir (str out)
420+
:main 'foreign-libs-cljs-2249.core
419421
:target :nodejs}]
420422
(test/delete-out-files out)
421423
(build/build (build/inputs (io/file root "foreign_libs_cljs_2249")) opts)

0 commit comments

Comments
 (0)