Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CLJS-528: Warns on any attempted extension of protocols to base JavaS…

…cript types, using the new warning system.
  • Loading branch information...
commit 6d9ba920ccd5c364df847a9633c1c6c614917981 1 parent 2daf0f4
@rupss rupss authored swannodette committed
Showing with 19 additions and 1 deletion.
  1. +7 −1 src/clj/cljs/analyzer.clj
  2. +12 −0 src/clj/cljs/core.clj
View
8 src/clj/cljs/analyzer.clj
@@ -41,7 +41,8 @@
:invalid-protocol-symbol true
:multiple-variadic-overloads true
:variadic-max-arity true
- :overload-arity true})
+ :overload-arity true
+ :extending-base-js-type true})
(declare message namespaces)
@@ -107,6 +108,11 @@
[warning-type extra]
(str (:name extra) ": Can't have 2 overloads with same arity"))
+(defmethod default-warning-handler* :extending-base-js-type
+ [warning-type extra]
+ (str "Extending an existing JavaScript type - use a different symbol name "
+ "instead of " (:current-symbol extra) " e.g " (:suggested-symbol extra)))
+
(defn ^:private default-warning-handler [warning-type env extra]
(when (warning-type *cljs-warnings*)
(when-let [s (default-warning-handler* warning-type extra)]
View
12 src/clj/cljs/core.clj
@@ -572,6 +572,14 @@
'boolean "boolean"
'default "_"})
+(def #^:private js-base-type
+ {'js/Boolean "boolean"
+ 'js/String "string"
+ 'js/Array "array"
+ 'js/Object "object"
+ 'js/Number "number"
+ 'js/Function "function"})
+
(defmacro reify [& impls]
(let [t (gensym "t")
meta-sym (gensym "meta")
@@ -736,6 +744,10 @@
[type assign-impls] (if-let [type (base-type type-sym)]
[type base-assign-impls]
[(resolve type-sym) proto-assign-impls])]
+ (when (and (:extending-base-js-type cljs.analyzer/*cljs-warnings*)
+ (js-base-type type-sym))
+ (cljs.analyzer/warning :extending-base-js-type env
+ {:current-symbol type-sym :suggested-symbol (js-base-type type-sym)}))
`(do ~@(mapcat #(assign-impls env resolve type-sym type %) impl-map))))
(defn- prepare-protocol-masks [env impls]
Please sign in to comment.
Something went wrong with that request. Please try again.