enhance reduce_vars & varify (#4714)
This commit is contained in:
@@ -1259,10 +1259,13 @@ merge(Compressor.prototype, {
|
|||||||
});
|
});
|
||||||
def(AST_VarDef, function(tw, descend, compressor) {
|
def(AST_VarDef, function(tw, descend, compressor) {
|
||||||
var node = this;
|
var node = this;
|
||||||
if (!node.value) return;
|
if (node.value) {
|
||||||
node.value.walk(tw);
|
node.value.walk(tw);
|
||||||
|
} else if (!(tw.parent() instanceof AST_Let)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
scan_declaration(tw, compressor, node.name, function() {
|
scan_declaration(tw, compressor, node.name, function() {
|
||||||
return node.value;
|
return node.value || make_node(AST_Undefined, node);
|
||||||
}, function(name, fixed) {
|
}, function(name, fixed) {
|
||||||
var d = name.definition();
|
var d = name.definition();
|
||||||
if (fixed && safe_to_assign(tw, d, true)) {
|
if (fixed && safe_to_assign(tw, d, true)) {
|
||||||
|
|||||||
@@ -610,6 +610,28 @@ drop_unused: {
|
|||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default_init: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
let a;
|
||||||
|
a = "PASS";
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
issue_4191: {
|
issue_4191: {
|
||||||
options = {
|
options = {
|
||||||
functions: true,
|
functions: true,
|
||||||
|
|||||||
@@ -409,3 +409,31 @@ drop_forin_let: {
|
|||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default_init: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
varify: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
A = "PASS";
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
let a;
|
||||||
|
a = A;
|
||||||
|
console.log(a);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
A = "PASS";
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
var a = A;
|
||||||
|
console.log(a);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user