denoland / deno_ast

Source text parsing, lexing, and AST related functionality for Deno
https://crates.io/crates/deno_ast
MIT License
146 stars 45 forks source link

feat: merge serializable jsx children #173

Closed marvinhagemeister closed 10 months ago

marvinhagemeister commented 10 months ago

This PR adds some logic to the new JSX transforms that allows it to merge serializable JSX children together. A node is deemed serializable when it is text, or is a serializable HTML node. This addresses the following scenarios where we'd generate more templates than necessary:

// input
<div>foo{" "}bar</div>

// before
const tpl = [
  "<div>foo",
  "",
  "bar</div>"
]
jsxssr(tpl, " ")

// after
const tpl = [
  "<div>foo bar</div>",
]
jsxssr(tpl)

This scenario happens often enough in our code bases that this optimization should be worth it.