diff --git a/src/main/clojure/cljs/analyzer.cljc b/src/main/clojure/cljs/analyzer.cljc index 6759c6d24..0c3220d39 100644 --- a/src/main/clojure/cljs/analyzer.cljc +++ b/src/main/clojure/cljs/analyzer.cljc @@ -159,6 +159,7 @@ :protocol-impl-recur-with-target true :single-segment-namespace true :munged-namespace true + :js-used-as-alias true :ns-var-clash true :non-dynamic-earmuffed-var true :extend-type-invalid-method-shape true @@ -177,6 +178,7 @@ (::externs @env/*compiler*)) (defn checked-arrays + "Returns false-y, :warn, or :error based on configuration and the "Returns false-y, :warn, or :error based on configuration and the current value of *unchecked-arrays*." [] @@ -439,6 +441,10 @@ (str "Namespace " name " contains a reserved JavaScript keyword," " the corresponding Google Closure namespace will be munged to " munged))) +(defmethod error-message :js-used-as-alias + [warning-type {:keys [spec] :as info}] + (str \"In \" (pr-str spec) \", the alias name js is reserved for JavaScript interop\")) + (defmethod error-message :ns-var-clash [warning-type {:keys [ns var] :as info}] (str "Namespace " ns " clashes with var " var)) @@ -2994,6 +3000,9 @@ lib' ((alias-type @aliases) alias)] (when (and (some? lib') (not= lib lib')) (throw (error env (parse-ns-error-msg spec ":as alias must be unique")))) + (when (= alias 'js) + (when-not (= lib (get-in @aliases [(if macros? :fns :macros) 'js])) ; warn only once + (warning :js-used-as-alias env {:spec spec}))) (swap! aliases update-in [alias-type] conj [alias lib] (when js-module-provides [js-module-provides lib])))) diff --git a/src/test/clojure/cljs/analyzer_tests.clj b/src/test/clojure/cljs/analyzer_tests.clj index 8ae750ddc..e96b6ae3f 100644 --- a/src/test/clojure/cljs/analyzer_tests.clj +++ b/src/test/clojure/cljs/analyzer_tests.clj @@ -1493,6 +1493,13 @@ (:import goog))])) (is (= {} (get-in @cenv [::ana/namespaces 'test.foo :imports]))))) +(deftest test-cljs-3320 + (let [ws (atom [])] + (ana/with-warning-handlers [(collecting-warning-handler ws)] + (binding [ana/*cljs-ns* 'cljs.user] + (analyze ns-env '(ns cljs3320.core (:require [cljs.js :as js]))))) + (is (string/includes? (first @ws) "the alias name js is reserved for JavaScript interop")))) + (deftest test-cljs-3371 (let [ws (atom [])] (ana/with-warning-handlers [(collecting-warning-handler ws)]