From d3f6e57746aa37a804eadb2ce63dafc6b485d9aa Mon Sep 17 00:00:00 2001 From: dnolen Date: Sun, 29 Mar 2020 15:59:53 -0400 Subject: [PATCH] CLJS-3219: Problem with asserts namespace inside goog.math.Long move more shareable logic into cljs.repl.bootstrap - do the goog.isProvided_ monkeypatch there - go ahead and keep a reference to the original just in case we need it in the future. tweak goog.require monkey patch to check if we're in the goog.module loader and in that case return the module. This is only for goog.module - nothing we would ever generate in ClojureScript --- src/main/clojure/cljs/repl/bootstrap.clj | 14 ++++++++++++-- src/main/clojure/cljs/repl/node.clj | 3 --- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/clojure/cljs/repl/bootstrap.clj b/src/main/clojure/cljs/repl/bootstrap.clj index 1d7a8c39eb..f54b1d2a92 100644 --- a/src/main/clojure/cljs/repl/bootstrap.clj +++ b/src/main/clojure/cljs/repl/bootstrap.clj @@ -13,9 +13,16 @@ "Install a version of goog.require that supports namespace reloading. IMPORTANT: must be invoked *after* loading cljs.core." [repl-env env] + ;; monkey patch goog.provide - it throws when namespaces are loaded multiple times + ;; we never care how many times a namespace is loaded it doesn't matter if + ;; Google Closure Library or ClojureScript (repl/evaluate-form repl-env env "" - '(set! (.-require__ js/goog) js/goog.require)) + '(set! (.-isProvided__ js/goog) js/goog.isProvided_)) + (repl/evaluate-form repl-env env "" + '(set! (.-isProvided_ js/goog) (fn [x] false))) ;; monkey-patch goog.require + (repl/evaluate-form repl-env env "" + '(set! (.-require__ js/goog) js/goog.require)) (repl/evaluate-form repl-env env "" '(set! (.-require js/goog) (fn [src reload] @@ -38,4 +45,7 @@ (let [ret (.require__ js/goog src)] (when (= reload "reload-all") (set! (.-cljsReloadAll_ js/goog) false)) - ret)))))) \ No newline at end of file + ;; handle requires from Closure Library goog.modules + (if (js/goog.isInModuleLoader_) + (js/goog.module.getInternal_ src) + ret))))))) diff --git a/src/main/clojure/cljs/repl/node.clj b/src/main/clojure/cljs/repl/node.clj index b6319cc3f9..03f6335f2a 100644 --- a/src/main/clojure/cljs/repl/node.clj +++ b/src/main/clojure/cljs/repl/node.clj @@ -192,9 +192,6 @@ (str "require(" (platform-path (conj root-path "node_repl_deps.js")) ")")) - ;; monkey-patch isProvided_ to avoid useless warnings - David - (node-eval repl-env - (str "goog.isProvided_ = function(x) { return false; };")) ;; load cljs.core, setup printing (repl/evaluate-form repl-env env "" '(do