diff --git a/deps.edn b/deps.edn index 2bc77d6..eb0f577 100644 --- a/deps.edn +++ b/deps.edn @@ -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"}}} diff --git a/src/cherry/compiler.cljc b/src/cherry/compiler.cljc index 47642af..e96fc89 100644 --- a/src/cherry/compiler.cljc +++ b/src/cherry/compiler.cljc @@ -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 diff --git a/test/cherry/compiler_test.cljs b/test/cherry/compiler_test.cljs index c578754..ff3b782 100644 --- a/test/cherry/compiler_test.cljs +++ b/test/cherry/compiler_test.cljs @@ -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]])) @@ -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'")) + (is (str/includes? s "clojure_core_some_fn.call(null)")))) + (defn init [] (cljs.test/run-tests 'cherry.compiler-test 'cherry.jsx-test))