Skip to content

Commit 3d44a6f

Browse files
committed
validate :main
1 parent 00b8dea commit 3d44a6f

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/main/clojure/cljs/cli.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ present"
474474
convey (into [:output-dir] repl/known-repl-opts)
475475
cfg (update cfg :options merge (select-keys opts convey))
476476
source (when (and (= :none (:optimizations opts :none)) main-ns)
477+
(closure/check-main opts)
477478
(:uri (build/ns->location main-ns)))
478479
cenv (env/default-compiler-env
479480
(closure/add-externs-sources (dissoc opts :foreign-libs)))]

src/main/clojure/cljs/closure.clj

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,13 @@
21912191
(assert (not (and (= target :nodejs) (= optimizations :none) (not (contains? opts :main))))
21922192
(format ":nodejs target with :none optimizations requires a :main entry")))
21932193

2194+
(defn check-main [{:keys [main] :as opts}]
2195+
(when main
2196+
(assert (symbol? main)
2197+
(format ":main must be a symbol, got %s instead" main))
2198+
(assert (not (string/starts-with? (str main) "'"))
2199+
(format ":main must be an unquoted symbol, got %s instead" main))))
2200+
21942201
(defn check-preloads [{:keys [preloads optimizations] :as opts}]
21952202
(when (and (some? preloads)
21962203
(not= preloads '[process.env])
@@ -2812,6 +2819,18 @@
28122819
[ns opts]
28132820
(compile-inputs (find-sources ns opts) opts))
28142821

2822+
(defn validate-opts [opts]
2823+
(check-output-to opts)
2824+
(check-output-dir opts)
2825+
(check-source-map opts)
2826+
(check-source-map-path opts)
2827+
(check-output-wrapper opts)
2828+
(check-node-target opts)
2829+
(check-preloads opts)
2830+
(check-cache-analysis-format opts)
2831+
(check-main opts)
2832+
opts)
2833+
28152834
(defn build
28162835
"Given compiler options, produce runnable JavaScript. An optional source
28172836
parameter may be provided."
@@ -2848,14 +2867,7 @@
28482867
ana/*cljs-static-fns*)
28492868
sources (when source
28502869
(-find-sources source opts))]
2851-
(check-output-to opts)
2852-
(check-output-dir opts)
2853-
(check-source-map opts)
2854-
(check-source-map-path opts)
2855-
(check-output-wrapper opts)
2856-
(check-node-target opts)
2857-
(check-preloads opts)
2858-
(check-cache-analysis-format opts)
2870+
(validate-opts opts)
28592871
(swap! compiler-env
28602872
#(-> %
28612873
(update-in [:options] merge opts)

0 commit comments

Comments
 (0)