oliyh / martian

The HTTP abstraction library for Clojure/script, supporting OpenAPI, Swagger, Schema, re-frame and more
MIT License
525 stars 42 forks source link

`wrap-default` in CLJS causes compiler warning #198

Closed rome-user closed 5 months ago

rome-user commented 5 months ago

The function in question

https://github.com/oliyh/martian/blob/b6a3f7698083e9f01c9bcfd46fa90d77a2c76425/core/src/martian/schema.cljc#L124-L133

When using shadow-cljs 2.27.1, the following compiler warning is emitted.

------ WARNING #1 - :undeclared-var --------------------------------------------
 Resource: martian/schema.cljc:128:22
--------------------------------------------------------------------------------
 125 |           ;patch for `inf` as a default value
 126 |           (if (and (= schema s/Int) (= default "inf"))
 127 |             #?(:clj Long/MAX_VALUE
 128 |                :cljs Number.MAX_SAFE_INTEGER)
----------------------------^---------------------------------------------------
 Use of undeclared Var martian.schema/Number
--------------------------------------------------------------------------------
 129 |             default)]
 130 |       (st/default schema default))
 131 |     schema))
 132 | 
--------------------------------------------------------------------------------

Line 128 should be js/Number.MAX_SAFE_INTEGER instead. Another reason to prefer the js namespace is that these symbols all have their externs inferred.

Per https://cljs.github.io/api/syntax/dot

Dots inside symbols accidentally work as a technical shortcut in ClojureScript, but this is not valid in Clojure. ... Dots inside symbols are not recommended, as they are not detected by :infer-externs.

Also see https://cljs.github.io/api/syntax/js-namespace

oliyh commented 5 months ago

Available now in 0.1.27-SNAPSHOT