|
1234 | 1234 | => 17"
|
1235 | 1235 | [psym & doc+methods]
|
1236 | 1236 | (let [p (:name (cljs.analyzer/resolve-var (dissoc &env :locals) psym))
|
1237 |
| - psym (vary-meta psym assoc :protocol-symbol true) |
| 1237 | + [doc methods] (if (core/string? (first doc+methods)) |
| 1238 | + [(first doc+methods) (next doc+methods)] |
| 1239 | + [nil doc+methods]) |
| 1240 | + psym (vary-meta psym assoc |
| 1241 | + :doc doc |
| 1242 | + :protocol-symbol true) |
1238 | 1243 | ns-name (-> &env :ns :name)
|
1239 | 1244 | fqn (fn [n] (symbol (core/str ns-name "." n)))
|
1240 | 1245 | prefix (protocol-prefix p)
|
1241 |
| - methods (if (core/string? (first doc+methods)) (next doc+methods) doc+methods) |
1242 | 1246 | _ (core/doseq [[mname & arities] methods]
|
1243 | 1247 | (when (some #{0} (map count (filter vector? arities)))
|
1244 |
| - (throw (Exception. (core/str "Invalid protocol, " psym " defines method " mname " with arity 0"))))) |
| 1248 | + (throw (Exception. |
| 1249 | + (core/str "Invalid protocol, " psym |
| 1250 | + " defines method " mname " with arity 0"))))) |
1245 | 1251 | expand-sig (fn [fname slot sig]
|
1246 | 1252 | `(~sig
|
1247 | 1253 | (if (and ~(first sig) (. ~(first sig) ~(symbol (core/str "-" slot)))) ;; Property access needed here.
|
|
1257 | 1263 | (into {}
|
1258 | 1264 | (map
|
1259 | 1265 | (fn [[fname & sigs]]
|
1260 |
| - (let [sigs (take-while vector? sigs)] |
1261 |
| - [fname (vec sigs)])) |
| 1266 | + (let [doc (as-> (last sigs) doc |
| 1267 | + (when (core/string? doc) doc)) |
| 1268 | + sigs (take-while vector? sigs)] |
| 1269 | + [(vary-meta fname assoc :doc doc) |
| 1270 | + (vec sigs)])) |
1262 | 1271 | methods)))
|
1263 | 1272 | method (fn [[fname & sigs]]
|
1264 |
| - (let [sigs (take-while vector? sigs) |
| 1273 | + (let [doc (as-> (last sigs) doc |
| 1274 | + (when (core/string? doc) doc)) |
| 1275 | + sigs (take-while vector? sigs) |
1265 | 1276 | slot (symbol (core/str prefix (name fname)))
|
1266 |
| - fname (vary-meta fname assoc :protocol p)] |
1267 |
| - `(defn ~fname ~@(map (fn [sig] |
1268 |
| - (expand-sig fname |
1269 |
| - (symbol (core/str slot "$arity$" (count sig))) |
1270 |
| - sig)) |
1271 |
| - sigs))))] |
| 1277 | + fname (vary-meta fname assoc |
| 1278 | + :protocol p |
| 1279 | + :doc doc)] |
| 1280 | + `(defn ~fname |
| 1281 | + ~@(map (fn [sig] |
| 1282 | + (expand-sig fname |
| 1283 | + (symbol (core/str slot "$arity$" (count sig))) |
| 1284 | + sig)) |
| 1285 | + sigs))))] |
1272 | 1286 | `(do
|
1273 | 1287 | (set! ~'*unchecked-if* true)
|
1274 | 1288 | (def ~psym (js-obj))
|
|
0 commit comments