borkdude/rewrite-edn

Fix update when comments appear on top

borkdude opened this issue · 3 comments

This works:

user=> (def nodes (r/parse-string "{:a {:b 1}} ;; dude"))
#'user/nodes
user=> (r/update nodes :a #(r/update % :b (comp inc r/sexpr)))
<forms: {:a {:b 2}} ;; dude>

But this doesn't:

user=> (def nodes (r/parse-string ";; beginning of config {:a {:b 1}}"))
#'user/nodes
user=> (r/update nodes :a #(r/update % :b (comp inc r/sexpr)))
Execution error at rewrite-cljc.custom-zipper.core/insert-right (core.cljc:192).
Insert at top

Why should this work? Or what are you expecting? The map is in a comment so I'd assume it would be ignored? If I'm reading this correctly you're basically running:

(update-in nil [:a :b] inc)

(nil since the string is technically empty)

@kwrooijen Maybe I meant:

;; beginning of config
{:a {:b 1}}

so with a newline in between. Not sure...

And that seems to work. So I think this is not a bug :). Thanks @kwrooijen.