ryansolid / dom-expressions

A Fine-Grained Runtime for Performant DOM Rendering
MIT License
858 stars 125 forks source link

Unwrap arrow function IIFEs in component props #272

Closed intrnl closed 11 months ago

intrnl commented 1 year ago

As per pull request title, unwraps arrow function IIFEs if they are directly used within a component prop.

the following <Show /> pattern can be quite common, and this saves up some of the bytes incurred by it

<Show
  when={(() => {
    const val = value();
    if ("key" in val) {
      return val;
    }
  })()}
>
  {(val) => (
    <>
      ...
    </>
  )}
</Show>
intrnl commented 1 year ago

this usage should be a non-issue as arrow functions this has already been handled by the plugin, but we can make an additional test case for this

ryansolid commented 11 months ago

I like this. It does add complication to the compiler but it is definitely the type of thing we can do. I'm trying to think of anywhere this falls down but I don't think so.