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

functions pruned when exported in an object literal #382

Open
davethieben opened this issue Feb 22, 2024 · 1 comment
Open

functions pruned when exported in an object literal #382

davethieben opened this issue Feb 22, 2024 · 1 comment

Comments

@davethieben
Copy link

version: 1.20.7 (through LigerShark.WebOptimizer v3.0.396)

Describe the bug
if RemoveUnneededCode = true, local functions are being pruned even they are referenced from an object literal
export

To Reproduce
invoking:

    var uglifyResult = NUglify.Uglify.Js(@"
function abc(def){
    alert(def);
}

export default { abc };
");
    Debug.WriteLine($"result:\r\n{uglifyResult.Code}");

Minified output or stack trace

export default{abc:n}

Excepted output code

function n(n){alert(n)}export default{abc:n}

which is what you get if you set RemoveUnneededCode = false

@trullock
Copy link
Owner

Good find

Not got a lot of time to look at this but PRs welcome.

It should be relatively easy to trace this though, look where RemoveUnneededCode ends up getting piped, it will be to one of the Visitors after JsParser has run. The code the checks if a particular AST node is needed or not is not paying attention to exports, or rather exports are not declaring their references in a way that the remover pays attention to

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

No branches or pull requests

2 participants