Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CLJS-680: function name shadows JavaScript globals

Change cljs.analyzer/empty-env so we add a :js-globals entry. Change
parse fn* so that we check this for :shadow. Reformat emit-fn-method.
  • Loading branch information...
commit 08b310f24b184d39082eac91b1d8a2dba7ae38af 1 parent b3db8e7
@swannodette swannodette authored
Showing with 22 additions and 19 deletions.
  1. +11 −2 src/clj/cljs/analyzer.clj
  2. +11 −17 src/clj/cljs/compiler.clj
View
13 src/clj/cljs/analyzer.clj
@@ -210,8 +210,16 @@
*cljs-macros-is-classpath* false]
~@body)))
+(defn js-globals [syms]
+ (into {}
+ (map #(vector % {:name %}) syms)))
+
(defn empty-env []
- {:ns (get-namespace *cljs-ns*) :context :statement :locals {}})
+ (env/ensure
+ {:ns (get-namespace *cljs-ns*)
+ :context :statement
+ :locals {}
+ :js-globals (js-globals '(alert window document))}))
(defmacro ^:private debug-prn
[& args]
@@ -561,7 +569,8 @@
locals (:locals env)
name-var (if name
{:name name
- :shadow (locals name)
+ :info {:shadow (or (locals name)
+ (get-in env [:js-globals name]))}
:tag (-> name meta :tag)})
locals (if (and locals name) (assoc locals name name-var) locals)
type (-> form meta ::type)
View
28 src/clj/cljs/compiler.clj
@@ -451,23 +451,17 @@
(defn emit-fn-method
[{:keys [type name variadic params expr env recurs max-fixed-arity]}]
(emit-wrap env
- ; Should we emit source-map for this inner declaration?
- ; It may be unnecessary.
- ; hello.core.greet = (function greet(){})
- ; e.g. Do we need a source-map entry for this? --^
-
- ; If so, we can't just munge the name and spit out a string.
- (emits "(function " (munge name) "(")
- (emit-fn-params params)
- (emits "){")
- (when type
- (emitln "var self__ = this;"))
- (when recurs (emitln "while(true){"))
- (emits expr)
- (when recurs
- (emitln "break;")
- (emitln "}"))
- (emits "})")))
+ (emits "(function " (munge name) "(")
+ (emit-fn-params params)
+ (emits "){")
+ (when type
+ (emitln "var self__ = this;"))
+ (when recurs (emitln "while(true){"))
+ (emits expr)
+ (when recurs
+ (emitln "break;")
+ (emitln "}"))
+ (emits "})")))
(defn emit-variadic-fn-method
[{:keys [type name variadic params expr env recurs max-fixed-arity] :as f}]
Please sign in to comment.
Something went wrong with that request. Please try again.