lilactown / helix

A simple, easy to use library for React development in ClojureScript.
Eclipse Public License 2.0
627 stars 52 forks source link

defcomponent doesn't support docstrings #99

Closed CamdenClark closed 2 years ago

CamdenClark commented 2 years ago

With shadow-cljs:

[:app] Build failure:
...
  39 | (defcomponent test-component
-------^------------------------------------------------------------------------
null
Too many arguments to def at line 39 ....cljs
--------------------------------------------------------------------------------
  40 |   "test"
lilactown commented 2 years ago

The error is this line https://github.com/lilactown/helix/blob/9856689e58b1faeb03ea6a21009a7d2ceac21a59/src/helix/core.clj#L394

docstring is a string, which is being expanded as a sequence of characters via ~@, so it ends up emitting something like:

(macroexpand '(defcomponent foo "bar"))
;; => (def foo "b" "a" "r" (helix.core/create-component (cljs.core/js-obj "displayName" "foo") (cljs.core/js-obj)))

I think the right fix is to wrap the docstring in a collection when returning from the when like we do here https://github.com/lilactown/helix/blob/9856689e58b1faeb03ea6a21009a7d2ceac21a59/src/helix/core.clj#L94