Skip to content

Commit

Permalink
Fix #919: :js-libs + refer + rename clashes with core var (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored Mar 4, 2024
1 parent 5940d69 commit a390739
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 5 additions & 2 deletions src/sci/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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!
Expand Down
1 change: 1 addition & 0 deletions src/sci/impl/load.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/sci/impl/parser.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions test/sci/js_libs_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {})]
Expand Down

0 comments on commit a390739

Please sign in to comment.