I am running into a slight issue with my own hook to parse one of the om.tools/defcomponentk
macros. The macro usage looks like this:
(defcomponentk wow-component [[:data a b c d] [:state wow mate]]
(display-name [_]
"Lol")
(component-did-mount [_])
(render [_]
(+ a b c d wow mate)))
I need all those vars a b c d wow mate
be resolved, so I wrote one transformer and right before it returns it does a (prn (api/sexpr new-node))
and shows me this:
(defn wow-component [a b c d wow mate] (letfn [(_ [_] "Lol") (_ [_]) (_ [_] (+ a b c d wow mate))]))
I am not sure why, clj-kondo still reports a, b, c, d ... all unresolved 😢
basically I am turning the defcomponent
into one defn
and then wrapping the whole body in one letfn
since that was the closest similar structure I could find
here's the code for the hook: https://gist.github.com/verma/58a6c170189b5cf3dc9bf4103ce2e475
So the node is returned? What if you return just a token node, just for debugging? Then it should not report those locals
checking
I tried returning (api/token-node '_)
and it said: test.clj::: error: Unresolved symbol: _
which seems right. when I comment out the body and just generate this: (defn wow-component [a b c d wow mate])
.. it shows be this:
test.clj::: error: unsupported binding form a │
test.clj::: error: unsupported binding form b │
test.clj::: error: unsupported binding form c │
test.clj::: error: unsupported binding form d │
test.clj::: error: unsupported binding form wow │
test.clj::: error: unsupported binding form mate │
linting took 13ms, errors: 6, warnings: 0
wonder if there's something about those vars which is not visible when api/sexpr
is run on it, printing raw one second
<list: (defn wow-component [a b c d wow mate])>
ooof that doesn't look right 😕
what doesn't look right about it?
hmm, never mind that looks ok
are you re-defining defn perhaps in this namespace?
I was wondering if it would show me the types of the vector etc also
no I don't think so
ah
(def wow-component (fn [a b c d wow mate])) │
<list: (def wow-component (fn [a b c d wow mate]))> │
test.clj::: error: unsupported binding form a │
test.clj::: error: unsupported binding form b │
test.clj::: error: unsupported binding form c │
test.clj::: error: unsupported binding form d │
test.clj::: error: unsupported binding form wow │
test.clj::: error: unsupported binding form mate │
test.clj::: error: unsupported binding form a │
test.clj::: error: unsupported binding form b │
test.clj::: error: unsupported binding form c │
test.clj::: error: unsupported binding form d │
test.clj::: error: unsupported binding form wow │
test.clj::: error: unsupported binding form mate
I changed defn to (def (fn ..)) just to be sure.
Can you perhaps print the incoming node too?
also not sure why printing twice
yeah one second
<list: (defcomponentk wow-component [[:data a b c d] [:state wow mate]] (display-name [_] "Lol") (component-did-mount [_]) (render [_] (+ a b c d wow mate)))>
One peculiar difference is that now each error is printing twice, instead of once
Maybe you can put this code up on Github? Then I'll have a look
or is it a work project?
In that case, maybe make a repro repo that I can run locally
I did, the hook code is on the gist I posted
but I can set it up so you can run it easily, one second
yes, please set it up completely
this will save me time
yeah definitely, thanks for your help, I'll ping you here when I have it ready to go
I am sorry @borkdude but I am an idiot 🙂 .. While I was prepping this for you I found the mistake, I was converting a vector-node to a vector using (api/sexpr)
but then adding it back in, I wasn't mapping to tokens back into token-nodes, basically went from:
(api/vector-node flattened)
;; to this ->
(api/vector-node (map api/token-node flattened))
please accept my apology for wasting your time
Not a problem. Glad you found it.
🙂 thank you!