Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function call in event attribute not mangled by terser #135

Closed
gnbl opened this issue Oct 24, 2022 · 2 comments
Closed

function call in event attribute not mangled by terser #135

gnbl opened this issue Oct 24, 2022 · 2 comments

Comments

@gnbl
Copy link

gnbl commented Oct 24, 2022

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.

@gnbl gnbl changed the title event attribute not nameCached by terser mangle function call in event attribute not mangled by terser Oct 28, 2022
@DanielRuf
Copy link
Contributor

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
Copy link
Contributor

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

grafik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants