Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e219a9a78a | ||
|
|
c80eabd61e | ||
|
|
9b82f9be91 | ||
|
|
657d525c80 | ||
|
|
6a3fe9d1df |
@@ -884,15 +884,12 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
if (ld && right instanceof AST_LambdaExpression) {
|
if (ld && right instanceof AST_LambdaExpression) {
|
||||||
walk_assign();
|
walk_assign();
|
||||||
if (ld.escaped.length) {
|
|
||||||
right.walk(tw);
|
|
||||||
} else {
|
|
||||||
right.parent_scope.resolve().fn_defs.push(right);
|
right.parent_scope.resolve().fn_defs.push(right);
|
||||||
right.safe_ids = null;
|
right.safe_ids = null;
|
||||||
if (!node.write_only) mark_fn_def(tw, ld, right);
|
if (!ld.fixed || !node.write_only) mark_fn_def(tw, ld, right);
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
} else if (scan) {
|
}
|
||||||
|
if (scan) {
|
||||||
right.walk(tw);
|
right.walk(tw);
|
||||||
walk_assign();
|
walk_assign();
|
||||||
return true;
|
return true;
|
||||||
@@ -984,7 +981,10 @@ merge(Compressor.prototype, {
|
|||||||
if (fixed && !modified && !sym.in_arg && safe_to_assign(tw, d)) {
|
if (fixed && !modified && !sym.in_arg && safe_to_assign(tw, d)) {
|
||||||
push_ref(d, sym);
|
push_ref(d, sym);
|
||||||
mark(tw, d);
|
mark(tw, d);
|
||||||
if (d.single_use && left instanceof AST_Destructured) d.single_use = false;
|
if (left instanceof AST_Destructured
|
||||||
|
|| d.orig.length == 1 && d.orig[0] instanceof AST_SymbolDefun) {
|
||||||
|
d.single_use = false;
|
||||||
|
}
|
||||||
tw.loop_ids[d.id] = tw.in_loop;
|
tw.loop_ids[d.id] = tw.in_loop;
|
||||||
mark_escaped(tw, d, sym.scope, node, right, 0, 1);
|
mark_escaped(tw, d, sym.scope, node, right, 0, 1);
|
||||||
sym.fixed = d.fixed = fixed;
|
sym.fixed = d.fixed = fixed;
|
||||||
@@ -1397,13 +1397,20 @@ merge(Compressor.prototype, {
|
|||||||
var node = this;
|
var node = this;
|
||||||
var value = node.value;
|
var value = node.value;
|
||||||
if (value instanceof AST_LambdaExpression && node.name instanceof AST_SymbolDeclaration) {
|
if (value instanceof AST_LambdaExpression && node.name instanceof AST_SymbolDeclaration) {
|
||||||
|
walk_defn();
|
||||||
value.parent_scope.resolve().fn_defs.push(value);
|
value.parent_scope.resolve().fn_defs.push(value);
|
||||||
value.safe_ids = null;
|
value.safe_ids = null;
|
||||||
|
var ld = node.name.definition();
|
||||||
|
if (!ld.fixed) mark_fn_def(tw, ld, value);
|
||||||
} else if (value) {
|
} else if (value) {
|
||||||
value.walk(tw);
|
value.walk(tw);
|
||||||
} else if (!(tw.parent() instanceof AST_Let)) {
|
walk_defn();
|
||||||
return;
|
} else if (tw.parent() instanceof AST_Let) {
|
||||||
|
walk_defn();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
function walk_defn() {
|
||||||
scan_declaration(tw, compressor, node.name, function() {
|
scan_declaration(tw, compressor, node.name, function() {
|
||||||
return node.value || make_node(AST_Undefined, node);
|
return node.value || make_node(AST_Undefined, node);
|
||||||
}, function(name, fixed) {
|
}, function(name, fixed) {
|
||||||
@@ -1421,7 +1428,7 @@ merge(Compressor.prototype, {
|
|||||||
d.fixed = false;
|
d.fixed = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
}
|
||||||
});
|
});
|
||||||
def(AST_While, function(tw, descend) {
|
def(AST_While, function(tw, descend) {
|
||||||
var save_loop = tw.in_loop;
|
var save_loop = tw.in_loop;
|
||||||
@@ -7294,12 +7301,11 @@ merge(Compressor.prototype, {
|
|||||||
if (value === null) {
|
if (value === null) {
|
||||||
value = make_node(AST_Number, node, { value: 0 });
|
value = make_node(AST_Number, node, { value: 0 });
|
||||||
} else if (value) {
|
} else if (value) {
|
||||||
if (value.may_throw_on_access(compressor, true)) value = make_sequence(node, [
|
if (value.tail_node().write_only === true || value.may_throw_on_access(compressor, true)) {
|
||||||
value,
|
value = make_node(AST_Array, node, {
|
||||||
make_node(AST_Number, node, { value: 0 }),
|
elements: value instanceof AST_Sequence ? value.expressions : [ value ],
|
||||||
]);
|
});
|
||||||
} else if (node instanceof AST_DestructuredArray) {
|
}
|
||||||
return make_node(AST_DestructuredArray, node, { elements: [] });
|
|
||||||
}
|
}
|
||||||
return make_node(AST_DestructuredObject, node, { properties: [] });
|
return make_node(AST_DestructuredObject, node, { properties: [] });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,8 @@ function minify(files, options) {
|
|||||||
var timings = options.timings && { start: Date.now() };
|
var timings = options.timings && { start: Date.now() };
|
||||||
if (options.rename === undefined) options.rename = options.compress && options.mangle;
|
if (options.rename === undefined) options.rename = options.compress && options.mangle;
|
||||||
if (options.annotations !== undefined) set_shorthand("annotations", options, [ "compress", "output" ]);
|
if (options.annotations !== undefined) set_shorthand("annotations", options, [ "compress", "output" ]);
|
||||||
if (options.ie || options.ie8) set_shorthand("ie", options, [ "compress", "mangle", "output" ]);
|
if (options.ie8) options.ie = options.ie || options.ie8;
|
||||||
|
if (options.ie) set_shorthand("ie", options, [ "compress", "mangle", "output" ]);
|
||||||
if (options.keep_fnames) set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
|
if (options.keep_fnames) set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
|
||||||
if (options.toplevel) set_shorthand("toplevel", options, [ "compress", "mangle" ]);
|
if (options.toplevel) set_shorthand("toplevel", options, [ "compress", "mangle" ]);
|
||||||
if (options.v8) set_shorthand("v8", options, [ "mangle", "output" ]);
|
if (options.v8) set_shorthand("v8", options, [ "mangle", "output" ]);
|
||||||
|
|||||||
@@ -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.14.0",
|
"version": "3.14.1",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -556,7 +556,7 @@ reduce_iife_3: {
|
|||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
reduce_lambda: {
|
reduce_lambda_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
@@ -588,6 +588,43 @@ reduce_lambda: {
|
|||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reduce_lambda_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(f, a, b) {
|
||||||
|
f = () => {
|
||||||
|
console.log(a, b);
|
||||||
|
};
|
||||||
|
a = "foo", b = 42;
|
||||||
|
f();
|
||||||
|
b = "bar";
|
||||||
|
f();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(f, a, b) {
|
||||||
|
f = () => {
|
||||||
|
console.log("foo", b);
|
||||||
|
};
|
||||||
|
b = 42;
|
||||||
|
f();
|
||||||
|
b = "bar";
|
||||||
|
f();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo 42",
|
||||||
|
"foo bar",
|
||||||
|
]
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
single_use_recursive: {
|
single_use_recursive: {
|
||||||
options = {
|
options = {
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
|
|||||||
@@ -6413,3 +6413,155 @@ issue_5067: {
|
|||||||
}
|
}
|
||||||
expect: {}
|
expect: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5096_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a, b = "FAIL", c = 1;
|
||||||
|
do {
|
||||||
|
a && a();
|
||||||
|
a = function() {
|
||||||
|
b = "PASS";
|
||||||
|
};
|
||||||
|
} while (c--);
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a, b = "FAIL", c = 1;
|
||||||
|
do {
|
||||||
|
a && a();
|
||||||
|
a = function() {
|
||||||
|
b = "PASS";
|
||||||
|
};
|
||||||
|
} while (c--);
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5096_2: {
|
||||||
|
options = {
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a, b = "FAIL", c = 1;
|
||||||
|
do {
|
||||||
|
a && a();
|
||||||
|
a = function() {
|
||||||
|
b = "PASS";
|
||||||
|
};
|
||||||
|
} while (c--);
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a, b = "FAIL", c = 1;
|
||||||
|
do {
|
||||||
|
a && a();
|
||||||
|
a = function() {
|
||||||
|
b = "PASS";
|
||||||
|
};
|
||||||
|
} while (c--);
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5096_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var b = "FAIL", c = 1;
|
||||||
|
do {
|
||||||
|
a && a();
|
||||||
|
var a = function() {
|
||||||
|
b = "PASS";
|
||||||
|
};
|
||||||
|
} while (c--);
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var b = "FAIL", c = 1;
|
||||||
|
do {
|
||||||
|
a && a();
|
||||||
|
var a = function() {
|
||||||
|
b = "PASS";
|
||||||
|
};
|
||||||
|
} while (c--);
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5096_4: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var b = "FAIL", c = 1;
|
||||||
|
do {
|
||||||
|
a && a();
|
||||||
|
var a = function() {
|
||||||
|
b = "PASS";
|
||||||
|
};
|
||||||
|
} while (c--);
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var b = "FAIL", c = 1;
|
||||||
|
do {
|
||||||
|
a && a();
|
||||||
|
var a = function() {
|
||||||
|
b = "PASS";
|
||||||
|
};
|
||||||
|
} while (c--);
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5098: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(o) {
|
||||||
|
function f() {
|
||||||
|
f = console.log;
|
||||||
|
if (o.p++)
|
||||||
|
throw "FAIL";
|
||||||
|
f("PASS");
|
||||||
|
}
|
||||||
|
return f;
|
||||||
|
})({ p: 0 })();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(o) {
|
||||||
|
function f() {
|
||||||
|
f = console.log;
|
||||||
|
if (o.p++)
|
||||||
|
throw "FAIL";
|
||||||
|
f("PASS");
|
||||||
|
}
|
||||||
|
return f;
|
||||||
|
})({ p: 0 })();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1003,3 +1003,69 @@ issue_5089_2: {
|
|||||||
expect_stdout: "undefined"
|
expect_stdout: "undefined"
|
||||||
node_version: ">=8"
|
node_version: ">=8"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5100_1: {
|
||||||
|
options = {
|
||||||
|
passes: 2,
|
||||||
|
pure_getters: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
[ {
|
||||||
|
p: {},
|
||||||
|
...a
|
||||||
|
} ] = [ {
|
||||||
|
p: {
|
||||||
|
q: a,
|
||||||
|
} = 42,
|
||||||
|
r: "PASS",
|
||||||
|
} ];
|
||||||
|
console.log(a.r);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
[ {
|
||||||
|
p: {},
|
||||||
|
...a
|
||||||
|
} ] = [ {
|
||||||
|
p: [ a = 42["q"] ],
|
||||||
|
r: "PASS",
|
||||||
|
} ];
|
||||||
|
console.log(a.r);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=8"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5100_2: {
|
||||||
|
options = {
|
||||||
|
passes: 2,
|
||||||
|
pure_getters: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
[ {
|
||||||
|
p: {},
|
||||||
|
...a
|
||||||
|
} ] = [ {
|
||||||
|
p: (console.log("PASS"), {
|
||||||
|
q: a,
|
||||||
|
} = 42),
|
||||||
|
} ];
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
[ {
|
||||||
|
p: {},
|
||||||
|
...a
|
||||||
|
} ] = [ {
|
||||||
|
p: [ console.log("PASS"), a = 42["q"] ],
|
||||||
|
} ];
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=10"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user