Skip to content
New issue

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

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

Already on GitHub? # to your account

minify-dead-code-elimination incorrectly removes return statement in a loop #275

Closed
asapach opened this issue Nov 15, 2016 · 1 comment
Closed

Comments

@asapach
Copy link

asapach commented Nov 15, 2016

Simplified repro:

function remove(id) {
    for (var j = 0; j < array.length; ++j) {
        if (array[j] === id) {
            array.splice(j, 1);
            return;
        }
    }
}

Output:

function remove(id) {
    for (var j = 0; j < array.length; ++j) {
        if (array[j] === id) {
            array.splice(j, 1);
        }
    }
}

In this case return is not dead code, since it terminates the loop. Interestingly break statement is not removed in the similar case.
REPL link

@boopathi
Copy link
Member

#266 fixes it

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

No branches or pull requests

2 participants