Permalink
Browse files

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.
  • Loading branch information...
mfikes authored and swannodette committed Nov 3, 2015
1 parent 5ebb3ad commit b12d836eff32232ddb20cca274cf34835e0fd7c7
Showing with 29 additions and 2 deletions.
  1. +4 −0 src/main/cljs/cljs/js.cljs
  2. +25 −2 src/test/self/self_host/test.cljs
@@ -440,6 +440,7 @@
((fn analyze-loop [last-ast ns]
(binding [env/*compiler* (:*compiler* bound-vars)
ana/*cljs-ns* ns
ana/*cljs-static-fns* (:static-fns opts)
*ns* (create-ns ns)
ana/*passes* (:*passes* bound-vars)
r/*data-readers* (:*data-readers* bound-vars)
@@ -527,6 +528,7 @@
(binding [env/*compiler* (:*compiler* bound-vars)
*eval-fn* (:*eval-fn* bound-vars)
ana/*cljs-ns* (:*cljs-ns* bound-vars)
ana/*cljs-static-fns* (:static-fns opts)
*ns* (create-ns (:*cljs-ns* bound-vars))
r/*data-readers* (:*data-readers* bound-vars)
r/resolve-symbol ana/resolve-symbol
@@ -601,6 +603,7 @@
(binding [env/*compiler* (:*compiler* bound-vars)
*eval-fn* (:*eval-fn* bound-vars)
ana/*cljs-ns* ns
ana/*cljs-static-fns* (:static-fns opts)
*ns* (create-ns ns)
r/*data-readers* (:*data-readers* bound-vars)
r/resolve-symbol ana/resolve-symbol
@@ -694,6 +697,7 @@
(binding [env/*compiler* (:*compiler* bound-vars)
*eval-fn* (:*eval-fn* bound-vars)
ana/*cljs-ns* ns
ana/*cljs-static-fns* (:static-fns opts)
*ns* (create-ns ns)
r/*data-readers* (:*data-readers* bound-vars)
r/resolve-symbol ana/resolve-symbol
@@ -2,6 +2,7 @@
(:require [cljs.test :as test
:refer-macros [run-tests deftest testing is async]]
[cljs.js :as cljs]
[clojure.string :as string]
[cljs.nodejs :as nodejs]))
(set! (.-user js/cljs) #js {})
@@ -66,7 +67,7 @@
(deftest test-compile-str
(async done
(let [l (latch 4 done)]
(let [l (latch 6 done)]
(cljs/compile-str st "(+ 1 1)"
(fn [{:keys [error value]}]
(is (nil? error))
@@ -89,11 +90,24 @@
(fn [{:keys [error value]}]
(is (nil? error))
(is (= "\"a\".toString()" value))
(inc! l)))
(cljs/compile-str st "(do (defn foo [a b] (+ a b)) (foo 1 2))" nil
{:context :expr}
(fn [{:keys [error value]}]
(is (nil? error))
(is (string/index-of value "cljs.user.foo.call(null,1,2)"))
(inc! l)))
(cljs/compile-str st "(do (defn foo [a b] (+ a b)) (foo 1 2))" nil
{:context :expr
:static-fns true}
(fn [{:keys [error value]}]
(is (nil? error))
(is (string/index-of value "cljs.user.foo(1,2)"))
(inc! l))))))
(deftest test-eval-str
(async done
(let [l (latch 7 done)]
(let [l (latch 8 done)]
(cljs/eval-str st "(+ 1 1)" nil
{:eval node-eval}
(fn [{:keys [error value]}]
@@ -140,6 +154,15 @@
(is (nil? error))
(is (== 3 (js/cljs.user.foo 1 2)))
(inc! l)))
(cljs/eval-str st "(do (defn foo [a b] (+ a b)) (foo 1 2))" nil
{:eval node-eval
:context :expr
:def-emits-var true
:static-fns true}
(fn [{:keys [error value]}]
(is (nil? error))
(is (== 3 value))
(inc! l)))
(cljs/eval-str st "(def foo (let [x 1] (let [x (inc x)] x)))" nil
{:eval node-eval
:context :statement

0 comments on commit b12d836

Please sign in to comment.