diff --git a/CHANGELOG.md b/CHANGELOG.md index 218cf6d7..4716f0c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/package.json b/package.json index 6048cd8d..168fec2a 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" + } } diff --git a/src/squint/compiler_common.cljc b/src/squint/compiler_common.cljc index 42e7d350..617265b2 100644 --- a/src/squint/compiler_common.cljc +++ b/src/squint/compiler_common.cljc @@ -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) diff --git a/test/squint/compiler_test.cljs b/test/squint/compiler_test.cljs index f7397fd0..5823224d 100644 --- a/test/squint/compiler_test.cljs +++ b/test/squint/compiler_test.cljs @@ -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