react icon indicating copy to clipboard operation
react copied to clipboard

feat(compiler): Implement constant propagation for template literals

Open nikeee opened this issue 1 year ago • 4 comments

Template literals consisting entirely of constant values will be inlined to a string literal, effectively replacing the backticks with a double quote.

This is done primarily to make the resulting instruction a string literal, so it can be processed further in constant propatation. So this is now correctly simplified to true:

`` === "" // now true
`a${1}` === "a1" // now true

If a template literal contains a non-constant value, the entire literal is left as-is. Transforming a template literal to one that has only partially inlined is something that can be improved upon in the future.

nikeee avatar Jun 02 '24 10:06 nikeee

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 16, 2024 10:28am

vercel[bot] avatar Jun 02 '24 10:06 vercel[bot]

Comparing: d77dd31a329df55a051800fc76668af8da8332b4...cee1f11d77c1c79e7eaf99ecbd82ed19d14ce3a4

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.66 kB 6.66 kB = 1.82 kB 1.82 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 496.48 kB 496.48 kB = 88.87 kB 88.87 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.67 kB 6.67 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 501.30 kB 501.30 kB = 89.56 kB 89.56 kB
facebook-www/ReactDOM-prod.classic.js = 593.97 kB 593.97 kB = 104.48 kB 104.48 kB
facebook-www/ReactDOM-prod.modern.js = 570.35 kB 570.35 kB = 100.89 kB 100.89 kB
test_utils/ReactAllWarnings.js Deleted 63.65 kB 0.00 kB Deleted 15.90 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
test_utils/ReactAllWarnings.js Deleted 63.65 kB 0.00 kB Deleted 15.90 kB 0.00 kB

Generated by :no_entry_sign: dangerJS against cee1f11d77c1c79e7eaf99ecbd82ed19d14ce3a4

react-sizebot avatar Jun 02 '24 10:06 react-sizebot

We should also test more edge cases: where the interpolation is at the beginning or end of the string, where there are multiple interpolations without any intervening text, with odd values like NaN, empty string, etc.

I agree, will do!

nikeee avatar Jun 05 '24 00:06 nikeee

This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.

github-actions[bot] avatar Oct 14 '24 11:10 github-actions[bot]

Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you!

github-actions[bot] avatar Oct 21 '24 11:10 github-actions[bot]