Skip to content
Open
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
[Squint](https://github.com/squint-cljs/squint): Light-weight ClojureScript dialect

## Unreleased

- [#779](https://github.com/squint-cljs/squint/pull/779): Added `compare-and-swap!`, `swap-vals!` and `reset-vals!`
- Multiple `:require-macros` with `:refer` now accumulate instead of overwriting
- Fix qualified symbol resolution in macro expansions when namespace has different runtime alias

## v0.9.182

Expand Down
3 changes: 2 additions & 1 deletion bb/tasks.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
(assert (str/includes? output "my-other-src 1 2"))
(assert (str/includes? output "json!"))
(assert (str/includes? output "{ a: 1 }"))
(assert (str/includes? output "\"emit!\"")))
(assert (str/includes? output "\"emit!\""))
(assert (str/includes? output "qualified test: 142")))
(assert (fs/exists? "test-project/lib/foo.json"))
(assert (fs/exists? "test-project/lib/baz.css"))
(assert (not (fs/exists? "test-project/lib/bar.json")))))
Expand Down
6 changes: 3 additions & 3 deletions src/squint/compiler/node.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
reload (concat [:reload])))
(let [publics (eval-form
`(ns-publics '~macro-ns))
ks (keys publics)
vs (vals publics)
vs (map deref vs)
macro-vars (filter (fn [[_ v]] (:macro (meta v))) publics)
ks (map first macro-vars)
vs (map (comp deref second) macro-vars)
publics (zipmap ks vs)]
publics)))]
(.then macros
Expand Down
13 changes: 11 additions & 2 deletions src/squint/compiler_common.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@
(str "globalThis." (munge *cljs-ns*) "."))
(alias-munge sym-ns) "."
(munged-name sn)))
(when-let [alias (get (:libname->alias current-ns) (str sym-ns))]
(str (when *repl*
(str "globalThis." (munge *cljs-ns*) "."))
(alias-munge alias) "."
(munged-name sn)))
(let [ns (namespace expr)
munged (munge ns)
nm (name expr)]
Expand Down Expand Up @@ -592,6 +597,7 @@
(when-not (or (= 'squint.core libname)
(= 'cherry.core libname))
(let [env (expr-env env)
original-libname libname
libname (resolve-ns env libname)
[libname suffix] (str/split (if (string? libname) libname (str libname)) #"\$" 2)
default? (= "default" suffix) ;; we only support a default suffix for now anyway
Expand Down Expand Up @@ -674,8 +680,11 @@
(swap! (:ns-state env)
(fn [ns-state]
(let [current (:current ns-state)]
(update-in ns-state [current :aliases] (fn [aliases]
((fnil assoc {}) aliases as libname)))))))
(-> ns-state
(update-in [current :aliases] (fn [aliases]
((fnil assoc {}) aliases as libname)))
(update-in [current :libname->alias] (fn [m]
((fnil assoc {}) m (str original-libname) as))))))))
(when-not (:elide-imports env)
expr)
#_nil)))
Expand Down
6 changes: 6 additions & 0 deletions test-project/src/macros.cljc
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
(ns macros
#?(:cljs (:require ["node:fs" :as fs])))

(defn add-100 [x]
(+ x 100))

(defmacro with-add-100 [x]
`(add-100 ~x))

(defmacro debug [_kwd body]
`(println ::debug ~body))

Expand Down
7 changes: 5 additions & 2 deletions test-project/src/main.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns main
(:require-macros [macros :as m :refer [debug]]
(:require-macros [macros :as m :refer [debug with-add-100]]
[macros2 :refer [also]])
(:require [other-ns]
(:require [macros :as mac]
[other-ns]
[my-other-src :as src]
["fs" :as fs]
["path" :as path]
Expand All @@ -28,3 +29,5 @@
println)

(js/console.log json)

(println "qualified test:" (m/with-add-100 42))
Loading