diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b7c36c0..bcf7d296 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ SCI is used in [babashka](https://github.com/babashka/babashka), ## Unreleased - Fix [#626](https://github.com/babashka/sci/issues/626): add `cljs.core/exists?` +- Fix [#919](https://github.com/babashka/sci/issues/919): :js-libs + refer + rename clashes with core var ## 0.8.41 (2023-11-24) diff --git a/src/sci/core.cljc b/src/sci/core.cljc index 409c0349..5e26ebcd 100644 --- a/src/sci/core.cljc +++ b/src/sci/core.cljc @@ -14,7 +14,6 @@ [sci.impl.callstack :as cs] [sci.impl.interpreter :as i] [sci.impl.io :as sio] - [sci.impl.load :as load] [sci.impl.macros :as macros] [sci.impl.namespaces :as namespaces] [sci.impl.opts :as opts] @@ -496,7 +495,11 @@ "Adds import of class named by `class-name` (a symbol) to namespace named by `ns-name` (a symbol) under alias `alias` (a symbol). Returns mutated context." [ctx ns-name class-name alias] ;; This relies on an internal format of the context and may change at any time. - (swap! (:env ctx) assoc-in [:namespaces ns-name :imports alias] class-name) + (swap! (:env ctx) + (fn [env] + (-> env + (assoc-in [:namespaces ns-name :imports alias] class-name) + (update-in [:namespaces ns-name :refer 'clojure.core :exclude] (fnil conj #{}) alias)))) ctx) (defn add-class! diff --git a/src/sci/impl/load.cljc b/src/sci/impl/load.cljc index d6bccc86..f3d9c6cc 100644 --- a/src/sci/impl/load.cljc +++ b/src/sci/impl/load.cljc @@ -42,6 +42,7 @@ refer (get rename refer refer)] (-> env (assoc-in [:namespaces cnn :imports refer] sub-sym) + (update-in [:namespaces cnn :refer 'clojure.core :exclude] (fnil conj #{}) refer) (assoc-in [:class->opts sub-sym :class] the-sublib) (assoc-in [:raw-classes sub-sym] the-sublib)))) env refers)) diff --git a/src/sci/impl/parser.cljc b/src/sci/impl/parser.cljc index a38cafa9..cb6e2c9a 100644 --- a/src/sci/impl/parser.cljc +++ b/src/sci/impl/parser.cljc @@ -79,7 +79,7 @@ :refer (get 'clojure.core) :exclude - (contains? sym )))) + (contains? sym)))) (contains? utils/ana-macros sym)) (symbol "clojure.core" sym-name-str)) (interop/fully-qualify-class ctx sym) diff --git a/test/sci/js_libs_test.cljs b/test/sci/js_libs_test.cljs index 77fbbfd8..8739717b 100644 --- a/test/sci/js_libs_test.cljs +++ b/test/sci/js_libs_test.cljs @@ -36,6 +36,11 @@ (sci/eval-form ctx '(do (require '["fs" :refer [readFileSync]] '[clojure.string :as str]) (first (str/split-lines (readFileSync "README.md" "utf-8"))))) + "img")) + (is (str/includes? + (sci/eval-form ctx '(do (require '["fs" :refer [readFileSync] :rename {readFileSync exists?}] + '[clojure.string :as str]) + (first (str/split-lines (exists? "README.md" "utf-8"))))) "img")))) (testing "rename" (let [ctx (sci/init {})]