Skip to content

Commit

Permalink
CLJS-646: single segment namespaces and reify don't work
Browse files Browse the repository at this point in the history
the exists? call in reify was not correct, it was a property access on
the namespace, which would of course get resolved by the compiler,
creating a symbol foo/foo (in the case where foo is the single segment
namespace). now we actually emit a symbol of the namespace and the type
symbol, the exists? macro now annotates this symbol with
:cljs.analyzer/no-resolve, the analyzer now respects this so the user
won't get spurious warnings from using exists? on vars that don't exist.
  • Loading branch information
swannodette committed Oct 29, 2013
1 parent d03c15b commit 85ac96e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/clj/cljs/analyzer.clj
Expand Up @@ -247,7 +247,9 @@
:ns full-ns})))))))

(defn resolve-existing-var [env sym]
(resolve-var env sym confirm-var-exists))
(if-not (-> sym meta ::no-resolve)
(resolve-var env sym confirm-var-exists)
(resolve-var env sym)))

(defn confirm-bindings [env names]
(doseq [name names]
Expand Down
7 changes: 5 additions & 2 deletions src/clj/cljs/core.clj
Expand Up @@ -279,8 +279,11 @@
(defmacro string? [x]
(bool-expr (list 'js* "typeof ~{} === 'string'" x)))

;; TODO: x must be a symbol, not an arbitrary expression
(defmacro exists? [x]
(bool-expr (list 'js* "typeof ~{} !== 'undefined'" x)))
(bool-expr
(list 'js* "typeof ~{} !== 'undefined'"
(vary-meta x assoc :cljs.analyzer/no-resolve true))))

(defmacro undefined? [x]
(bool-expr (list 'js* "(void 0 === ~{})" x)))
Expand Down Expand Up @@ -576,7 +579,7 @@
ns (-> &env :ns :name)
munge cljs.compiler/munge]
`(do
(when-not (exists? (. ~ns ~(symbol (core/str "-" t))))
(when-not (exists? ~(symbol (core/str ns) (core/str t)))
(deftype ~t [~@locals ~meta-sym]
IWithMeta
(~'-with-meta [~this-sym ~meta-sym]
Expand Down

0 comments on commit 85ac96e

Please sign in to comment.