ryansolid / dom-expressions

A Fine-Grained Runtime for Performant DOM Rendering
MIT License
865 stars 124 forks source link

class:foo={undefined} doesn't cast to boolean #133

Closed edemaine closed 1 year ago

edemaine commented 2 years ago

I was reviewing https://github.com/solidjs/solid-docs/commit/4850acf52752db5ebe28e05f593567339d0b0c83 but don't understand the code well enough to read it, so I just tested it.

Bug: <div class:foo={undefined}/> seems to compile to _el$2.classList.toggle("foo", undefined);, which is the opposite of what we want (it turns the class on). Similarly <div class:foo={foo}/> where foo is a local variable. So I guess the literals not matching the if need to be !!d at compile time.

By contrast, <div class:foo={foo()}/> compiles correctly to

_v$3 = !!foo();
...
_v$3 !== _p$._v$3 && _el$2.classList.toggle("foo", _p$._v$3 = _v$3);

Also classList works great.

ryansolid commented 2 years ago

Yeah literals have a different branch of code in the compiler. I likely missed that one.