Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize adjacent static parts+fields #90

Open
developit opened this issue May 30, 2019 · 0 comments
Open

Optimize adjacent static parts+fields #90

developit opened this issue May 30, 2019 · 0 comments

Comments

@developit
Copy link
Owner

@developit developit commented May 30, 2019

I've been toying around with optimizing Tagged Templates by merging literal field values (strings, numbers and booleans) into their adjacent static part and collapsing the adjacent static parts into a single part:

// input:
<div class={"foo"}>hello</div>
<button id={1} />

// current output:
html`<div class=${"foo"}>hello</div>`
html `<button id=${1} />`

// optimized output:
html`<div class="foo">`
html`<button id=1 />`

It'd be really neat to get this behavior into babel-plugin-transform-jsx-to-htm, since additional assumptions could be made about nested Arrays:

const color = 'red';

// input:
<style jsx>{`
  .foo { color: ${color}; }
`}</style>

// current output:
html`
  <style jsx>${`
    .foo { color: ${color}; }
  `}</style>
`

// optimized output:
html`
  <style jsx>
    .foo { color: ${color}; }
  </style>
`

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.