Skip to content

Incorrect Minification Result for Destructuring Assignment with Spread Operator #425

@experdot

Description

@experdot

Description:

When using NUglify to minify JavaScript code that contains a destructuring assignment with a spread operator, the resulting minified code is incorrect. Specifically, the variable names in the destructuring assignment are being incorrectly renamed, leading to potential runtime errors.

Steps to Reproduce:

  1. Use the following input code:
    $m=(e,t,n,o,r,s)=>{const{uid:a=t,...i}=n;}
  2. Run the following C# code to minify the JavaScript:
    var result = NUglify.Uglify.Js("$m=(e,t,n,o,r,s)=>{const{uid:a=t,...i}=n;}").Code;
    Console.WriteLine(result);
  3. Observe the output:
    $m=(n,t,i)=>{const{uid:r=t,...i}=i}

Actual Behavior:

The minified code incorrectly renames variables in the destructuring assignment, leading to a broken structure:

$m=(n,t,i)=>{const{uid:r=t,...i}=i}

Here, the variable i is reused both as the object being destructured and as the rest parameter, which is invalid and will cause runtime errors.

Environment:

  • NUglify Version: 1.21.13

Additional Notes:

This issue seems to occur specifically when destructuring assignments involve a default value (uid:a=t) and a spread operator (...i). It appears that the variable renaming logic in NUglify is not handling these cases correctly.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions