diff --git a/src/squint/compiler_common.cljc b/src/squint/compiler_common.cljc index dc2b1893..a8aa4af9 100644 --- a/src/squint/compiler_common.cljc +++ b/src/squint/compiler_common.cljc @@ -708,19 +708,6 @@ break;}" body) (wrap-iife)) (emit-return outer-env))))) -#_(defmethod emit-special 'funcall [_type env [fname & args :as _expr]] - (-> (emit-wrap (str - (emit fname (expr-env env)) - ;; this is needed when calling keywords, symbols, etc. We could - ;; optimize this later by inferring that we're not directly - ;; calling a `function`. - #_(when-not interop? ".call") - (comma-list (emit-args env - args #_(if interop? args - (cons nil args))))) - env) - (emit-repl env))) - (defmethod emit-special 'funcall [_type env [fname & args :as _expr]] (let [ns (when (symbol? fname) (namespace fname)) fname (if ns (symbol (munge ns) (name fname)) diff --git a/test-resources/alias_conflict_test.cljs b/test-resources/alias_conflict_test.cljs new file mode 100644 index 00000000..eaefdb6d --- /dev/null +++ b/test-resources/alias_conflict_test.cljs @@ -0,0 +1,4 @@ +(ns alias-conflict-test (:require ["fs" :as _])) +(prn [(vec (map - [1 2 3])) + (_/existsSync "README.md") + (apply - [1 2 (- 10 1)])]) diff --git a/test/squint/compiler_test.cljs b/test/squint/compiler_test.cljs index f488c579..e80cb167 100644 --- a/test/squint/compiler_test.cljs +++ b/test/squint/compiler_test.cljs @@ -6,7 +6,8 @@ [squint.jsx-test] [squint.string-test] [squint.test-utils :refer [eq js! jss! jsv!]] - ["fs" :as fs])) + ["fs" :as fs] + ["child_process" :as process])) (deftest return-test (is (str/includes? (jss! '(do (def x (do 1 2 nil)))) @@ -1460,5 +1461,14 @@ (deftest bit-and-or (is (= 3 (jsv! "(+ (bit-and 1 2 3) (bit-or 1 2 3))")))) +(deftest alias-conflict-test + (let [expr (fs/readFileSync "test-resources/alias_conflict_test.cljs" "UTF-8") + js (:javascript (compiler/compile-string* expr {:core-alias "squint_core"}))] + (when (not (fs/existsSync "test-output")) + (fs/mkdirSync "test-output")) + (fs/writeFileSync "test-output/foo.mjs" js) + (is (str/includes? (process/execSync "node test-output/foo.mjs") + "[[1,2,3],true,-10]")))) + (defn init [] (t/run-tests 'squint.compiler-test 'squint.jsx-test 'squint.string-test)) diff --git a/test/squint/test_utils.cljs b/test/squint/test_utils.cljs index 96867259..1f8d595e 100644 --- a/test/squint/test_utils.cljs +++ b/test/squint/test_utils.cljs @@ -29,18 +29,26 @@ (set! js/process.exitCode 1) (old-error m)) -(defn jss! [expr] - (if (string? expr) - (:body (squint/compile-string* expr {:elide-imports true - :core-alias "squint_core"})) - (squint/transpile-form expr {:elide-imports true - :core-alias "squint_core"}))) - -(defn js! [expr] - (let [js (jss! expr)] - [(js/eval js) js])) - -(defn jsv! [expr] - (first (js! expr))) +(defn jss! + ([expr] (jss! expr nil)) + ([expr opts] + (if (string? expr) + (:body (squint/compile-string* expr (merge {:elide-imports true + :core-alias "squint_core"} + opts))) + (squint/transpile-form expr (merge {:elide-imports true + :core-alias "squint_core"} + opts))))) + +(defn js! + ([expr] (js! expr nil)) + ([expr opts] + (let [js (jss! expr opts)] + [(js/eval js) js]))) + +(defn jsv! + ([expr] (jsv! expr nil)) + ([expr opts] + (first (js! expr opts))))