Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61a0dad9fe | ||
|
|
3e2c51a4da | ||
|
|
0e29ad5eb9 |
@@ -1235,7 +1235,7 @@ merge(Compressor.prototype, {
|
|||||||
var lvalues = get_lvalues(candidate);
|
var lvalues = get_lvalues(candidate);
|
||||||
var lhs_local = is_lhs_local(lhs);
|
var lhs_local = is_lhs_local(lhs);
|
||||||
if (!side_effects) side_effects = value_has_side_effects(candidate);
|
if (!side_effects) side_effects = value_has_side_effects(candidate);
|
||||||
var replace_all = replace_all_symbols();
|
var replace_all = replace_all_symbols(candidate);
|
||||||
var may_throw = candidate.may_throw(compressor) ? in_try ? function(node) {
|
var may_throw = candidate.may_throw(compressor) ? in_try ? function(node) {
|
||||||
return node.has_side_effects(compressor);
|
return node.has_side_effects(compressor);
|
||||||
} : side_effects_external : return_false;
|
} : side_effects_external : return_false;
|
||||||
@@ -1312,6 +1312,7 @@ merge(Compressor.prototype, {
|
|||||||
|
|
||||||
function in_conditional(node, parent) {
|
function in_conditional(node, parent) {
|
||||||
if (parent instanceof AST_Binary) return lazy_op[parent.operator] && parent.left !== node;
|
if (parent instanceof AST_Binary) return lazy_op[parent.operator] && parent.left !== node;
|
||||||
|
if (parent instanceof AST_Case) return parent.expression !== node;
|
||||||
if (parent instanceof AST_Conditional) return parent.condition !== node;
|
if (parent instanceof AST_Conditional) return parent.condition !== node;
|
||||||
return parent instanceof AST_If && parent.condition !== node;
|
return parent instanceof AST_If && parent.condition !== node;
|
||||||
}
|
}
|
||||||
@@ -1477,19 +1478,43 @@ merge(Compressor.prototype, {
|
|||||||
if (parent instanceof AST_Call) return node;
|
if (parent instanceof AST_Call) return node;
|
||||||
if (parent instanceof AST_Case) return node;
|
if (parent instanceof AST_Case) return node;
|
||||||
if (parent instanceof AST_Conditional) return node;
|
if (parent instanceof AST_Conditional) return node;
|
||||||
if (parent instanceof AST_Definitions) return find_stop(parent, level + 1);
|
if (parent instanceof AST_Definitions) return find_stop_unused(parent, level + 1);
|
||||||
if (parent instanceof AST_Exit) return node;
|
if (parent instanceof AST_Exit) return node;
|
||||||
if (parent instanceof AST_If) return node;
|
if (parent instanceof AST_If) return node;
|
||||||
if (parent instanceof AST_IterationStatement) return node;
|
if (parent instanceof AST_IterationStatement) return node;
|
||||||
if (parent instanceof AST_PropAccess) return node;
|
if (parent instanceof AST_PropAccess) return node;
|
||||||
if (parent instanceof AST_Sequence) return find_stop(parent, level + 1);
|
if (parent instanceof AST_Sequence) {
|
||||||
if (parent instanceof AST_SimpleStatement) return find_stop(parent, level + 1);
|
return (parent.tail_node() === node ? find_stop : find_stop_unused)(parent, level + 1);
|
||||||
|
}
|
||||||
|
if (parent instanceof AST_SimpleStatement) return find_stop_unused(parent, level + 1);
|
||||||
if (parent instanceof AST_Switch) return node;
|
if (parent instanceof AST_Switch) return node;
|
||||||
if (parent instanceof AST_Unary) return node;
|
if (parent instanceof AST_Unary) return node;
|
||||||
if (parent instanceof AST_VarDef) return node;
|
if (parent instanceof AST_VarDef) return node;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function find_stop_unused(node, level) {
|
||||||
|
var parent = scanner.parent(level);
|
||||||
|
if (is_last_node(node, parent)) return node;
|
||||||
|
if (in_conditional(node, parent)) return node;
|
||||||
|
if (parent instanceof AST_Assign) return find_stop_unused(parent, level + 1);
|
||||||
|
if (parent instanceof AST_Binary) return find_stop_unused(parent, level + 1);
|
||||||
|
if (parent instanceof AST_Call) return find_stop_unused(parent, level + 1);
|
||||||
|
if (parent instanceof AST_Case) return find_stop_unused(parent, level + 1);
|
||||||
|
if (parent instanceof AST_Conditional) return find_stop_unused(parent, level + 1);
|
||||||
|
if (parent instanceof AST_Definitions) return find_stop_unused(parent, level + 1);
|
||||||
|
if (parent instanceof AST_Exit) return find_stop_unused(parent, level + 1);
|
||||||
|
if (parent instanceof AST_If) return find_stop_unused(parent, level + 1);
|
||||||
|
if (parent instanceof AST_IterationStatement) return node;
|
||||||
|
if (parent instanceof AST_PropAccess) return find_stop_unused(parent, level + 1);
|
||||||
|
if (parent instanceof AST_Sequence) return find_stop_unused(parent, level + 1);
|
||||||
|
if (parent instanceof AST_SimpleStatement) return find_stop_unused(parent, level + 1);
|
||||||
|
if (parent instanceof AST_Switch) return find_stop_unused(parent, level + 1);
|
||||||
|
if (parent instanceof AST_Unary) return find_stop_unused(parent, level + 1);
|
||||||
|
if (parent instanceof AST_VarDef) return find_stop_unused(parent, level + 1);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function mangleable_var(var_def) {
|
function mangleable_var(var_def) {
|
||||||
var value = var_def.value;
|
var value = var_def.value;
|
||||||
if (!(value instanceof AST_SymbolRef)) return;
|
if (!(value instanceof AST_SymbolRef)) return;
|
||||||
@@ -1656,7 +1681,8 @@ merge(Compressor.prototype, {
|
|||||||
return get_rvalue(expr).has_side_effects(compressor);
|
return get_rvalue(expr).has_side_effects(compressor);
|
||||||
}
|
}
|
||||||
|
|
||||||
function replace_all_symbols() {
|
function replace_all_symbols(expr) {
|
||||||
|
if (expr instanceof AST_Unary) return false;
|
||||||
if (side_effects) return false;
|
if (side_effects) return false;
|
||||||
if (value_def) return true;
|
if (value_def) return true;
|
||||||
if (lhs instanceof AST_SymbolRef) {
|
if (lhs instanceof AST_SymbolRef) {
|
||||||
@@ -2881,6 +2907,7 @@ merge(Compressor.prototype, {
|
|||||||
if (!non_converting_binary[this.operator]) depth++;
|
if (!non_converting_binary[this.operator]) depth++;
|
||||||
var left = this.left._eval(compressor, cached, depth);
|
var left = this.left._eval(compressor, cached, depth);
|
||||||
if (left === this.left) return this;
|
if (left === this.left) return this;
|
||||||
|
if (this.operator == (left ? "||" : "&&")) return left;
|
||||||
var right = this.right._eval(compressor, cached, depth);
|
var right = this.right._eval(compressor, cached, depth);
|
||||||
if (right === this.right) return this;
|
if (right === this.right) return this;
|
||||||
var result;
|
var result;
|
||||||
@@ -3049,7 +3076,10 @@ merge(Compressor.prototype, {
|
|||||||
cached.push(node);
|
cached.push(node);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return stat.value ? stat.value._eval(compressor, cached, depth) : undefined;
|
if (!stat.value) return undefined;
|
||||||
|
var val = stat.value._eval(compressor, cached, depth);
|
||||||
|
if (val === stat.value) return this;
|
||||||
|
return val;
|
||||||
} else if (compressor.option("unsafe") && exp instanceof AST_PropAccess) {
|
} else if (compressor.option("unsafe") && exp instanceof AST_PropAccess) {
|
||||||
var key = exp.property;
|
var key = exp.property;
|
||||||
if (key instanceof AST_Node) {
|
if (key instanceof AST_Node) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||||
"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": "3.6.7",
|
"version": "3.6.8",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6387,3 +6387,51 @@ issue_3562: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS PASS"
|
expect_stdout: "PASS PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dot_throw_assign_sequence: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
var b;
|
||||||
|
b[0] = (a = "PASS", 0);
|
||||||
|
a = 1 + a;
|
||||||
|
} catch (c) {
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
var b;
|
||||||
|
b[0] = (a = "PASS", 0);
|
||||||
|
a = 1 + a;
|
||||||
|
} catch (c) {
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
call_assign_order: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a, b = 1, c = 0, log = console.log;
|
||||||
|
(function() {
|
||||||
|
a = b = "PASS";
|
||||||
|
})((b = "FAIL", c++));
|
||||||
|
log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a, b = 1, c = 0, log = console.log;
|
||||||
|
(function() {
|
||||||
|
a = b = "PASS";
|
||||||
|
})((b = "FAIL", c++));
|
||||||
|
log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1876,3 +1876,27 @@ issue_3558: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1 0"
|
expect_stdout: "1 0"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3568: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0;
|
||||||
|
function f(b) {
|
||||||
|
return b && b.p;
|
||||||
|
}
|
||||||
|
console.log(f(++a + f()));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 0;
|
||||||
|
function f(b) {
|
||||||
|
return b && b.p;
|
||||||
|
}
|
||||||
|
console.log(NaN);
|
||||||
|
}
|
||||||
|
expect_stdout: "NaN"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user