ryansolid / dom-expressions

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

IIFE in attributes get incorrectly unwrapped #335

Open edemaine opened 1 month ago

edemaine commented 1 month ago

Playground link

Input

<For
  each={((s, e) => {
    let step = e > s ? 1 : -1;
    return Array.from(
      { length: Math.abs(e - s) },
      (_, i) => s + i * step,
    );
  })(0, params.boxes)}
/>

(this code may look a bit weird, but it's generated from the simple Civet code <For each=[0...params.boxes]>)

Output

import { createComponent as _$createComponent } from "solid-js/web";
import { For as _$For } from "solid-js/web";
_$createComponent(_$For, {
  get each() {
    let step = e > s ? 1 : -1;
    return Array.from({
      length: Math.abs(e - s)
    }, (_, i) => s + i * step);
  }
});

The bindings for s and e (by the IIFE) got lost. ☹️

This bug seems to go back to at least Solid 1.8.5.

Workaround

Wrap attribute in another IIFE: () => ...

ryansolid commented 1 week ago

Yeah that ones a bit odd.. I wouldn't expect the iife to get swallowed since we usually check for argument length, and that clearly has arguments.

edemaine commented 1 week ago

This seems to be fixed by #327. So maybe just needs a release.

ryansolid commented 5 days ago

That was released like 7 versions ago. 0.37.22... we are on 0.38.5. The release should have gone out June 25th. Can you confirm if you have it?