Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Oct 24, 2023
1 parent 00d33ec commit 04ab839
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
13 changes: 0 additions & 13 deletions src/squint/compiler_common.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions test-resources/alias_conflict_test.cljs
Original file line number Diff line number Diff line change
@@ -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)])])
12 changes: 11 additions & 1 deletion test/squint/compiler_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down Expand Up @@ -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))
34 changes: 21 additions & 13 deletions test/squint/test_utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))))


0 comments on commit 04ab839

Please sign in to comment.