Skip to content

Commit

Permalink
CLJS-1577: Self-host: syntax-quote resolves on dot forms
Browse files Browse the repository at this point in the history
If you try to evaluate a syntax-quoted dot form, as in `.x, by default
symbol resolution will be applied to the dot form .x, yielding /x.
Instead, we need this to yield just .x. To do this, revise cljs.js
to check for this case before delegating to cljs.analyzer/resolve-symbol.
  • Loading branch information
mfikes authored and dnolen committed Feb 23, 2016
1 parent ea40068 commit 22a2692
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main/cljs/cljs/js.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
0 (- (count file) 5))]
(symbol (demunge lib-name))))

(defn- resolve-symbol
[sym]
(if (string/starts-with? (str sym) ".")
sym
(ana/resolve-symbol sym)))

(defn- atom? [x]
(instance? Atom x))

Expand Down Expand Up @@ -444,7 +450,7 @@
*ns* (create-ns ns)
ana/*passes* (:*passes* bound-vars)
r/*data-readers* (:*data-readers* bound-vars)
r/resolve-symbol ana/resolve-symbol
r/resolve-symbol resolve-symbol
comp/*source-map-data* (:*sm-data* bound-vars)]
(let [res (try
{:value (r/read {:eof eof :read-cond :allow :features #{:cljs}} rdr)}
Expand Down Expand Up @@ -531,7 +537,7 @@
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
r/resolve-symbol resolve-symbol
comp/*source-map-data* (:*sm-data* bound-vars)]
(let [aenv (ana/empty-env)
aenv (cond-> (assoc aenv :ns (ana/get-namespace ana/*cljs-ns*))
Expand Down Expand Up @@ -606,7 +612,7 @@
ana/*cljs-static-fns* (:static-fns opts)
*ns* (create-ns ns)
r/*data-readers* (:*data-readers* bound-vars)
r/resolve-symbol ana/resolve-symbol
r/resolve-symbol resolve-symbol
comp/*source-map-data* (:*sm-data* bound-vars)]
(let [res (try
{:value (r/read {:eof eof :read-cond :allow :features #{:cljs}} rdr)}
Expand Down Expand Up @@ -704,7 +710,7 @@
ana/*cljs-static-fns* (:static-fns opts)
*ns* (create-ns ns)
r/*data-readers* (:*data-readers* bound-vars)
r/resolve-symbol ana/resolve-symbol
r/resolve-symbol resolve-symbol
comp/*source-map-data* (:*sm-data* bound-vars)]
(let [res (try
{:value (r/read {:eof eof :read-cond :allow :features #{:cljs}} rdr)}
Expand Down
26 changes: 26 additions & 0 deletions src/test/self/self_host/test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,32 @@
(is (nil? error))
(is (= "90°" value)))))

(deftest test-CLJS-1577
(cljs/analyze-str st
"`.x"
nil
{:eval node-eval
:context :expr}
(fn [{:keys [error value]}]
(is (nil? error))
(is (= '.x (:form value)))))
(cljs/compile-str st
"`.x"
nil
{:eval node-eval
:context :expr}
(fn [{:keys [error value]}]
(is (nil? error))
(is (string/starts-with? value "new cljs.core.Symbol(null,\".x\",\".x\","))))
(cljs/eval-str st
"`.x"
nil
{:eval node-eval
:context :expr}
(fn [{:keys [error value]}]
(is (nil? error))
(is (= '.x value)))))

(deftest test-CLJS-1584
(cljs/eval-str st
"(condp = 1 1 2)"
Expand Down

0 comments on commit 22a2692

Please sign in to comment.