weavejester / hiccup

Fast library for rendering HTML in Clojure
http://weavejester.github.io/hiccup
Eclipse Public License 1.0
2.68k stars 174 forks source link

precompile let and when forms #142

Closed thheller closed 2 years ago

thheller commented 7 years ago

Currently only if and for are pre-compiled by hiccup.compiler. Added let and when since those are the most common I have as well and they fall back to interpreted mode.

Might be useful to add cond, case, condp?

weavejester commented 7 years ago

Thanks! Can you add a capital letter to the start of the commit message?

thheller commented 7 years ago

Sure, done.

weavejester commented 7 years ago

Thanks! Just one more thing: I notice there aren't any tests for this. Could you add a couple, one for testing when and the other for testing let?

thheller commented 7 years ago

Sure, but looking through the existing tests I have no idea how to go about that. The compiled form produces the exact same output as the uncompiled form, thus just testing the output is not actually a reliable test that the code worked.

Inspecting the macroexpand output seems too restrictive given that one might want to change things in the future which may yield different code.

So just a "test" that compares the output and disregards the possibility that something wasn't compiled just interpreted? Any other ideas?

weavejester commented 7 years ago

I should have been a little clearer. I don't think we need a test to check that it's being precompiled, because as you say that's pretty complex! But I think we can have a test to check that the wrong output isn't produced. So something like:

(is (= (html (let [x "foo"] [:span x])) "<span>foo</span>")

Similarly one for when.