Skip to content
Closed
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 deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
org.babashka/cli {:mvn/version "0.3.32"}
org.babashka/sci {:mvn/version "0.3.32"}
io.github.squint-cljs/compiler-common
{:git/sha "06666157fc052e9efae597ec6e811cb0292c2de2"}}
{:git/sha "868c16ed27de6193dfb2bf3a9019704d5525213d"}}
:aliases
{:dev {:extra-deps {io.github.squint-cljs/compiler-common
{:local/root "compiler-common"}}}
Expand Down
6 changes: 4 additions & 2 deletions src/cherry/compiler.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@


(defmethod emit-special 'funcall [_type env [fname & args :as _expr]]
(let [interop? (and (symbol? fname)
(= "js" (namespace fname)))]
(let [ns (namespace fname)
fname (symbol (munge ns) (name fname))
interop? (and (symbol? fname)
(= "js" ns))]
(emit-wrap (str
(emit fname (expr-env env))
;; this is needed when calling keywords, symbols, etc. We could
Expand Down
18 changes: 18 additions & 0 deletions test/cherry/compiler_test.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns cherry.compiler-test
(:require
[cherry.jsx-test]
[cherry.compiler :as cherry]
[cherry.test-utils :refer [js! jss! jsv!]]
[clojure.string :as str]
[clojure.test :as t :refer [async deftest is]]))
Expand Down Expand Up @@ -331,5 +332,22 @@
(deftest try-catch-test
(is (= 2 (jsv! '(try (assoc :foo 1 2) (catch :default _ 2))))))

(deftest require-with-kebab-case-alias-test
(let [s (cherry/compile-string "(ns test-namespace (:require [\"some-js-library$default\" :as some-js-lib])) (some-js-lib/some_fn)")]
(is (str/includes? s "import { some_fn as some_js_lib_some_fn } from 'some-js-library$default'"))
(is (str/includes? s "some_js_lib_some_fn.call(null)")))

(let [s (cherry/compile-string "(ns test-namespace (:require [\"some-js-library\" :as some-js-lib])) (some-js-lib/some_fn)")]
(is (str/includes? s "import { some_fn as some_js_lib_some_fn } from 'some-js-library'"))
(is (str/includes? s "some_js_lib_some_fn.call(null)")))

(let [s (cherry/compile-string "(ns test-namespace (:require [\"./local_file.mjs\" :as local-file])) (local-file/some_fn)")]
(is (str/includes? s "import { some_fn as local_file_some_fn } from './local_file.mjs'"))
(is (str/includes? s "local_file_some_fn.call(null)")))

(let [s (cherry/compile-string "(ns test-namespace (:require [clojure.core :as clojure-core])) (clojure-core/some-fn)")]
(is (str/includes? s "import { some_fn as clojure_core_some_fn } from 'clojure-core'"))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Cherry didn't previously support requiring Clojure namespaces, I wasn't sure what the output here should be

(is (str/includes? s "clojure_core_some_fn.call(null)"))))

(defn init []
(cljs.test/run-tests 'cherry.compiler-test 'cherry.jsx-test))