swc
swc copied to clipboard
jsc.minify.format.inlineScript support
Describe the feature
https://swc.rs/docs/configuration/minification#jscminifyformat
input:
"<script></script>"
expected output:
"<script><\\/script>"
Are you willing to work on this yourself? yes
Babel plugin or link to the feature description
https://github.com/terser/terser/blob/aeddfabd04ace5a6565b2920b074ad7dc210bcac/lib/output.js#L367
Additional context
No response
FWIW, the Terser implementation isn't complete, so the linked code isn't sufficient to make it completely safe.
I've filed an issue with Terser: https://github.com/terser/terser/issues/1408
I'm implementing this with a simple lookup of the latest printed stuff before printing.
For example I'm going to check if the output stream ends with "--" before printing the ">" operator. If it does, I'll add a space.
It looks like #8252 tried to fix this, but it doesn't seem to actually work. I haven't dug deep into why, but at least in my use case I'm using swc as the minifier in a webpack build, where pre-minification it's got a.innerHTML="<script>\x3c/script>" (which comes from react-dom, so I'd expect this to be a fairly common thing for people to encounter), so I'm wondering if maybe the issue is one of order of operations between converting \x3c to / and escaping / to \/.