Skip to content

Commit e86a369

Browse files
authored
runtime existence check for :require-global libs under :optimizations :none (#270)
1 parent be21ba1 commit e86a369

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/main/clojure/cljs/compiler.cljc

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,19 +1312,24 @@
13121312
(apply str
13131313
(map #(str "['" % "']") xs)))))
13141314

1315-
(defn emit-global-export [ns-name global-exports lib]
1316-
(let [[lib' sublib] (ana/lib&sublib lib)]
1315+
(defn emit-global-export [ns-name global-exports lib opts]
1316+
(let [[lib' sublib] (ana/lib&sublib lib)
1317+
ref (str "goog.global"
1318+
;; Convert object dot access to bracket access
1319+
(->> (string/split (name (or (get global-exports (symbol lib'))
1320+
(get global-exports (name lib'))))
1321+
#"\.")
1322+
(map (fn [prop] (str "[\"" prop "\"]")))
1323+
(apply str)))]
1324+
(when (and (ana/external-dep? lib')
1325+
(= :none (:optimizations opts)))
1326+
(emitln
1327+
"if(!" ref ") throw new Error(\"External library, " lib' ", never provided\");"))
13171328
(emitln
13181329
(munge ns-name) "."
13191330
(ana/munge-global-export lib)
1320-
" = goog.global"
1321-
;; Convert object dot access to bracket access
1322-
(->> (string/split (name (or (get global-exports (symbol lib'))
1323-
(get global-exports (name lib'))))
1324-
#"\.")
1325-
(map (fn [prop]
1326-
(str "[\"" prop "\"]")))
1327-
(apply str))
1331+
" = "
1332+
ref
13281333
(sublib-select sublib)
13291334
";")))
13301335

@@ -1409,7 +1414,7 @@
14091414
;; Global Exports
14101415
(doseq [lib global-exports-libs]
14111416
(let [{:keys [global-exports]} (get js-dependency-index (name (-> lib ana/lib&sublib first)))]
1412-
(emit-global-export ns-name global-exports lib)))
1417+
(emit-global-export ns-name global-exports lib options)))
14131418
(when (-> libs meta :reload-all)
14141419
(emitln "if(!COMPILED) " loaded-libs " = cljs.core.into(" loaded-libs-temp ", " loaded-libs ");"))))
14151420

0 commit comments

Comments
 (0)