Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
CLJS-3330: Flag for legacy loading of goog.object & goog.array
  • Loading branch information
swannodette committed Oct 19, 2021
1 parent 76ac6bf commit 1a9a10f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/main/clojure/cljs/analyzer.cljc
Expand Up @@ -815,8 +815,14 @@
(defn goog-module-dep?
[module]
(let [[module _] (lib&sublib module)
module-type (get-in @env/*compiler* [:js-dependency-index (str module) :module])]
(= :goog module-type)))
module-str (str module)
options (compiler-options)]
;; CLJS-3330: flag for loading some old things in the old way to give time
;; for library authors to migrate
(if (and (:global-goog-object&array options)
(#{"goog.object" "goog.array"} module-str))
false
(= :goog (get-in @env/*compiler* [:js-dependency-index module-str :module])))))

(defn confirm-var-exists
([env prefix suffix]
Expand Down
2 changes: 1 addition & 1 deletion src/main/clojure/cljs/closure.clj
Expand Up @@ -213,7 +213,7 @@
:watch :watch-error-fn :watch-fn :install-deps :process-shim :rename-prefix :rename-prefix-namespace
:closure-variable-map-in :closure-property-map-in :closure-variable-map-out :closure-property-map-out
:stable-names :ignore-js-module-exts :opts-cache :aot-cache :elide-strict :fingerprint :spec-skip-macros
:nodejs-rt :target-fn :deps-cmd :bundle-cmd})
:nodejs-rt :target-fn :deps-cmd :bundle-cmd :global-goog-object&array})

(def string->charset
{"iso-8859-1" StandardCharsets/ISO_8859_1
Expand Down
14 changes: 13 additions & 1 deletion src/test/clojure/cljs/compiler/glib_module_test.clj
Expand Up @@ -5,7 +5,7 @@

(deftest test-glib-module-compile
(testing "glib modules compiled to Closure Compile expectations"
(let [src (env/with-compiler-env (env/default-compiler-env)
(let [src (env/with-compiler-env (env/default-compiler-env )
(comp-tests/compile-form-seq
'[(ns test.foo
(:import [goog.module ModuleLoader]))
Expand All @@ -14,6 +14,18 @@
(is (re-find #"test\.foo\.goog\$module\$goog\$module\$ModuleLoader = goog\.module\.get\('goog.module.ModuleLoader'\)" src))
(is (re-find #"test\.foo\.module_loader = \(new test\.foo\.goog\$module\$goog\$module\$ModuleLoader\(\)\)" src)))))

(deftest cljs-3330-global-goog-object&array
(testing "migration path for goog.module impact on goog.object & goog.array"
(let [src (env/with-compiler-env
(env/default-compiler-env {:global-goog-object&array true})
(comp-tests/compile-form-seq
'[(ns test.foo
(:require [goog.object :as gobj]
[goog.array :as garray]))
(def module-loader (ModuleLoader.))]))]
(is (re-find #"goog\.require\('goog\.object\'\)" src))
(is (re-find #"goog\.require\('goog\.array\'\)" src)))))

(comment

(test/run-tests)
Expand Down

0 comments on commit 1a9a10f

Please sign in to comment.