Skip to content

CLJS-3330: Flag for legacy loading of goog.object & goog.array #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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