Merge branch 'master' into harmony-v2.8.8
This commit is contained in:
27
lib/ast.js
27
lib/ast.js
@@ -91,9 +91,20 @@ var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos
|
|||||||
}, null);
|
}, null);
|
||||||
|
|
||||||
var AST_Node = DEFNODE("Node", "start end", {
|
var AST_Node = DEFNODE("Node", "start end", {
|
||||||
clone: function() {
|
_clone: function(deep) {
|
||||||
|
if (deep) {
|
||||||
|
var self = this.clone();
|
||||||
|
return self.transform(new TreeTransformer(function(node) {
|
||||||
|
if (node !== self) {
|
||||||
|
return node.clone(true);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
return new this.CTOR(this);
|
return new this.CTOR(this);
|
||||||
},
|
},
|
||||||
|
clone: function(deep) {
|
||||||
|
return this._clone(deep);
|
||||||
|
},
|
||||||
$documentation: "Base class of all AST nodes",
|
$documentation: "Base class of all AST nodes",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
start: "[AST_Token] The first token of this node",
|
start: "[AST_Token] The first token of this node",
|
||||||
@@ -199,6 +210,20 @@ var AST_LabeledStatement = DEFNODE("LabeledStatement", "label", {
|
|||||||
this.label._walk(visitor);
|
this.label._walk(visitor);
|
||||||
this.body._walk(visitor);
|
this.body._walk(visitor);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
clone: function(deep) {
|
||||||
|
var node = this._clone(deep);
|
||||||
|
if (deep) {
|
||||||
|
var refs = node.label.references;
|
||||||
|
var label = this.label;
|
||||||
|
node.walk(new TreeWalker(function(node) {
|
||||||
|
if (node instanceof AST_LoopControl
|
||||||
|
&& node.label && node.label.thedef === label) {
|
||||||
|
refs.push(node);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
}, AST_StatementWithBody);
|
}, AST_StatementWithBody);
|
||||||
|
|
||||||
|
|||||||
@@ -224,6 +224,7 @@ merge(Compressor.prototype, {
|
|||||||
|
|
||||||
AST_Node.DEFMETHOD("reset_opt_flags", function(compressor, rescan){
|
AST_Node.DEFMETHOD("reset_opt_flags", function(compressor, rescan){
|
||||||
var reduce_vars = rescan && compressor.option("reduce_vars");
|
var reduce_vars = rescan && compressor.option("reduce_vars");
|
||||||
|
var toplevel = compressor.option("toplevel");
|
||||||
var ie8 = !compressor.option("screw_ie8");
|
var ie8 = !compressor.option("screw_ie8");
|
||||||
var safe_ids = [];
|
var safe_ids = [];
|
||||||
push();
|
push();
|
||||||
@@ -245,7 +246,8 @@ merge(Compressor.prototype, {
|
|||||||
if (node instanceof AST_SymbolRef) {
|
if (node instanceof AST_SymbolRef) {
|
||||||
var d = node.definition();
|
var d = node.definition();
|
||||||
d.references.push(node);
|
d.references.push(node);
|
||||||
if (!d.fixed || isModified(node, 0) || !is_safe(d)) {
|
if (!d.fixed || !is_safe(d)
|
||||||
|
|| is_modified(node, 0, d.fixed instanceof AST_Lambda)) {
|
||||||
d.fixed = false;
|
d.fixed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -265,6 +267,21 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (node instanceof AST_Defun) {
|
||||||
|
var d = node.name.definition();
|
||||||
|
if (!toplevel && d.global || is_safe(d)) {
|
||||||
|
d.fixed = false;
|
||||||
|
} else {
|
||||||
|
d.fixed = node;
|
||||||
|
mark_as_safe(d);
|
||||||
|
}
|
||||||
|
var save_ids = safe_ids;
|
||||||
|
safe_ids = [];
|
||||||
|
push();
|
||||||
|
descend();
|
||||||
|
safe_ids = save_ids;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
var iife;
|
var iife;
|
||||||
if (node instanceof AST_Function
|
if (node instanceof AST_Function
|
||||||
&& (iife = tw.parent()) instanceof AST_Call
|
&& (iife = tw.parent()) instanceof AST_Call
|
||||||
@@ -339,18 +356,22 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function reset_def(def) {
|
function reset_def(def) {
|
||||||
|
if (toplevel || !def.global || def.orig[0] instanceof AST_SymbolConst) {
|
||||||
def.fixed = undefined;
|
def.fixed = undefined;
|
||||||
|
} else {
|
||||||
|
def.fixed = false;
|
||||||
|
}
|
||||||
def.references = [];
|
def.references = [];
|
||||||
def.should_replace = undefined;
|
def.should_replace = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isModified(node, level) {
|
function is_modified(node, level, func) {
|
||||||
var parent = tw.parent(level);
|
var parent = tw.parent(level);
|
||||||
if (isLHS(node, parent)
|
if (isLHS(node, parent)
|
||||||
|| parent instanceof AST_Call && parent.expression === node) {
|
|| !func && parent instanceof AST_Call && parent.expression === node) {
|
||||||
return true;
|
return true;
|
||||||
} else if (parent instanceof AST_PropAccess && parent.expression === node) {
|
} else if (parent instanceof AST_PropAccess && parent.expression === node) {
|
||||||
return isModified(parent, level + 1);
|
return !func && is_modified(parent, level + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -548,11 +569,14 @@ merge(Compressor.prototype, {
|
|||||||
// Constant single use vars can be replaced in any scope.
|
// Constant single use vars can be replaced in any scope.
|
||||||
if (var_decl.value.is_constant()) {
|
if (var_decl.value.is_constant()) {
|
||||||
var ctt = new TreeTransformer(function(node) {
|
var ctt = new TreeTransformer(function(node) {
|
||||||
if (node === ref
|
if (node instanceof AST_Destructuring) return node;
|
||||||
&& !ctt.find_parent(AST_Destructuring)
|
var parent = ctt.parent();
|
||||||
&& !ctt.find_parent(AST_ForIn)) {
|
if (parent instanceof AST_IterationStatement
|
||||||
return replace_var(node, ctt.parent(), true);
|
&& (parent.condition === node || parent.init === node)) {
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
if (node === ref)
|
||||||
|
return replace_var(node, parent, true);
|
||||||
});
|
});
|
||||||
stat.transform(ctt);
|
stat.transform(ctt);
|
||||||
continue;
|
continue;
|
||||||
@@ -1325,14 +1349,7 @@ merge(Compressor.prototype, {
|
|||||||
def(AST_Statement, function(){
|
def(AST_Statement, function(){
|
||||||
throw new Error(string_template("Cannot evaluate a statement [{file}:{line},{col}]", this.start));
|
throw new Error(string_template("Cannot evaluate a statement [{file}:{line},{col}]", this.start));
|
||||||
});
|
});
|
||||||
// XXX: AST_Accessor and AST_Function both inherit from AST_Scope,
|
def(AST_Lambda, function(){
|
||||||
// which itself inherits from AST_Statement; however, they aren't
|
|
||||||
// really statements. This could bite in other places too. :-(
|
|
||||||
// Wish JS had multiple inheritance.
|
|
||||||
def(AST_Accessor, function(){
|
|
||||||
throw def;
|
|
||||||
});
|
|
||||||
def(AST_Function, function(){
|
|
||||||
throw def;
|
throw def;
|
||||||
});
|
});
|
||||||
def(AST_Arrow, function() {
|
def(AST_Arrow, function() {
|
||||||
@@ -2714,6 +2731,24 @@ merge(Compressor.prototype, {
|
|||||||
|
|
||||||
OPT(AST_Call, function(self, compressor){
|
OPT(AST_Call, function(self, compressor){
|
||||||
var exp = self.expression;
|
var exp = self.expression;
|
||||||
|
if (compressor.option("reduce_vars")
|
||||||
|
&& exp instanceof AST_SymbolRef) {
|
||||||
|
var def = exp.definition();
|
||||||
|
if (def.fixed instanceof AST_Defun) {
|
||||||
|
def.fixed = make_node(AST_Function, def.fixed, def.fixed).clone(true);
|
||||||
|
}
|
||||||
|
if (def.fixed instanceof AST_Function) {
|
||||||
|
exp = def.fixed;
|
||||||
|
if (compressor.option("unused")
|
||||||
|
&& def.references.length == 1
|
||||||
|
&& compressor.find_parent(AST_Scope) === def.scope) {
|
||||||
|
if (!compressor.option("keep_fnames")) {
|
||||||
|
exp.name = null;
|
||||||
|
}
|
||||||
|
self.expression = exp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (compressor.option("unused")
|
if (compressor.option("unused")
|
||||||
&& exp instanceof AST_Function
|
&& exp instanceof AST_Function
|
||||||
&& !exp.uses_arguments
|
&& !exp.uses_arguments
|
||||||
|
|||||||
@@ -889,7 +889,9 @@ function OutputStream(options) {
|
|||||||
output.with_parens(function(){
|
output.with_parens(function(){
|
||||||
self.condition.print(output);
|
self.condition.print(output);
|
||||||
});
|
});
|
||||||
|
if (output.option("beautify") && output.option("screw_ie8")) {
|
||||||
output.semicolon();
|
output.semicolon();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_While, function(self, output){
|
DEFPRINT(AST_While, function(self, output){
|
||||||
output.print("while");
|
output.print("while");
|
||||||
@@ -1096,15 +1098,6 @@ function OutputStream(options) {
|
|||||||
// adds the block brackets if needed.
|
// adds the block brackets if needed.
|
||||||
if (!self.body)
|
if (!self.body)
|
||||||
return output.force_semicolon();
|
return output.force_semicolon();
|
||||||
if (self.body instanceof AST_Do) {
|
|
||||||
// Unconditionally use the if/do-while workaround for all browsers.
|
|
||||||
// https://github.com/mishoo/UglifyJS/issues/#issue/57 IE
|
|
||||||
// croaks with "syntax error" on code like this: if (foo)
|
|
||||||
// do ... while(cond); else ... we need block brackets
|
|
||||||
// around do/while
|
|
||||||
make_block(self.body, output);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var b = self.body;
|
var b = self.body;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (b instanceof AST_If) {
|
if (b instanceof AST_If) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"homepage": "http://lisperator.net/uglifyjs",
|
"homepage": "http://lisperator.net/uglifyjs",
|
||||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"version": "2.8.7",
|
"version": "2.8.8",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -24,26 +24,57 @@ var results = {};
|
|||||||
var remaining = 2 * urls.length;
|
var remaining = 2 * urls.length;
|
||||||
function done() {
|
function done() {
|
||||||
if (!--remaining) {
|
if (!--remaining) {
|
||||||
|
var failures = [];
|
||||||
urls.forEach(function(url) {
|
urls.forEach(function(url) {
|
||||||
|
var info = results[url];
|
||||||
console.log();
|
console.log();
|
||||||
console.log(url);
|
console.log(url);
|
||||||
console.log(results[url].time);
|
console.log(info.log);
|
||||||
console.log("SHA1:", results[url].sha1);
|
var elapsed = 0;
|
||||||
|
info.log.replace(/: ([0-9]+\.[0-9]{3})s/g, function(match, time) {
|
||||||
|
elapsed += parseFloat(time);
|
||||||
});
|
});
|
||||||
|
console.log("Run-time:", elapsed.toFixed(3), "s");
|
||||||
|
console.log("Original:", info.input, "bytes");
|
||||||
|
console.log("Uglified:", info.output, "bytes");
|
||||||
|
console.log("SHA1 sum:", info.sha1);
|
||||||
|
if (info.code) {
|
||||||
|
failures.push(url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (failures.length) {
|
||||||
|
console.error("Benchmark failed:");
|
||||||
|
failures.forEach(function(url) {
|
||||||
|
console.error(url);
|
||||||
|
});
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
urls.forEach(function(url) {
|
urls.forEach(function(url) {
|
||||||
results[url] = { time: "" };
|
results[url] = {
|
||||||
|
input: 0,
|
||||||
|
output: 0,
|
||||||
|
log: ""
|
||||||
|
};
|
||||||
require(url.slice(0, url.indexOf(":"))).get(url, function(res) {
|
require(url.slice(0, url.indexOf(":"))).get(url, function(res) {
|
||||||
var uglifyjs = fork("bin/uglifyjs", args, { silent: true });
|
var uglifyjs = fork("bin/uglifyjs", args, { silent: true });
|
||||||
res.pipe(uglifyjs.stdin);
|
res.on("data", function(data) {
|
||||||
uglifyjs.stdout.pipe(createHash("sha1")).on("data", function(data) {
|
results[url].input += data.length;
|
||||||
|
}).pipe(uglifyjs.stdin);
|
||||||
|
uglifyjs.stdout.on("data", function(data) {
|
||||||
|
results[url].output += data.length;
|
||||||
|
}).pipe(createHash("sha1")).on("data", function(data) {
|
||||||
results[url].sha1 = data.toString("hex");
|
results[url].sha1 = data.toString("hex");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
uglifyjs.stderr.setEncoding("utf8");
|
uglifyjs.stderr.setEncoding("utf8");
|
||||||
uglifyjs.stderr.on("data", function(data) {
|
uglifyjs.stderr.on("data", function(data) {
|
||||||
results[url].time += data;
|
results[url].log += data;
|
||||||
}).on("end", done)
|
});
|
||||||
|
uglifyjs.on("exit", function(code) {
|
||||||
|
results[url].code = code;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -344,9 +344,9 @@ collapse_vars_do_while: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1(y) {
|
function f1(y) {
|
||||||
// The constant do-while condition `c` will be replaced.
|
// The constant do-while condition `c` will not be replaced.
|
||||||
var c = 9;
|
var c = 9;
|
||||||
do { } while (c === 77);
|
do {} while (c === 77);
|
||||||
}
|
}
|
||||||
function f2(y) {
|
function f2(y) {
|
||||||
// The non-constant do-while condition `c` will not be replaced.
|
// The non-constant do-while condition `c` will not be replaced.
|
||||||
@@ -381,7 +381,8 @@ collapse_vars_do_while: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f1(y) {
|
function f1(y) {
|
||||||
do ; while (false);
|
var c = 9;
|
||||||
|
do ; while (77 === c);
|
||||||
}
|
}
|
||||||
function f2(y) {
|
function f2(y) {
|
||||||
var c = 5 - y;
|
var c = 5 - y;
|
||||||
@@ -418,9 +419,9 @@ collapse_vars_do_while_drop_assign: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1(y) {
|
function f1(y) {
|
||||||
// The constant do-while condition `c` will be replaced.
|
// The constant do-while condition `c` will be not replaced.
|
||||||
var c = 9;
|
var c = 9;
|
||||||
do { } while (c === 77);
|
do {} while (c === 77);
|
||||||
}
|
}
|
||||||
function f2(y) {
|
function f2(y) {
|
||||||
// The non-constant do-while condition `c` will not be replaced.
|
// The non-constant do-while condition `c` will not be replaced.
|
||||||
@@ -455,7 +456,8 @@ collapse_vars_do_while_drop_assign: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f1(y) {
|
function f1(y) {
|
||||||
do ; while (false);
|
var c = 9;
|
||||||
|
do ; while (77 === c);
|
||||||
}
|
}
|
||||||
function f2(y) {
|
function f2(y) {
|
||||||
var c = 5 - y;
|
var c = 5 - y;
|
||||||
@@ -1309,8 +1311,8 @@ collapse_vars_regexp: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
(function(){
|
(function(){
|
||||||
var result, rx = /ab*/g;
|
var result, s = "acdabcdeabbb", rx = /ab*/g;
|
||||||
while (result = rx.exec('acdabcdeabbb'))
|
while (result = rx.exec(s))
|
||||||
console.log(result[0]);
|
console.log(result[0]);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
@@ -1421,3 +1423,35 @@ issue_1537_destructuring_for_of: {
|
|||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1562: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var v = 1, B = 2;
|
||||||
|
for (v in objs) f(B);
|
||||||
|
|
||||||
|
var x = 3, C = 10;
|
||||||
|
while(x + 2) bar(C);
|
||||||
|
|
||||||
|
var y = 4, D = 20;
|
||||||
|
do bar(D); while(y + 2);
|
||||||
|
|
||||||
|
var z = 5, E = 30;
|
||||||
|
for (; f(z + 2) ;) bar(E);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var v = 1;
|
||||||
|
for (v in objs) f(2);
|
||||||
|
|
||||||
|
var x = 3;
|
||||||
|
while(x + 2) bar(10);
|
||||||
|
|
||||||
|
var y = 4;
|
||||||
|
do bar(20); while(y + 2);
|
||||||
|
|
||||||
|
var z = 5;
|
||||||
|
for (; f(z + 2) ;) bar(30);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ dead_code_const_annotation: {
|
|||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
|
toplevel : true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var unused;
|
var unused;
|
||||||
@@ -194,6 +195,7 @@ dead_code_const_annotation_complex_scope: {
|
|||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
|
toplevel : true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var unused_var;
|
var unused_var;
|
||||||
|
|||||||
@@ -240,3 +240,159 @@ issue_1532: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_186: {
|
||||||
|
beautify = {
|
||||||
|
beautify: false,
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: 'var x=3;if(foo())do do alert(x);while(--x)while(x)else bar();'
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186_ie8: {
|
||||||
|
beautify = {
|
||||||
|
beautify: false,
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: 'var x=3;if(foo())do do alert(x);while(--x)while(x)else bar();'
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186_beautify: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: 'var x = 3;\n\nif (foo()) do do alert(x); while (--x); while (x); else bar();'
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186_beautify_ie8: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: 'var x = 3;\n\nif (foo()) do do alert(x); while (--x) while (x) else bar();'
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186_bracketize: {
|
||||||
|
beautify = {
|
||||||
|
beautify: false,
|
||||||
|
bracketize: true,
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else{bar()}'
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186_bracketize_ie8: {
|
||||||
|
beautify = {
|
||||||
|
beautify: false,
|
||||||
|
bracketize: true,
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else{bar()}'
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186_beautify_bracketize: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
bracketize: true,
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: 'var x = 3;\n\nif (foo()) {\n do {\n do {\n alert(x);\n } while (--x);\n } while (x);\n} else {\n bar();\n}'
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186_beautify_bracketize_ie8: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
bracketize: true,
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: 'var x = 3;\n\nif (foo()) {\n do {\n do {\n alert(x);\n } while (--x)\n } while (x)\n} else {\n bar();\n}'
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ reduce_vars: {
|
|||||||
C : 0
|
C : 0
|
||||||
},
|
},
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
|
toplevel : true,
|
||||||
unused : true
|
unused : true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -452,6 +453,7 @@ multi_def_2: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
function f(){
|
||||||
if (code == 16)
|
if (code == 16)
|
||||||
var bitsLength = 2, bitsOffset = 3, what = len;
|
var bitsLength = 2, bitsOffset = 3, what = len;
|
||||||
else if (code == 17)
|
else if (code == 17)
|
||||||
@@ -460,7 +462,9 @@ multi_def_2: {
|
|||||||
var bitsLength = 7, bitsOffset = 11, what = (len = 0);
|
var bitsLength = 7, bitsOffset = 11, what = (len = 0);
|
||||||
var repeatLength = this.getBits(bitsLength) + bitsOffset;
|
var repeatLength = this.getBits(bitsLength) + bitsOffset;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
function f(){
|
||||||
if (16 == code)
|
if (16 == code)
|
||||||
var bitsLength = 2, bitsOffset = 3, what = len;
|
var bitsLength = 2, bitsOffset = 3, what = len;
|
||||||
else if (17 == code)
|
else if (17 == code)
|
||||||
@@ -469,6 +473,7 @@ multi_def_2: {
|
|||||||
var bitsLength = 7, bitsOffset = 11, what = (len = 0);
|
var bitsLength = 7, bitsOffset = 11, what = (len = 0);
|
||||||
var repeatLength = this.getBits(bitsLength) + bitsOffset;
|
var repeatLength = this.getBits(bitsLength) + bitsOffset;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use_before_var: {
|
use_before_var: {
|
||||||
@@ -477,13 +482,17 @@ use_before_var: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
function f(){
|
||||||
console.log(t);
|
console.log(t);
|
||||||
var t = 1;
|
var t = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
function f(){
|
||||||
console.log(t);
|
console.log(t);
|
||||||
var t = 1;
|
var t = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inner_var_if: {
|
inner_var_if: {
|
||||||
@@ -492,23 +501,21 @@ inner_var_if: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(){
|
function f(a){
|
||||||
return 0;
|
if (a)
|
||||||
}
|
|
||||||
if (f())
|
|
||||||
var t = 1;
|
var t = 1;
|
||||||
if (!t)
|
if (!t)
|
||||||
console.log(t);
|
console.log(t);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f(){
|
function f(a){
|
||||||
return 0;
|
if (a)
|
||||||
}
|
|
||||||
if (f())
|
|
||||||
var t = 1;
|
var t = 1;
|
||||||
if (!t)
|
if (!t)
|
||||||
console.log(t);
|
console.log(t);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inner_var_label: {
|
inner_var_label: {
|
||||||
@@ -517,25 +524,23 @@ inner_var_label: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(){
|
function f(a){
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
l: {
|
l: {
|
||||||
if (f()) break l;
|
if (a) break l;
|
||||||
var t = 1;
|
var t = 1;
|
||||||
}
|
}
|
||||||
console.log(t);
|
console.log(t);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f(){
|
function f(a){
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
l: {
|
l: {
|
||||||
if (f()) break l;
|
if (a) break l;
|
||||||
var t = 1;
|
var t = 1;
|
||||||
}
|
}
|
||||||
console.log(t);
|
console.log(t);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inner_var_for: {
|
inner_var_for: {
|
||||||
@@ -544,15 +549,18 @@ inner_var_for: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
function f() {
|
||||||
var a = 1;
|
var a = 1;
|
||||||
x(a, b, d);
|
x(a, b, d);
|
||||||
for (var b = 2, c = 3; x(a, b, c, d); x(a, b, c, d)) {
|
for (var b = 2, c = 3; x(a, b, c, d); x(a, b, c, d)) {
|
||||||
var d = 4, e = 5;
|
var d = 4, e = 5;
|
||||||
x(a, b, c, d, e);
|
x(a, b, c, d, e);
|
||||||
}
|
}
|
||||||
x(a, b, c, d, e)
|
x(a, b, c, d, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
function f() {
|
||||||
var a = 1;
|
var a = 1;
|
||||||
x(1, b, d);
|
x(1, b, d);
|
||||||
for (var b = 2, c = 3; x(1, b, 3, d); x(1, b, 3, d)) {
|
for (var b = 2, c = 3; x(1, b, 3, d); x(1, b, 3, d)) {
|
||||||
@@ -561,6 +569,7 @@ inner_var_for: {
|
|||||||
}
|
}
|
||||||
x(1, b, 3, d, e);
|
x(1, b, 3, d, e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inner_var_for_in_1: {
|
inner_var_for_in_1: {
|
||||||
@@ -569,6 +578,7 @@ inner_var_for_in_1: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
function f() {
|
||||||
var a = 1, b = 2;
|
var a = 1, b = 2;
|
||||||
for (b in (function() {
|
for (b in (function() {
|
||||||
return x(a, b, c);
|
return x(a, b, c);
|
||||||
@@ -578,7 +588,9 @@ inner_var_for_in_1: {
|
|||||||
}
|
}
|
||||||
x(a, b, c, d);
|
x(a, b, c, d);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
function f() {
|
||||||
var a = 1, b = 2;
|
var a = 1, b = 2;
|
||||||
for (b in (function() {
|
for (b in (function() {
|
||||||
return x(1, b, c);
|
return x(1, b, c);
|
||||||
@@ -588,6 +600,7 @@ inner_var_for_in_1: {
|
|||||||
}
|
}
|
||||||
x(1, b, c, d);
|
x(1, b, c, d);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inner_var_for_in_2: {
|
inner_var_for_in_2: {
|
||||||
@@ -596,13 +609,17 @@ inner_var_for_in_2: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
function f() {
|
||||||
for (var long_name in {})
|
for (var long_name in {})
|
||||||
console.log(long_name);
|
console.log(long_name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
function f() {
|
||||||
for (var long_name in {})
|
for (var long_name in {})
|
||||||
console.log(long_name);
|
console.log(long_name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inner_var_catch: {
|
inner_var_catch: {
|
||||||
@@ -611,6 +628,7 @@ inner_var_catch: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
function f() {
|
||||||
try {
|
try {
|
||||||
a();
|
a();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -618,7 +636,9 @@ inner_var_catch: {
|
|||||||
}
|
}
|
||||||
console.log(b);
|
console.log(b);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
function f() {
|
||||||
try {
|
try {
|
||||||
a();
|
a();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -626,6 +646,7 @@ inner_var_catch: {
|
|||||||
}
|
}
|
||||||
console.log(b);
|
console.log(b);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1533_1: {
|
issue_1533_1: {
|
||||||
@@ -634,15 +655,19 @@ issue_1533_1: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
function f() {
|
||||||
var id = "";
|
var id = "";
|
||||||
for (id in {break: "me"})
|
for (id in {break: "me"})
|
||||||
console.log(id);
|
console.log(id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
function f() {
|
||||||
var id = "";
|
var id = "";
|
||||||
for (id in {break: "me"})
|
for (id in {break: "me"})
|
||||||
console.log(id);
|
console.log(id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1533_2: {
|
issue_1533_2: {
|
||||||
@@ -651,15 +676,449 @@ issue_1533_2: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
function f() {
|
||||||
var id = "";
|
var id = "";
|
||||||
for (var id in {break: "me"})
|
for (var id in {break: "me"})
|
||||||
console.log(id);
|
console.log(id);
|
||||||
console.log(id);
|
console.log(id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
function f() {
|
||||||
var id = "";
|
var id = "";
|
||||||
for (var id in {break: "me"})
|
for (var id in {break: "me"})
|
||||||
console.log(id);
|
console.log(id);
|
||||||
console.log(id);
|
console.log(id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toplevel_on: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel:true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toplevel_off: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel:false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x = 3;
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toplevel_on_loops_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel:true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function bar() {
|
||||||
|
console.log("bar:", --x);
|
||||||
|
}
|
||||||
|
var x = 3;
|
||||||
|
do
|
||||||
|
bar();
|
||||||
|
while (x);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x = 3;
|
||||||
|
do
|
||||||
|
(function() {
|
||||||
|
console.log("bar:", --x);
|
||||||
|
})();
|
||||||
|
while (x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toplevel_off_loops_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel:false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function bar() {
|
||||||
|
console.log("bar:", --x);
|
||||||
|
}
|
||||||
|
var x = 3;
|
||||||
|
do
|
||||||
|
bar();
|
||||||
|
while (x);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function bar() {
|
||||||
|
console.log("bar:", --x);
|
||||||
|
}
|
||||||
|
var x = 3;
|
||||||
|
do
|
||||||
|
bar();
|
||||||
|
while (x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toplevel_on_loops_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel:true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function bar() {
|
||||||
|
console.log("bar:");
|
||||||
|
}
|
||||||
|
var x = 3;
|
||||||
|
do
|
||||||
|
bar();
|
||||||
|
while (x);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (;;) (function() {
|
||||||
|
console.log("bar:");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toplevel_off_loops_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel:false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function bar() {
|
||||||
|
console.log("bar:");
|
||||||
|
}
|
||||||
|
var x = 3;
|
||||||
|
do
|
||||||
|
bar();
|
||||||
|
while (x);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function bar() {
|
||||||
|
console.log("bar:");
|
||||||
|
}
|
||||||
|
var x = 3;
|
||||||
|
do
|
||||||
|
bar();
|
||||||
|
while (x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toplevel_on_loops_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel:true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
while (x) bar();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (;;) bar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toplevel_off_loops_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel:false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
while (x) bar();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x = 3;
|
||||||
|
for (;x;) bar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defun_reference: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
function g() {
|
||||||
|
x();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
var a = h();
|
||||||
|
var b = 2;
|
||||||
|
return a + b;
|
||||||
|
function h() {
|
||||||
|
y();
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
function g() {
|
||||||
|
x();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
var a = h();
|
||||||
|
var b = 2;
|
||||||
|
return a + b;
|
||||||
|
function h() {
|
||||||
|
y();
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defun_inline_1: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
return g(2) + h();
|
||||||
|
function g(b) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
function h() {
|
||||||
|
return h();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
return function(b) {
|
||||||
|
return b;
|
||||||
|
}(2) + h();
|
||||||
|
function h() {
|
||||||
|
return h();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defun_inline_2: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
function g(b) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
function h() {
|
||||||
|
return h();
|
||||||
|
}
|
||||||
|
return g(2) + h();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
function h() {
|
||||||
|
return h();
|
||||||
|
}
|
||||||
|
return function(b) {
|
||||||
|
return b;
|
||||||
|
}(2) + h();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defun_inline_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
return g(2);
|
||||||
|
function g(b) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defun_call: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
return g() + h(1) - h(g(), 2, 3);
|
||||||
|
function g() {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
function h(a) {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
return 4 + h(1) - h(4);
|
||||||
|
function h(a) {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defun_redefine: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
function g() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
function h() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
g = function() {
|
||||||
|
return 3;
|
||||||
|
};
|
||||||
|
return g() + h();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
function g() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
g = function() {
|
||||||
|
return 3;
|
||||||
|
};
|
||||||
|
return g() + 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func_inline: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
var g = function() {
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
console.log(g() + h());
|
||||||
|
var h = function() {
|
||||||
|
return 2;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
console.log(1 + h());
|
||||||
|
var h = function() {
|
||||||
|
return 2;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func_modified: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
function a() { return 1; }
|
||||||
|
function b() { return 2; }
|
||||||
|
function c() { return 3; }
|
||||||
|
b.inject = [];
|
||||||
|
c = function() { return 4; };
|
||||||
|
return a() + b() + c();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
function b() { return 2; }
|
||||||
|
function c() { return 3; }
|
||||||
|
b.inject = [];
|
||||||
|
c = function() { return 4; };
|
||||||
|
return 1 + 2 + c();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defun_label: {
|
||||||
|
options = {
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
!function() {
|
||||||
|
function f(a) {
|
||||||
|
L: {
|
||||||
|
if (a) break L;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(f(2));
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function() {
|
||||||
|
console.log(function(a) {
|
||||||
|
L: {
|
||||||
|
if (a) break L;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}(2));
|
||||||
|
}();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
test/mocha/benchmark.js
Normal file
24
test/mocha/benchmark.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
var assert = require("assert");
|
||||||
|
var exec = require("child_process").exec;
|
||||||
|
|
||||||
|
describe("test/benchmark.js", function() {
|
||||||
|
this.timeout(120000);
|
||||||
|
var command = '"' + process.argv[0] + '" test/benchmark.js ';
|
||||||
|
[
|
||||||
|
"-b",
|
||||||
|
"-b bracketize",
|
||||||
|
"-m",
|
||||||
|
"-mc passes=3",
|
||||||
|
"-mc passes=3,toplevel",
|
||||||
|
"-mc passes=3,unsafe",
|
||||||
|
"-mc keep_fargs=false,passes=3",
|
||||||
|
"-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto",
|
||||||
|
].forEach(function(args) {
|
||||||
|
it("Should pass with options " + args, function(done) {
|
||||||
|
exec(command + args, function(err) {
|
||||||
|
if (err) throw err;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -82,7 +82,7 @@ describe("bin/uglifyjs", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("Should work with --keep-fnames (mangle & compress)", function (done) {
|
it("Should work with --keep-fnames (mangle & compress)", function (done) {
|
||||||
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m -c';
|
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m -c unused=false';
|
||||||
|
|
||||||
exec(command, function (err, stdout) {
|
exec(command, function (err, stdout) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|||||||
@@ -3,17 +3,13 @@ var assert = require("assert");
|
|||||||
|
|
||||||
describe("minify() with input file globs", function() {
|
describe("minify() with input file globs", function() {
|
||||||
it("minify() with one input file glob string.", function() {
|
it("minify() with one input file glob string.", function() {
|
||||||
var result = Uglify.minify("test/input/issue-1242/foo.*", {
|
var result = Uglify.minify("test/input/issue-1242/foo.*");
|
||||||
compress: { collapse_vars: true }
|
|
||||||
});
|
|
||||||
assert.strictEqual(result.code, 'function foo(o){print("Foo:",2*o)}var print=console.log.bind(console);');
|
assert.strictEqual(result.code, 'function foo(o){print("Foo:",2*o)}var print=console.log.bind(console);');
|
||||||
});
|
});
|
||||||
it("minify() with an array of one input file glob.", function() {
|
it("minify() with an array of one input file glob.", function() {
|
||||||
var result = Uglify.minify([
|
var result = Uglify.minify([
|
||||||
"test/input/issue-1242/b*.es5",
|
"test/input/issue-1242/b*.es5",
|
||||||
], {
|
]);
|
||||||
compress: { collapse_vars: true }
|
|
||||||
});
|
|
||||||
assert.strictEqual(result.code, 'function bar(n){return 3*n}function baz(n){return n/2}');
|
assert.strictEqual(result.code, 'function bar(n){return 3*n}function baz(n){return n/2}');
|
||||||
});
|
});
|
||||||
it("minify() with an array of multiple input file globs.", function() {
|
it("minify() with an array of multiple input file globs.", function() {
|
||||||
@@ -21,8 +17,8 @@ describe("minify() with input file globs", function() {
|
|||||||
"test/input/issue-1242/???.es5",
|
"test/input/issue-1242/???.es5",
|
||||||
"test/input/issue-1242/*.js",
|
"test/input/issue-1242/*.js",
|
||||||
], {
|
], {
|
||||||
compress: { collapse_vars: true }
|
compress: { toplevel: true }
|
||||||
});
|
});
|
||||||
assert.strictEqual(result.code, 'function bar(n){return 3*n}function baz(n){return n/2}function foo(n){print("Foo:",2*n)}var print=console.log.bind(console);print("qux",bar(3),baz(12)),foo(11);');
|
assert.strictEqual(result.code, 'var print=console.log.bind(console);print("qux",function(n){return 3*n}(3),function(n){return n/2}(12)),function(n){print("Foo:",2*n)}(11);');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user