ryansolid / dom-expressions

A Fine-Grained Runtime for Performant DOM Rendering
MIT License
887 stars 127 forks source link

Option for preserving whitespace within JSXChildren #329

Open bterlson opened 5 months ago

bterlson commented 5 months ago

Would it be acceptable to add an option to preserve whitespace within JSXChildren? I am building a framework for generating source code with JSX and in that context whitespace is important to preserve. In particular, if I had something like:

function PythonFunction({name}) {
  return <>
    def {name}():
      <PythonFunctionBody />
  </>
}

which compiled to something like: ["\n def ", name, "():\n ", $createComponent(PythonFunctionBody, {})], then I can use the leading whitespace for the first text node to establish the baseline indent level, and book-keep subsequent indent level increases within my render function.

ryansolid commented 4 months ago

This seems reasonable. I'm not sure if this would impact walks at all. It should be the same and match up I imagine. But that would be my main consideration.