ryansolid / dom-expressions

A Fine-Grained Runtime for Performant DOM Rendering
MIT License
850 stars 122 forks source link

Template generation template literal escape problem #309

Closed iczero closed 5 months ago

iczero commented 5 months ago

When generating template literals, the raw string value is passed to both raw and cooked. This causes some issues when handling "escape" sequences in JSX, such as <p>this \n is an escape</p>.

https://github.com/ryansolid/dom-expressions/blob/eb9a6bcf640b04c1d1c889d9983914a2776093fe/packages/babel-plugin-jsx-dom-expressions/src/dom/template.js#L39-L42

I believe the raw value needs to be escaped, as is done here: https://github.com/esast/esast/blob/7532b1c87880d59165eafce0a4599d226739e3b7/src/TemplateLiteral.ts#L54-L70

In React, the JSX above would render as "this \n is an escape". In Solid, the "escape" goes missing, as it is interpreted as a space.

Edit: <p>{"${blah}"}</p> fails to compile entirely.