Skip to content
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

Fix #919: :js-libs + refer + rename clashes with core var #920

Merged
merged 1 commit into from
Mar 4, 2024
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
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
Loading