From 1a9a10f283429f716838e982881b6512325ad09c Mon Sep 17 00:00:00 2001 From: David Nolen Date: Tue, 19 Oct 2021 16:29:58 -0400 Subject: [PATCH] CLJS-3330: Flag for legacy loading of goog.object & goog.array --- src/main/clojure/cljs/analyzer.cljc | 10 ++++++++-- src/main/clojure/cljs/closure.clj | 2 +- .../clojure/cljs/compiler/glib_module_test.clj | 14 +++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/clojure/cljs/analyzer.cljc b/src/main/clojure/cljs/analyzer.cljc index 12a6bab46..9cd94fe8f 100644 --- a/src/main/clojure/cljs/analyzer.cljc +++ b/src/main/clojure/cljs/analyzer.cljc @@ -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] diff --git a/src/main/clojure/cljs/closure.clj b/src/main/clojure/cljs/closure.clj index b84b7382a..c3f5ea251 100644 --- a/src/main/clojure/cljs/closure.clj +++ b/src/main/clojure/cljs/closure.clj @@ -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 diff --git a/src/test/clojure/cljs/compiler/glib_module_test.clj b/src/test/clojure/cljs/compiler/glib_module_test.clj index c9813d209..3e6f12c0f 100644 --- a/src/test/clojure/cljs/compiler/glib_module_test.clj +++ b/src/test/clojure/cljs/compiler/glib_module_test.clj @@ -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])) @@ -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)