terser / html-minifier-terser

actively maintained fork of html-minifier - minify HTML, CSS and JS code using terser - supports ES6 code
https://terser.org/html-minifier-terser
MIT License
376 stars 30 forks source link

function call in event attribute not mangled by terser #135

Closed gnbl closed 1 year ago

gnbl commented 1 year ago

Running html-minifier-terser test.html --minify-js '{"mangle":{"toplevel":true},"nameCache":{}}' on

<html><body>
        <script>function test(){console.log("test");}</script>
        <button onclick="test();"></button>        
</body></html>

works, but fails when the function call in the event attribute comes before the definition in the script, e.g.

<html><body>
        <button onclick="test();"></button>
        <script>function test(){console.log("test");}</script>
</body></html>

Increasing compress passes does not have an effect. My guess is that function calls are changed only if a previous definition has been mangled. In that case, is there a way to do another mangling pass (passes is not a mangle option)?

Of course workarounds include simply changing the order or attaching event handlers programmatically.

DanielRuf commented 1 year ago

My guess is that function calls are changed only if a previous definition has been mangled.

That may be correct.

In that case, is there a way to do another mangling pass (passes is not a mangle option)?

Not sure. Someone would have to check the options and the code to answer this.

DanielRuf commented 1 year ago

Can not reproduce with the latest version at https://terser.org/html-minifier-terser/

grafik