From 85ac96e3e2de4a3598c1658f7c1de6cf88734d93 Mon Sep 17 00:00:00 2001 From: David Nolen Date: Tue, 29 Oct 2013 18:45:28 -0400 Subject: [PATCH] CLJS-646: single segment namespaces and reify don't work 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. --- src/clj/cljs/analyzer.clj | 4 +++- src/clj/cljs/core.clj | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/clj/cljs/analyzer.clj b/src/clj/cljs/analyzer.clj index 0b9920e494..4d3cb6ff18 100644 --- a/src/clj/cljs/analyzer.clj +++ b/src/clj/cljs/analyzer.clj @@ -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] diff --git a/src/clj/cljs/core.clj b/src/clj/cljs/core.clj index 87149eba77..1e76b4d7a2 100644 --- a/src/clj/cljs/core.clj +++ b/src/clj/cljs/core.clj @@ -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))) @@ -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]