Clean up unit test breakage

In 992b6b9fcc unit test broke (which I missed). This was due to undeclared variables not being side-effects free.

However, since they're really not side-effect free, just declare them in the test cases.
This commit is contained in:
Richard van Velzen
2015-02-11 21:27:21 +01:00
parent 992b6b9fcc
commit 61e850ceb5
2 changed files with 91 additions and 89 deletions

View File

@@ -53,6 +53,7 @@ ifs_3_should_warn: {
booleans : true booleans : true
}; };
input: { input: {
var x, y;
if (x && !(x + "1") && y) { // 1 if (x && !(x + "1") && y) { // 1
var qq; var qq;
foo(); foo();
@@ -68,6 +69,7 @@ ifs_3_should_warn: {
} }
} }
expect: { expect: {
var x, y;
var qq; bar(); // 1 var qq; bar(); // 1
var jj; foo(); // 2 var jj; foo(); // 2
} }

View File

@@ -1,89 +1,89 @@
dead_code_1: { dead_code_1: {
options = { options = {
dead_code: true dead_code: true
}; };
input: { input: {
function f() { function f() {
a(); a();
b(); b();
x = 10; x = 10;
return; return;
if (x) { if (x) {
y(); y();
} }
} }
} }
expect: { expect: {
function f() { function f() {
a(); a();
b(); b();
x = 10; x = 10;
return; return;
} }
} }
} }
dead_code_2_should_warn: { dead_code_2_should_warn: {
options = { options = {
dead_code: true dead_code: true
}; };
input: { input: {
function f() { function f() {
g(); g();
x = 10; x = 10;
throw "foo"; throw "foo";
// completely discarding the `if` would introduce some // completely discarding the `if` would introduce some
// bugs. UglifyJS v1 doesn't deal with this issue; in v2 // bugs. UglifyJS v1 doesn't deal with this issue; in v2
// we copy any declarations to the upper scope. // we copy any declarations to the upper scope.
if (x) { if (x) {
y(); y();
var x; var x;
function g(){}; function g(){};
// but nested declarations should not be kept. // but nested declarations should not be kept.
(function(){ (function(){
var q; var q;
function y(){}; function y(){};
})(); })();
} }
} }
} }
expect: { expect: {
function f() { function f() {
g(); g();
x = 10; x = 10;
throw "foo"; throw "foo";
var x; var x;
function g(){}; function g(){};
} }
} }
} }
dead_code_constant_boolean_should_warn_more: { dead_code_constant_boolean_should_warn_more: {
options = { options = {
dead_code : true, dead_code : true,
loops : true, loops : true,
booleans : true, booleans : true,
conditionals : true, conditionals : true,
evaluate : true evaluate : true
}; };
input: { input: {
while (!((foo && bar) || (x + "0"))) { while (!((foo && bar) || (x + "0"))) {
console.log("unreachable"); console.log("unreachable");
var foo; var foo;
function bar() {} function bar() {}
} }
for (var x = 10; x && (y || x) && (!typeof x); ++x) { for (var x = 10, y; x && (y || x) && (!typeof x); ++x) {
asdf(); asdf();
foo(); foo();
var moo; var moo;
} }
} }
expect: { expect: {
var foo; var foo;
function bar() {} function bar() {}
// nothing for the while // nothing for the while
// as for the for, it should keep: // as for the for, it should keep:
var x = 10; var x = 10, y;
var moo; var moo;
} }
} }