File tree Expand file tree Collapse file tree 2 files changed +22
-13
lines changed Expand file tree Collapse file tree 2 files changed +22
-13
lines changed Original file line number Diff line number Diff line change 2072
2072
(missing-protocol
2073
2073
~(core/str psym " ." fname) ~fsig))))
2074
2074
2075
- ; ; then check protocol fn in metadata (only when protocol is marked with :extend-via-metadata true)
2076
- check
2077
- (core/if-not (:extend-via-metadata opts)
2078
- check
2079
- `(if-let [meta-impl# (-> ~fsig (core/meta ) (core/get '~fqn-fname))]
2080
- (meta-impl# ~@sig)
2081
- ~check))
2082
-
2083
2075
; ; then check protocol on js string,function,array,object (first dynamic check actually executed)
2084
2076
check
2085
2077
`(let [x# (if (nil? ~fsig) nil ~fsig)
2088
2080
(m# ~@sig)
2089
2081
~check))]
2090
2082
`(~sig ~check)))
2091
- expand-sig (core/fn [dyn-name slot sig]
2083
+ expand-sig (core/fn [fname dyn-name slot sig]
2092
2084
(core/let [sig (sig->syms sig)
2093
2085
2086
+ fqn-fname (with-meta (fqn fname) {:cljs.analyzer/no-resolve true })
2094
2087
fsig (first sig)
2095
2088
2096
2089
; ; check protocol property on object (first check executed)
2099
2092
; ; Property access needed here.
2100
2093
(not (nil? (. ~fsig ~(with-meta (symbol (core/str " -" slot)) {:protocol-prop true })))))
2101
2094
(. ~fsig ~slot ~@sig)
2102
- (~dyn-name ~@sig))]
2095
+ (~dyn-name ~@sig))
2096
+
2097
+ ; ; then check protocol fn in metadata (only when protocol is marked with :extend-via-metadata true)
2098
+ check
2099
+ (core/if-not (:extend-via-metadata opts)
2100
+ check
2101
+ `(if-let [meta-impl# (-> ~fsig (core/meta ) (core/get '~fqn-fname))]
2102
+ (meta-impl# ~@sig)
2103
+ ~check))]
2103
2104
`(~sig ~check)))
2104
2105
psym (core/-> psym
2105
2106
(vary-meta update-in [:jsdoc ] conj " @interface" )
2147
2148
sigs))]
2148
2149
(defn ~fname
2149
2150
~@(map (core/fn [sig]
2150
- (expand-sig dyn-name
2151
+ (expand-sig fname dyn-name
2151
2152
(with-meta (symbol (core/str slot " $arity$" (count sig)))
2152
2153
{:protocol-prop true })
2153
2154
sig))
Original file line number Diff line number Diff line change 1770
1770
(deftest test-cljs-2960
1771
1771
; ; protocol impl via metadata
1772
1772
(is (= 1 (ext-meta-protocol (with-meta {} {`ext-meta-protocol (fn [_] 1 )}))))
1773
- ; ; actual impl before metadata
1774
- (is (= 2 (ext-meta-protocol (with-meta (SomeMetaImpl. 2 ) {`ext-meta-protocol (fn [_] 1 )}))))
1773
+ ; ; metadata before actual impl
1774
+ (is (= 1 (ext-meta-protocol (with-meta (SomeMetaImpl. 2 ) {`ext-meta-protocol (fn [_] 1 )}))))
1775
1775
; ; protocol not marked as :extend-via-metadata so fallthrough to no impl
1776
1776
(is (thrown? js/Error (non-meta-protocol (with-meta {} {`non-meta-protocol (fn [_] 1 )}))))
1777
1777
; ; normal impl call just in case
1778
1778
(is (= 2 (non-meta-protocol (with-meta (SomeMetaImpl. 2 ) {`non-meta-protocol (fn [_] 1 )})))))
1779
1779
1780
+ (extend-type PersistentArrayMap
1781
+ ExtMetaProtocol
1782
+ (ext-meta-protocol [m] 2 ))
1783
+
1784
+ (deftest test-cljs-3313
1785
+ (testing " metadata protocol fn takes precedence over direct implementation"
1786
+ (= 1 (ext-meta-protocol (with-meta (array-map ) {`ext-meta-protocol (fn [_] 1 )})))))
1787
+
1780
1788
(deftest test-cljs-3054
1781
1789
(testing " `into` behaves the same as Clojure"
1782
1790
(is (nil? (into nil #{})))
You can’t perform that action at this time.
0 commit comments