Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73d082df2e | ||
|
|
50b8d7272c | ||
|
|
7d11b96f48 | ||
|
|
eab99a1c3d | ||
|
|
19e2fb134d | ||
|
|
f4919e3a25 |
@@ -85,13 +85,14 @@ merge(Compressor.prototype, {
|
|||||||
},
|
},
|
||||||
before: function(node, descend, in_list) {
|
before: function(node, descend, in_list) {
|
||||||
if (node._squeezed) return node;
|
if (node._squeezed) return node;
|
||||||
|
var was_scope = false;
|
||||||
if (node instanceof AST_Scope) {
|
if (node instanceof AST_Scope) {
|
||||||
//node.drop_unused(this);
|
|
||||||
node = node.hoist_declarations(this);
|
node = node.hoist_declarations(this);
|
||||||
|
was_scope = true;
|
||||||
}
|
}
|
||||||
descend(node, this);
|
descend(node, this);
|
||||||
node = node.optimize(this);
|
node = node.optimize(this);
|
||||||
if (node instanceof AST_Scope) {
|
if (was_scope && node instanceof AST_Scope) {
|
||||||
node.drop_unused(this);
|
node.drop_unused(this);
|
||||||
descend(node, this);
|
descend(node, this);
|
||||||
}
|
}
|
||||||
@@ -1865,6 +1866,14 @@ merge(Compressor.prototype, {
|
|||||||
return self.evaluate(compressor)[0];
|
return self.evaluate(compressor)[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function has_side_effects_or_prop_access(node, compressor) {
|
||||||
|
var save_pure_getters = compressor.option("pure_getters");
|
||||||
|
compressor.options.pure_getters = false;
|
||||||
|
var ret = node.has_side_effects(compressor);
|
||||||
|
compressor.options.pure_getters = save_pure_getters;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
AST_Binary.DEFMETHOD("lift_sequences", function(compressor){
|
AST_Binary.DEFMETHOD("lift_sequences", function(compressor){
|
||||||
if (compressor.option("sequences")) {
|
if (compressor.option("sequences")) {
|
||||||
if (this.left instanceof AST_Seq) {
|
if (this.left instanceof AST_Seq) {
|
||||||
@@ -1876,8 +1885,8 @@ merge(Compressor.prototype, {
|
|||||||
return seq;
|
return seq;
|
||||||
}
|
}
|
||||||
if (this.right instanceof AST_Seq
|
if (this.right instanceof AST_Seq
|
||||||
&& !(this.operator == "||" || this.operator == "&&")
|
&& this instanceof AST_Assign
|
||||||
&& !this.left.has_side_effects(compressor)) {
|
&& !has_side_effects_or_prop_access(this.left, compressor)) {
|
||||||
var seq = this.right;
|
var seq = this.right;
|
||||||
var x = seq.to_array();
|
var x = seq.to_array();
|
||||||
this.right = x.pop();
|
this.right = x.pop();
|
||||||
@@ -2022,16 +2031,6 @@ merge(Compressor.prototype, {
|
|||||||
&& self.right.getValue() === "" && self.left instanceof AST_Binary
|
&& self.right.getValue() === "" && self.left instanceof AST_Binary
|
||||||
&& self.left.operator == "+" && self.left.is_string(compressor)) {
|
&& self.left.operator == "+" && self.left.is_string(compressor)) {
|
||||||
return self.left;
|
return self.left;
|
||||||
} else if (self.operator == "+" && self.right instanceof AST_String
|
|
||||||
&& self.right.getValue() === "" && self.left instanceof AST_Binary
|
|
||||||
&& self.left.operator == "+" && self.left.right instanceof AST_Number) {
|
|
||||||
return make_node(AST_Binary, self, {
|
|
||||||
left: self.left.left,
|
|
||||||
operator: "+",
|
|
||||||
right: make_node(AST_String, self.right, {
|
|
||||||
value: String(self.left.right.value)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (compressor.option("evaluate")) {
|
if (compressor.option("evaluate")) {
|
||||||
if (self.operator == "+") {
|
if (self.operator == "+") {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||||
"homepage": "http://lisperator.net/uglifyjs",
|
"homepage": "http://lisperator.net/uglifyjs",
|
||||||
"main": "tools/node.js",
|
"main": "tools/node.js",
|
||||||
"version": "2.4.2",
|
"version": "2.4.4",
|
||||||
"engines": { "node" : ">=0.4.0" },
|
"engines": { "node" : ">=0.4.0" },
|
||||||
"maintainers": [{
|
"maintainers": [{
|
||||||
"name": "Mihai Bazon",
|
"name": "Mihai Bazon",
|
||||||
|
|||||||
@@ -54,15 +54,13 @@ strings_concat: {
|
|||||||
input: {
|
input: {
|
||||||
f(
|
f(
|
||||||
String(x + 'str'),
|
String(x + 'str'),
|
||||||
String('str' + x),
|
String('str' + x)
|
||||||
String(x + 5)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
f(
|
f(
|
||||||
x + 'str',
|
x + 'str',
|
||||||
'str' + x,
|
'str' + x
|
||||||
x + '5'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,10 +101,12 @@ lift_sequences_1: {
|
|||||||
lift_sequences_2: {
|
lift_sequences_2: {
|
||||||
options = { sequences: true, evaluate: true };
|
options = { sequences: true, evaluate: true };
|
||||||
input: {
|
input: {
|
||||||
q = 1 + (foo(), bar(), 5) + 7 * (5 / (3 - (a(), (QW=ER), c(), 2))) - (x(), y(), 5);
|
foo.x = (foo = {}, 10);
|
||||||
|
bar = (bar = {}, 10);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
foo(), bar(), a(), QW = ER, c(), x(), y(), q = 36
|
foo.x = (foo = {}, 10),
|
||||||
|
bar = {}, bar = 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user