wrote more of the compressor and added some tests
This commit is contained in:
49
test/compress/blocks.js
Normal file
49
test/compress/blocks.js
Normal file
@@ -0,0 +1,49 @@
|
||||
remove_blocks: {
|
||||
input: {
|
||||
{;}
|
||||
foo();
|
||||
{};
|
||||
{
|
||||
{};
|
||||
};
|
||||
bar();
|
||||
{}
|
||||
}
|
||||
expect: {
|
||||
foo();
|
||||
bar();
|
||||
}
|
||||
}
|
||||
|
||||
keep_some_blocks: {
|
||||
input: {
|
||||
// 1.
|
||||
if (foo) {
|
||||
{{{}}}
|
||||
if (bar) baz();
|
||||
{{}}
|
||||
} else {
|
||||
stuff();
|
||||
}
|
||||
|
||||
// 2.
|
||||
if (foo) {
|
||||
for (var i = 0; i < 5; ++i)
|
||||
if (bar) baz();
|
||||
} else {
|
||||
stuff();
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
// 1.
|
||||
if (foo) {
|
||||
if (bar) baz();
|
||||
} else stuff();
|
||||
|
||||
// 2.
|
||||
if (foo) {
|
||||
for (var i = 0; i < 5; ++i)
|
||||
if (bar) baz();
|
||||
} else stuff();
|
||||
}
|
||||
}
|
||||
53
test/compress/dead-code.js
Normal file
53
test/compress/dead-code.js
Normal file
@@ -0,0 +1,53 @@
|
||||
dead_code_1: {
|
||||
options = {
|
||||
dead_code: true
|
||||
};
|
||||
input: {
|
||||
function f() {
|
||||
a();
|
||||
b();
|
||||
x = 10;
|
||||
return;
|
||||
if (x) {
|
||||
y();
|
||||
}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
a();
|
||||
b();
|
||||
x = 10;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dead_code_2_should_warn: {
|
||||
options = {
|
||||
dead_code: true
|
||||
};
|
||||
input: {
|
||||
function f() {
|
||||
g();
|
||||
x = 10;
|
||||
throw "foo";
|
||||
// completely discarding the `if` would introduce some
|
||||
// bugs. UglifyJS v1 doesn't deal with this issue.
|
||||
if (x) {
|
||||
y();
|
||||
var x;
|
||||
function g(){};
|
||||
}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
g();
|
||||
x = 10;
|
||||
throw "foo";
|
||||
var x;
|
||||
function g(){};
|
||||
}
|
||||
}
|
||||
}
|
||||
24
test/compress/debugger.js
Normal file
24
test/compress/debugger.js
Normal file
@@ -0,0 +1,24 @@
|
||||
keep_debugger: {
|
||||
options = {
|
||||
drop_debugger: false
|
||||
};
|
||||
input: {
|
||||
debugger;
|
||||
}
|
||||
expect: {
|
||||
debugger;
|
||||
}
|
||||
}
|
||||
|
||||
drop_debugger: {
|
||||
options = {
|
||||
drop_debugger: true
|
||||
};
|
||||
input: {
|
||||
debugger;
|
||||
if (foo) debugger;
|
||||
}
|
||||
expect: {
|
||||
if (foo);
|
||||
}
|
||||
}
|
||||
25
test/compress/properties.js
Normal file
25
test/compress/properties.js
Normal file
@@ -0,0 +1,25 @@
|
||||
keep_properties: {
|
||||
options = {
|
||||
properties: false
|
||||
};
|
||||
input: {
|
||||
a["foo"] = "bar";
|
||||
}
|
||||
expect: {
|
||||
a["foo"] = "bar";
|
||||
}
|
||||
}
|
||||
|
||||
dot_properties: {
|
||||
options = {
|
||||
properties: true
|
||||
};
|
||||
input: {
|
||||
a["foo"] = "bar";
|
||||
a["if"] = "if";
|
||||
}
|
||||
expect: {
|
||||
a.foo = "bar";
|
||||
a["if"] = "if";
|
||||
}
|
||||
}
|
||||
60
test/compress/sequences.js
Normal file
60
test/compress/sequences.js
Normal file
@@ -0,0 +1,60 @@
|
||||
make_sequences_1: {
|
||||
options = {
|
||||
sequences: true
|
||||
};
|
||||
input: {
|
||||
foo();
|
||||
bar();
|
||||
baz();
|
||||
}
|
||||
expect: {
|
||||
foo(),bar(),baz();
|
||||
}
|
||||
}
|
||||
|
||||
make_sequences_2: {
|
||||
options = {
|
||||
sequences: true
|
||||
};
|
||||
input: {
|
||||
if (boo) {
|
||||
foo();
|
||||
bar();
|
||||
baz();
|
||||
} else {
|
||||
x();
|
||||
y();
|
||||
z();
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
if (boo) foo(),bar(),baz();
|
||||
else x(),y(),z();
|
||||
}
|
||||
}
|
||||
|
||||
make_sequences_3: {
|
||||
options = {
|
||||
sequences: true
|
||||
};
|
||||
input: {
|
||||
function f() {
|
||||
foo();
|
||||
bar();
|
||||
return baz();
|
||||
}
|
||||
function g() {
|
||||
foo();
|
||||
bar();
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
return foo(), bar(), baz();
|
||||
}
|
||||
function g() {
|
||||
throw foo(), bar(), new Error();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user