|
68 | 68 | :protocol-invalid-method true
|
69 | 69 | :protocol-duped-method true
|
70 | 70 | :protocol-multiple-impls true
|
71 |
| - :single-segment-namespace true}) |
| 71 | + :single-segment-namespace true |
| 72 | + :munged-namespace true}) |
| 73 | + |
| 74 | +(def js-reserved |
| 75 | + #{"abstract" "boolean" "break" "byte" "case" |
| 76 | + "catch" "char" "class" "const" "continue" |
| 77 | + "debugger" "default" "delete" "do" "double" |
| 78 | + "else" "enum" "export" "extends" "final" |
| 79 | + "finally" "float" "for" "function" "goto" "if" |
| 80 | + "implements" "import" "in" "instanceof" "int" |
| 81 | + "interface" "let" "long" "native" "new" |
| 82 | + "package" "private" "protected" "public" |
| 83 | + "return" "short" "static" "super" "switch" |
| 84 | + "synchronized" "this" "throw" "throws" |
| 85 | + "transient" "try" "typeof" "var" "void" |
| 86 | + "volatile" "while" "with" "yield" "methods" |
| 87 | + "null"}) |
72 | 88 |
|
73 | 89 | (declare message namespaces)
|
74 | 90 |
|
|
184 | 200 | [warning-type info]
|
185 | 201 | (str (:name info) " is a single segment namespace"))
|
186 | 202 |
|
| 203 | +(defmethod error-message :munged-namespace |
| 204 | + [warning-type {:keys [name] :as info}] |
| 205 | + (let [munged (->> (string/split (clojure.core/name name) #"\.") |
| 206 | + (map #(if (js-reserved %) (str % "$") %)) |
| 207 | + (string/join ".") |
| 208 | + (munge))] |
| 209 | + (str "Namespace " name " contains a reserved JavaScript keyword," |
| 210 | + " the corresponding Google Closure namespace will be munged to " munged))) |
| 211 | + |
187 | 212 | (defn ^:private default-warning-handler [warning-type env extra]
|
188 | 213 | (when (warning-type *cljs-warnings*)
|
189 | 214 | (when-let [s (error-message warning-type extra)]
|
|
1385 | 1410 | [_ env [_ name & args :as form] _ opts]
|
1386 | 1411 | (when-not (symbol? name)
|
1387 | 1412 | (throw (error env "Namespaces must be named by a symbol.")))
|
1388 |
| - (when (= 1 (count (string/split (clojure.core/name name) #"\."))) |
1389 |
| - (warning :single-segment-namespace env {:name name})) |
| 1413 | + (let [segments (string/split (clojure.core/name name) #"\.")] |
| 1414 | + (when (= 1 (count segments)) |
| 1415 | + (warning :single-segment-namespace env {:name name})) |
| 1416 | + (when (some js-reserved segments) |
| 1417 | + (warning :munged-namespace env {:name name}))) |
1390 | 1418 | (let [docstring (if (string? (first args)) (first args))
|
1391 | 1419 | mdocstr (-> name meta :doc)
|
1392 | 1420 | args (if docstring (next args) args)
|
|
0 commit comments