Skip to content

Commit 0323346

Browse files
authored
Fix the case when result of map-lookup is falsy (xapix-io#114)
* Fix the case when result of map-lookup is falsy * Add test
1 parent 6834668 commit 0323346

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/axel_f/compiler.cljc

+6-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
(reduce
2525
(fn [_ x]
2626
(when (map? x)
27-
(when-let [v (or (get x idx)
28-
(get x (switch-type idx)))]
29-
(reduced v))))
27+
(let [idx' (switch-type idx)]
28+
(cond
29+
(and (contains? x idx) (some? (get x idx)))
30+
(reduced (get x idx))
31+
(and (contains? x idx') (some? (get x idx')))
32+
(reduced (get x idx'))))))
3033
nil ctxs))
3134

3235
(defn lookup [ctx [p & path]]

test/axel_f/reference_test.cljc

+6
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@
6969
(t/deftest reference-can-start-with-number
7070
(t/is (= 1
7171
((af/compile "1to1.foo") {"1to1" {:foo 1}}))))
72+
73+
(t/deftest falsy-values
74+
(t/is (= [false true 1]
75+
((af/compile "foo.[].bar") {"foo" [{:bar false}
76+
{"bar" true}
77+
{"bar" 1}]}))))

0 commit comments

Comments
 (0)