swc icon indicating copy to clipboard operation
swc copied to clipboard

jsc.minify.format.inlineScript support

Open 9aoy opened this issue 2 years ago • 3 comments
trafficstars

Describe the feature

https://swc.rs/docs/configuration/minification#jscminifyformat

image

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

9aoy avatar Jun 29 '23 11:06 9aoy

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

Skalman avatar Jul 06 '23 21:07 Skalman

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.

fabiosantoscode avatar Jul 14 '23 13:07 fabiosantoscode

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 \/.

adam-azarchs avatar Jan 04 '24 19:01 adam-azarchs