Skip to content

Commit b12d836

Browse files
mfikesdnolen
authored and
dnolen
committed
CLJS-1478: Self-host: Allow static-fns opt
Bind cljs.analyzer/*cljs-static-fns* with :static-fns opts value in all API entry points. Test compilation and evaluation with respect to :static-fns in self-host mode.
1 parent 5ebb3ad commit b12d836

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/main/cljs/cljs/js.cljs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@
440440
((fn analyze-loop [last-ast ns]
441441
(binding [env/*compiler* (:*compiler* bound-vars)
442442
ana/*cljs-ns* ns
443+
ana/*cljs-static-fns* (:static-fns opts)
443444
*ns* (create-ns ns)
444445
ana/*passes* (:*passes* bound-vars)
445446
r/*data-readers* (:*data-readers* bound-vars)
@@ -527,6 +528,7 @@
527528
(binding [env/*compiler* (:*compiler* bound-vars)
528529
*eval-fn* (:*eval-fn* bound-vars)
529530
ana/*cljs-ns* (:*cljs-ns* bound-vars)
531+
ana/*cljs-static-fns* (:static-fns opts)
530532
*ns* (create-ns (:*cljs-ns* bound-vars))
531533
r/*data-readers* (:*data-readers* bound-vars)
532534
r/resolve-symbol ana/resolve-symbol
@@ -601,6 +603,7 @@
601603
(binding [env/*compiler* (:*compiler* bound-vars)
602604
*eval-fn* (:*eval-fn* bound-vars)
603605
ana/*cljs-ns* ns
606+
ana/*cljs-static-fns* (:static-fns opts)
604607
*ns* (create-ns ns)
605608
r/*data-readers* (:*data-readers* bound-vars)
606609
r/resolve-symbol ana/resolve-symbol
@@ -694,6 +697,7 @@
694697
(binding [env/*compiler* (:*compiler* bound-vars)
695698
*eval-fn* (:*eval-fn* bound-vars)
696699
ana/*cljs-ns* ns
700+
ana/*cljs-static-fns* (:static-fns opts)
697701
*ns* (create-ns ns)
698702
r/*data-readers* (:*data-readers* bound-vars)
699703
r/resolve-symbol ana/resolve-symbol

src/test/self/self_host/test.cljs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
(:require [cljs.test :as test
33
:refer-macros [run-tests deftest testing is async]]
44
[cljs.js :as cljs]
5+
[clojure.string :as string]
56
[cljs.nodejs :as nodejs]))
67

78
(set! (.-user js/cljs) #js {})
@@ -66,7 +67,7 @@
6667

6768
(deftest test-compile-str
6869
(async done
69-
(let [l (latch 4 done)]
70+
(let [l (latch 6 done)]
7071
(cljs/compile-str st "(+ 1 1)"
7172
(fn [{:keys [error value]}]
7273
(is (nil? error))
@@ -89,11 +90,24 @@
8990
(fn [{:keys [error value]}]
9091
(is (nil? error))
9192
(is (= "\"a\".toString()" value))
93+
(inc! l)))
94+
(cljs/compile-str st "(do (defn foo [a b] (+ a b)) (foo 1 2))" nil
95+
{:context :expr}
96+
(fn [{:keys [error value]}]
97+
(is (nil? error))
98+
(is (string/index-of value "cljs.user.foo.call(null,1,2)"))
99+
(inc! l)))
100+
(cljs/compile-str st "(do (defn foo [a b] (+ a b)) (foo 1 2))" nil
101+
{:context :expr
102+
:static-fns true}
103+
(fn [{:keys [error value]}]
104+
(is (nil? error))
105+
(is (string/index-of value "cljs.user.foo(1,2)"))
92106
(inc! l))))))
93107

94108
(deftest test-eval-str
95109
(async done
96-
(let [l (latch 7 done)]
110+
(let [l (latch 8 done)]
97111
(cljs/eval-str st "(+ 1 1)" nil
98112
{:eval node-eval}
99113
(fn [{:keys [error value]}]
@@ -140,6 +154,15 @@
140154
(is (nil? error))
141155
(is (== 3 (js/cljs.user.foo 1 2)))
142156
(inc! l)))
157+
(cljs/eval-str st "(do (defn foo [a b] (+ a b)) (foo 1 2))" nil
158+
{:eval node-eval
159+
:context :expr
160+
:def-emits-var true
161+
:static-fns true}
162+
(fn [{:keys [error value]}]
163+
(is (nil? error))
164+
(is (== 3 value))
165+
(inc! l)))
143166
(cljs/eval-str st "(def foo (let [x 1] (let [x (inc x)] x)))" nil
144167
{:eval node-eval
145168
:context :statement

0 commit comments

Comments
 (0)