Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa43768ce0 | ||
|
|
a74e600fa0 | ||
|
|
4b21526310 | ||
|
|
a7a7b1daed | ||
|
|
7436977aa5 | ||
|
|
e3c565b46f | ||
|
|
54b0b49b68 | ||
|
|
65648d84a5 |
@@ -1361,6 +1361,7 @@ merge(Compressor.prototype, {
|
||||
hit_stack.push(expr);
|
||||
if (expr instanceof AST_Assign) {
|
||||
candidates.push(hit_stack.slice());
|
||||
extract_candidates(expr.left);
|
||||
extract_candidates(expr.right);
|
||||
} else if (expr instanceof AST_Binary) {
|
||||
extract_candidates(expr.left);
|
||||
@@ -1376,6 +1377,8 @@ merge(Compressor.prototype, {
|
||||
extract_candidates(expr.alternative);
|
||||
} else if (expr instanceof AST_Definitions) {
|
||||
expr.definitions.forEach(extract_candidates);
|
||||
} else if (expr instanceof AST_Dot) {
|
||||
extract_candidates(expr.expression);
|
||||
} else if (expr instanceof AST_DWLoop) {
|
||||
extract_candidates(expr.condition);
|
||||
if (!(expr.body instanceof AST_Block)) {
|
||||
@@ -1407,6 +1410,9 @@ merge(Compressor.prototype, {
|
||||
expr.expressions.forEach(extract_candidates);
|
||||
} else if (expr instanceof AST_SimpleStatement) {
|
||||
extract_candidates(expr.body);
|
||||
} else if (expr instanceof AST_Sub) {
|
||||
extract_candidates(expr.expression);
|
||||
extract_candidates(expr.property);
|
||||
} else if (expr instanceof AST_Switch) {
|
||||
extract_candidates(expr.expression);
|
||||
expr.body.forEach(extract_candidates);
|
||||
@@ -1465,6 +1471,7 @@ merge(Compressor.prototype, {
|
||||
return node;
|
||||
}
|
||||
if (parent instanceof AST_IterationStatement) return node;
|
||||
if (parent instanceof AST_PropAccess) return node;
|
||||
if (parent instanceof AST_Sequence) {
|
||||
return find_stop(parent, level + 1, parent.tail_node() !== node);
|
||||
}
|
||||
@@ -2239,7 +2246,11 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
def(AST_SymbolRef, function() {
|
||||
var fixed = this.fixed_value();
|
||||
return fixed && fixed.is_truthy();
|
||||
if (!fixed) return false;
|
||||
this.is_truthy = return_false;
|
||||
var result = fixed.is_truthy();
|
||||
delete this.is_truthy;
|
||||
return result;
|
||||
});
|
||||
})(function(node, func) {
|
||||
node.DEFMETHOD("is_truthy", func);
|
||||
@@ -2293,7 +2304,11 @@ merge(Compressor.prototype, {
|
||||
if (is_undeclared_ref(this) && this.is_declared(compressor)) return false;
|
||||
if (this.is_immutable()) return false;
|
||||
var fixed = this.fixed_value();
|
||||
return !fixed || fixed._dot_throw(compressor);
|
||||
if (!fixed) return true;
|
||||
this._dot_throw = return_true;
|
||||
var result = fixed._dot_throw(compressor);
|
||||
delete this._dot_throw;
|
||||
return result;
|
||||
});
|
||||
def(AST_UnaryPrefix, function() {
|
||||
return this.operator == "void";
|
||||
@@ -2335,7 +2350,11 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
def(AST_SymbolRef, function(compressor) {
|
||||
var fixed = this.fixed_value();
|
||||
return fixed && fixed.is_boolean(compressor);
|
||||
if (!fixed) return false;
|
||||
this.is_boolean = return_false;
|
||||
var result = fixed.is_boolean(compressor);
|
||||
delete this.is_boolean;
|
||||
return result;
|
||||
});
|
||||
var unary = makePredicate("! delete");
|
||||
def(AST_UnaryPrefix, function() {
|
||||
@@ -2420,7 +2439,11 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
def(AST_SymbolRef, function(compressor) {
|
||||
var fixed = this.fixed_value();
|
||||
return fixed && fixed.is_number(compressor);
|
||||
if (!fixed) return false;
|
||||
this.is_number = return_false;
|
||||
var result = fixed.is_number(compressor);
|
||||
delete this.is_number;
|
||||
return result;
|
||||
});
|
||||
var unary = makePredicate("+ - ~ ++ --");
|
||||
def(AST_Unary, function() {
|
||||
@@ -2449,7 +2472,11 @@ merge(Compressor.prototype, {
|
||||
def(AST_String, return_true);
|
||||
def(AST_SymbolRef, function(compressor) {
|
||||
var fixed = this.fixed_value();
|
||||
return fixed && fixed.is_string(compressor);
|
||||
if (!fixed) return false;
|
||||
this.is_string = return_false;
|
||||
var result = fixed.is_string(compressor);
|
||||
delete this.is_string;
|
||||
return result;
|
||||
});
|
||||
def(AST_UnaryPrefix, function() {
|
||||
return this.operator == "typeof";
|
||||
@@ -5065,7 +5092,7 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
} while (!(scope instanceof AST_Scope));
|
||||
var safe_to_inject = (!(scope instanceof AST_Toplevel) || compressor.toplevel.vars)
|
||||
&& fn.parent_scope === compressor.find_parent(AST_Scope);
|
||||
&& (exp !== fn || fn.parent_scope === compressor.find_parent(AST_Scope));
|
||||
var inline = compressor.option("inline");
|
||||
if (!can_inject_vars(catches, inline >= 3 && safe_to_inject)) return false;
|
||||
if (!can_inject_args(catches, inline >= 2 && safe_to_inject)) return false;
|
||||
|
||||
14
lib/scope.js
14
lib/scope.js
@@ -198,24 +198,20 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
||||
}
|
||||
if (node instanceof AST_SymbolLambda) {
|
||||
var def = node.thedef;
|
||||
if (def.orig.length == 1) {
|
||||
redefine(node, node.scope.parent_scope);
|
||||
node.thedef.init = def.init;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
|
||||
function redefine(node, scope) {
|
||||
var name = node.name;
|
||||
var refs = node.thedef.references;
|
||||
var def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
|
||||
refs.forEach(function(ref) {
|
||||
ref.thedef = def;
|
||||
ref.reference(options);
|
||||
});
|
||||
node.thedef = def;
|
||||
var old_def = node.thedef;
|
||||
var new_def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
|
||||
old_def.orig.concat(old_def.references).forEach(function(node) {
|
||||
node.thedef = new_def;
|
||||
node.reference(options);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||
"license": "BSD-2-Clause",
|
||||
"version": "3.5.0",
|
||||
"version": "3.5.3",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
|
||||
@@ -3895,11 +3895,11 @@ issue_2436_10: {
|
||||
o = { b: 3 };
|
||||
return n;
|
||||
}
|
||||
console.log((c = o, [
|
||||
c.a,
|
||||
console.log([
|
||||
(c = o).a,
|
||||
f(c.b),
|
||||
c.b,
|
||||
]).join(" "));
|
||||
].join(" "));
|
||||
var c;
|
||||
}
|
||||
expect_stdout: "1 2 2"
|
||||
@@ -6121,3 +6121,39 @@ issue_3327: {
|
||||
}
|
||||
expect_stdout: "PASS 42"
|
||||
}
|
||||
|
||||
assign_left: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a, b) {
|
||||
(b = a, b.p).q = "PASS";
|
||||
return a.p.q;
|
||||
}({p: {}}));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a, b) {
|
||||
(b = a).p.q = "PASS";
|
||||
return a.p.q;
|
||||
}({p: {}}));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
sub_property: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a, b) {
|
||||
return a[(b = a, b.length - 1)];
|
||||
}([ "FAIL", "PASS" ]));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a, b) {
|
||||
return a[(b = a).length - 1];
|
||||
}([ "FAIL", "PASS" ]));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -1124,14 +1124,14 @@ issue_2207_1: {
|
||||
console.log(Math.max(3, 6, 2, 7, 3, 4));
|
||||
console.log(Math.cos(1.2345));
|
||||
console.log(Math.cos(1.2345) - Math.sin(4.321));
|
||||
console.log(Math.pow(Math.PI, Math.E - Math.LN10));
|
||||
console.log(Math.pow(Math.PI, Math.E - Math.LN10).toFixed(15));
|
||||
}
|
||||
expect: {
|
||||
console.log("A");
|
||||
console.log(7);
|
||||
console.log(Math.cos(1.2345));
|
||||
console.log(1.2543732512566947);
|
||||
console.log(1.6093984514472044);
|
||||
console.log("1.609398451447204");
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -2675,3 +2675,31 @@ cross_references_3: {
|
||||
"9 27",
|
||||
]
|
||||
}
|
||||
|
||||
loop_inline: {
|
||||
options = {
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(o) {
|
||||
function g(p) {
|
||||
return o[p];
|
||||
}
|
||||
function h(q) {
|
||||
while (g(q));
|
||||
}
|
||||
return h;
|
||||
}([ 1, "foo", 0 ])(2));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(o) {
|
||||
return function(q) {
|
||||
while (p = q, o[p]);
|
||||
var p;
|
||||
};
|
||||
}([ 1, "foo", 0 ])(2));
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
@@ -861,3 +861,111 @@ issue_3215_4: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3355_1: {
|
||||
mangle = {
|
||||
ie8: false,
|
||||
}
|
||||
input: {
|
||||
(function f() {
|
||||
var f;
|
||||
})();
|
||||
(function g() {
|
||||
})();
|
||||
console.log(typeof f === typeof g);
|
||||
}
|
||||
expect: {
|
||||
(function o() {
|
||||
var o;
|
||||
})();
|
||||
(function o() {
|
||||
})();
|
||||
console.log(typeof f === typeof g);
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
issue_3355_2: {
|
||||
mangle = {
|
||||
ie8: true,
|
||||
}
|
||||
input: {
|
||||
(function f() {
|
||||
var f;
|
||||
})();
|
||||
(function g() {
|
||||
})();
|
||||
console.log(typeof f === typeof g);
|
||||
}
|
||||
expect: {
|
||||
(function f() {
|
||||
var f;
|
||||
})();
|
||||
(function g() {
|
||||
})();
|
||||
console.log(typeof f === typeof g);
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
issue_3355_3: {
|
||||
mangle = {
|
||||
ie8: false,
|
||||
}
|
||||
input: {
|
||||
!function(a) {
|
||||
"aaaaaaaaaa";
|
||||
a();
|
||||
var b = function c() {
|
||||
var c = 42;
|
||||
console.log("FAIL");
|
||||
};
|
||||
}(function() {
|
||||
console.log("PASS");
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
!function(a) {
|
||||
"aaaaaaaaaa";
|
||||
a();
|
||||
var o = function a() {
|
||||
var a = 42;
|
||||
console.log("FAIL");
|
||||
};
|
||||
}(function() {
|
||||
console.log("PASS");
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3355_4: {
|
||||
mangle = {
|
||||
ie8: true,
|
||||
}
|
||||
input: {
|
||||
!function(a) {
|
||||
"aaaaaaaaaa";
|
||||
a();
|
||||
var b = function c() {
|
||||
var c = 42;
|
||||
console.log("FAIL");
|
||||
};
|
||||
}(function() {
|
||||
console.log("PASS");
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
!function(a) {
|
||||
"aaaaaaaaaa";
|
||||
a();
|
||||
var o = function n() {
|
||||
var n = 42;
|
||||
console.log("FAIL");
|
||||
};
|
||||
}(function() {
|
||||
console.log("PASS");
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user