Skip to content

Commit 962a88b

Browse files
authored
Fix #669: munge refer-ed + renamed var (#670)
1 parent 1ecbf7f commit 962a88b

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## v0.8.148
6+
7+
- Fix [#669](https://github.com/squint-cljs/squint/issues/669): munge refer-ed + renamed var
8+
59
## v0.8.147
610

711
- Fix [#661](https://github.com/squint-cljs/squint/issues/661): support `throw` in expression position

src/squint/compiler_common.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@
584584
(str "." suffix)
585585
"")))
586586
(str/join (map (fn [sym]
587-
(statement (str "globalThis." (munge current-ns-name) "." sym " = " sym)))
587+
(let [sym (munge sym)]
588+
(statement (str "globalThis." (munge current-ns-name) "." sym " = " sym))))
588589
(map (fn [refer]
589590
(get rename refer refer))
590591
refer))))

test/squint/compiler_test.cljs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,11 +1718,13 @@
17181718
(is (and
17191719
(str/includes? s "existsSync as exists")
17201720
(str/includes? s "exists(\"README.md\")"))))
1721-
(let [s (squint/compile-string "(ns test-namespace (:require [\"some-js-library\" :refer [existsSync] :rename {existsSync exists}])) (exists \"README.md\")"
1721+
(let [s (squint/compile-string "(ns test-namespace (:require [\"some-js-library\" :refer [existsSync] :rename {existsSync foo-bar}])) (foo-bar \"README.md\")"
17221722
{:repl true})]
1723+
(println s)
17231724
(is (and
1724-
(str/includes? s "existsSync: exists")
1725-
(str/includes? s "globalThis.test_namespace.exists(\"README.md\")"))))
1725+
(str/includes? s "existsSync: foo_bar")
1726+
(str/includes? s "globalThis.test_namespace.foo_bar(\"README.md\")")))
1727+
(is (not (str/includes? s "foo-bar") )))
17261728
(testing "alias + refer"
17271729
(let [s (squint/compile-string "(ns foo (:require [\"node:fs\" :as \"fs\" :refer [existsSync]]))")]
17281730
(is (and
@@ -2352,7 +2354,6 @@ new Foo();")
23522354
:context (if return?
23532355
:return
23542356
:statement)})]
2355-
(println javascript)
23562357
(is (str/includes? pragmas "use client"))
23572358
(is (str/includes? pragmas "// ts-check"))
23582359
(is (not (str/includes? pragmas ";")))

0 commit comments

Comments
 (0)