Skip to content

Commit

Permalink
Fix #563: prioritize refer over core built-in (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored Oct 17, 2024
1 parent a558881 commit 757982b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

[Squint](https://github.com/squint-cljs/squint): Light-weight ClojureScript dialect

## v0.8.117 (2024-10-17)

- Fix [#563](https://github.com/squint-cljs/squint/issues/563): prioritize refer over core built-in

## v0.8.117 (2024-10-11)

- BREAKING: Dynamic CSS in `#html` must now be explicitly passed as map literal: `(let [m {:color :green}] #html [:div {:style {:& m}}])`. Fixes issue when using `lit-html` in combination with `classMap`. See [demo](https://squint-cljs.github.io/squint/?src=KG5zIG15bGl0CiAgKDpyZXF1aXJlIFtzcXVpbnQuY29yZSA6cmVmZXIgW2RlZmNsYXNzIGpzLXRlbXBsYXRlXV0KICAgWyJodHRwczovL2VzbS5zaC9saXRAMy4wLjAiIDphcyBsaXRdCiAgIFsiaHR0cHM6Ly9lc20uc2gvbGl0QDMuMC4wL2RpcmVjdGl2ZXMvY2xhc3MtbWFwLmpzIiA6cmVmZXIgW2NsYXNzTWFwXV0pKQoKKGRlZmNsYXNzIE15RWxlbWVudAogIChleHRlbmRzIGxpdC9MaXRFbGVtZW50KQogICheOnN0YXRpYyBmaWVsZCBwcm9wZXJ0aWVzIHs6Y291bnQge319KQoKICAoY29uc3RydWN0b3IgW3RoaXNdCiAgICAoc3VwZXIpCiAgICAoc2V0ISB0aGlzLmNvdW50IDApCiAgICAoc2V0ISB0aGlzLm5hbWUgIkhlbGxvIikpCgogIE9iamVjdAogIChyZW5kZXIgW3RoaXNdCiAgICAjaHRtbCBebGl0L2h0bWwKICAgIFs6ZGl2CiAgICAgWzpoMSB7OmNsYXNzIChjbGFzc01hcCB7OmVuYWJsZWQgdHJ1ZX0pfQogICAgICB0aGlzLm5hbWVdCiAgICAgWzpidXR0b24geyJAY2xpY2siIHRoaXMub25DbGljawogICAgICAgICAgICAgICA6cGFydCAiYnV0dG9uIn0KICAgICAgIkNsaWNrIGNvdW50ICIgdGhpcy5jb3VudF1dKQoKICAob25DbGljayBbdGhpc10KICAgIChzZXQhIHRoaXMuY291bnQgKGluYyB0aGlzLmNvdW50KSkpKQoKKGRlZm9uY2UgZm9vCiAgKGRvCiAgICAoanMvd2luZG93LmN1c3RvbUVsZW1lbnRzLmRlZmluZSAibXktZWxlbWVudCIgTXlFbGVtZW50KQogICAgdHJ1ZSkpCgooZGVmIGFwcCAob3IgKGpzL2RvY3VtZW50LnF1ZXJ5U2VsZWN0b3IgIiNhcHAiKQogICAgICAgICAgIChkb3RvIChqcy9kb2N1bWVudC5jcmVhdGVFbGVtZW50ICJkaXYiKQogICAgICAgICAgICAgKHNldCEgLWlkICJhcHAiKQogICAgICAgICAgICAgKGpzL2RvY3VtZW50LmJvZHkucHJlcGVuZCkpKSkKCihzZXQhICguLWlubmVySFRNTCBhcHApICNodG1sIFs6ZGl2CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBbOm15LWVsZW1lbnRdCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAjX1s6bXktZWxlbWVudF1dKQ%3D%3D)
Expand Down
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"chalk": "^5.0.1",
"esbuild": "^0.14.49",
"eslint": "^8.54.0",
"jotai": "^2.10.1",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"playwright": "^1.26.1",
Expand All @@ -45,13 +46,14 @@
"url": "https://github.com/sponsors/borkdude"
}
],
"exports": {".": "./index.js",
"./index.js": "./index.js",
"./core.js": "./core.js",
"./string.js": "./string.js",
"./src/squint/core.js": "./src/squint/core.js",
"./src/squint/set.js": "./src/squint/set.js",
"./src/squint/string.js": "./src/squint/string.js",
"./src/squint/html.js": "./src/squint/html.js"
}
"exports": {
".": "./index.js",
"./index.js": "./index.js",
"./core.js": "./core.js",
"./string.js": "./string.js",
"./src/squint/core.js": "./src/squint/core.js",
"./src/squint/set.js": "./src/squint/set.js",
"./src/squint/string.js": "./src/squint/string.js",
"./src/squint/html.js": "./src/squint/html.js"
}
}
18 changes: 11 additions & 7 deletions src/squint/compiler_common.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,19 @@
(when (contains? current-ns expr)
(str (when *repl*
(str "globalThis." (munge *cljs-ns*) ".")) (munged-name expr)))
(some-> (maybe-core-var expr env) munge)
(let [renamed (:rename current-ns)
expr (get renamed expr expr)]
(when (or (contains? (:refers current-ns) expr)
(let [alias (get (:aliases current-ns) expr)]
alias))
(str (when *repl*
(str "globalThis." (munge *cljs-ns*) "."))
(munged-name expr))))
(or
(when (contains? (:refers current-ns) expr)
(str (when *repl*
(str "globalThis." (munge *cljs-ns*) "."))
(munged-name expr)))
(some-> (maybe-core-var expr env) munge)
(when (let [alias (get (:aliases current-ns) expr)]
alias)
(str (when *repl*
(str "globalThis." (munge *cljs-ns*) "."))
(munged-name expr)))))
(let [m (munged-name expr)]
m)))))]
(emit-return (escape-jsx expr env)
Expand Down
13 changes: 9 additions & 4 deletions test/squint/compiler_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1614,16 +1614,21 @@
"import './popup.css'"))
(is (re-find #"import.*'./popup.css'"
(squint/compile-string (pr-str '(ns foo (:require ["./popup.css" :as pop]))))))
(is (str/ends-with?
(str/trim (squint/compile-string "(ns foo (:require [\"fs\" :refer [readFileSync]])) readFileSync" {:repl true}))
"globalThis.foo.readFileSync;"))
(is (str/ends-with?
(str/trim (squint/compile-string "(ns foo (:require [\"some-js-lib\" :refer [atom]])) atom" {:repl true}))
"foo.atom;")))

(deftest ns-test-async
(t/async done
(let [js (squint/compile-string "(ns foo (:require [clojure.string :as str])) (str 1 2 3 (str/join \",\" [1 2 3]))" {:repl true
:context :return})]
(-> (.then (js/eval (str/replace "(async function () {\n%s\n})()" "%s" js))
(fn [v]
(is (= "1231,2,3" v))))
(.finally done))))
(is (str/ends-with?
(str/trim (squint/compile-string "(ns foo (:require [\"fs\" :refer [readFileSync]])) readFileSync" {:repl true}))
"globalThis.foo.readFileSync;")))
(.finally done)))))

(deftest global-ns-test
(t/async done
Expand Down

0 comments on commit 757982b

Please sign in to comment.