Skip to content

Break statement left in function when uglifying do while loop #1532

@madrussa

Description

@madrussa

There's a bug in which a break statement is left in a function when uglifying a do while loop.

I've inherited a DojoX project and there is a function which uses a do while(false) which can be found in https://github.com/dojo/dojox/blob/master/gfx/_base.js the splitFontString method on line 864. Our current build process causes an illegal break statement syntax error for this function as it leaves the break statement in whilst removing the do while.

I've managed to simplify the function to the bare minimum:

Input

var test = function(str) {
    var font = '';
    do {
        if (str.length < 5){
            break;
        }
        font = str;
    } while (false);
    return font;
}

Output
var test=function(t){if(t.length<5)break;return t};

Command
uglifyjs --compress --mangle -- input.js

The expected output should not leave the break statement in as there's no containing loop or case to break out of.

Found broken in version 2.8.3, working in version 2.7.0 (using uglify as dependency of grunt-contrib-uglify).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions