feat(codegen): prefer backquotes over double / single quotes#8839
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Performance ReportMerging #8839 will not alter performanceComparing Summary
|
|
|
df82694 to
3cf8a9c
Compare
Merge activity
|
When thinking about why #8443 made the gzip size increased, I thought it maybe because the backquotes appear more than before the PR. So I changed the codegen to prefer backquotes than double/single quotes. It seems this separate change have a positive effect with some projects. My guess is that in most projects, back quotes does not appear in string literals than double quotes and single quotes. The gzipped size slightly increases for `bundle.min.js`, `victory.js`, `antd.js`, but those will be decreased by #8443 except for `bundle.min.js`.
3cf8a9c to
b4ee617
Compare
Compress `"".concat(a, "b", c)` into `` `${a}b${c}` ``.
~~I'm not sure if this should be merged. It works for antd but it doesn't for typescript.~~ Now with #8839, it works well for typescript as well.
**References**
- [Spec of `String::concat`](https://tc39.es/ecma262/multipage/text-processing.html#sec-string.prototype.concat)
- [Spec of template literal](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-template-literals-runtime-semantics-evaluation)
|
@sapphi-red I'm getting an issue/bug with this. The gist of it is we have something like: Before minification, — the regex no longer matches because backticks aren't quotes. Terser and esbuild both preserve string literal quote types. The minifier should not convert string literals to template literals, as it changes observable behavior via .toString(). Is there a way to opt out of this behavior? |
No minifier preserves the output of I guess you can modify the code to handle backquotes as well. |
|
OK that's fair we'll handle this on our side |

When thinking about why #8443 made the gzip size increased, I thought it maybe because the backquotes appear more than before the PR. So I changed the codegen to prefer backquotes than double/single quotes. It seems this separate change have a positive effect with some projects.
My guess is that in most projects, back quotes does not appear in string literals than double quotes and single quotes.
The gzipped size slightly increases for
bundle.min.js,victory.js,antd.js, but those will be decreased by #8443 except forbundle.min.js.