@@ -1556,12 +1556,17 @@ merge(Compressor.prototype, {
|
|||||||
if (node instanceof AST_Defun) return funarg && lhs.name === node.name.name;
|
if (node instanceof AST_Defun) return funarg && lhs.name === node.name.name;
|
||||||
if (node instanceof AST_DWLoop) return true;
|
if (node instanceof AST_DWLoop) return true;
|
||||||
if (node instanceof AST_LoopControl) return true;
|
if (node instanceof AST_LoopControl) return true;
|
||||||
|
if (node instanceof AST_SymbolRef) {
|
||||||
|
if (node.is_declared(compressor) ? node.fixed_value() || all(node.definition().orig, function(sym) {
|
||||||
|
return !(sym instanceof AST_SymbolConst || sym instanceof AST_SymbolLet);
|
||||||
|
}) : parent instanceof AST_Assign && parent.operator == "=" && parent.left === node) return false;
|
||||||
|
if (!replace_all) return true;
|
||||||
|
scan_rhs = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (node instanceof AST_Try) return true;
|
if (node instanceof AST_Try) return true;
|
||||||
if (node instanceof AST_With) return true;
|
if (node instanceof AST_With) return true;
|
||||||
if (replace_all) return false;
|
return false;
|
||||||
return node instanceof AST_SymbolRef
|
|
||||||
&& !node.is_declared(compressor)
|
|
||||||
&& !(parent instanceof AST_Assign && parent.operator == "=" && parent.left === node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function in_conditional(node, parent) {
|
function in_conditional(node, parent) {
|
||||||
@@ -1710,6 +1715,8 @@ merge(Compressor.prototype, {
|
|||||||
extract_candidates(expr.condition);
|
extract_candidates(expr.condition);
|
||||||
extract_candidates(expr.consequent);
|
extract_candidates(expr.consequent);
|
||||||
extract_candidates(expr.alternative);
|
extract_candidates(expr.alternative);
|
||||||
|
} else if (expr instanceof AST_Definitions) {
|
||||||
|
expr.definitions.forEach(extract_candidates);
|
||||||
} else if (expr instanceof AST_Dot) {
|
} else if (expr instanceof AST_Dot) {
|
||||||
extract_candidates(expr.expression);
|
extract_candidates(expr.expression);
|
||||||
} else if (expr instanceof AST_DWLoop) {
|
} else if (expr instanceof AST_DWLoop) {
|
||||||
@@ -1763,18 +1770,18 @@ merge(Compressor.prototype, {
|
|||||||
} else {
|
} else {
|
||||||
extract_candidates(expr.expression);
|
extract_candidates(expr.expression);
|
||||||
}
|
}
|
||||||
} else if (expr instanceof AST_Var) {
|
|
||||||
expr.definitions.forEach(extract_candidates);
|
|
||||||
} else if (expr instanceof AST_VarDef) {
|
} else if (expr instanceof AST_VarDef) {
|
||||||
if (expr.value) {
|
if (expr.name instanceof AST_SymbolVar) {
|
||||||
var def = expr.name.definition();
|
if (expr.value) {
|
||||||
if (def.references.length > def.replaced) {
|
var def = expr.name.definition();
|
||||||
candidates.push(hit_stack.slice());
|
if (def.references.length > def.replaced) {
|
||||||
|
candidates.push(hit_stack.slice());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
declare_only[expr.name.name] = (declare_only[expr.name.name] || 0) + 1;
|
||||||
}
|
}
|
||||||
extract_candidates(expr.value);
|
|
||||||
} else {
|
|
||||||
declare_only[expr.name.name] = (declare_only[expr.name.name] || 0) + 1;
|
|
||||||
}
|
}
|
||||||
|
if (expr.value) extract_candidates(expr.value);
|
||||||
}
|
}
|
||||||
hit_stack.pop();
|
hit_stack.pop();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8577,3 +8577,28 @@ issue_4242: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "undefined"
|
expect_stdout: "undefined"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_4248: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0;
|
||||||
|
try {
|
||||||
|
a = 1;
|
||||||
|
b[1];
|
||||||
|
} catch (e) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 0;
|
||||||
|
try {
|
||||||
|
a = 1;
|
||||||
|
b[1];
|
||||||
|
} catch (e) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1104,3 +1104,34 @@ issue_4245: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_4248: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
(function() {
|
||||||
|
a = "PASS";
|
||||||
|
b[a];
|
||||||
|
const b = 0;
|
||||||
|
})();
|
||||||
|
} catch (e) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
(function() {
|
||||||
|
a = "PASS";
|
||||||
|
b[a];
|
||||||
|
const b = 0;
|
||||||
|
})();
|
||||||
|
} catch (e) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -916,3 +916,37 @@ issue_4245: {
|
|||||||
expect_stdout: ReferenceError("a is not defined")
|
expect_stdout: ReferenceError("a is not defined")
|
||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_4248: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
a = "PASS";
|
||||||
|
b[a];
|
||||||
|
let b;
|
||||||
|
})();
|
||||||
|
} catch (e) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
a = "PASS";
|
||||||
|
b[a];
|
||||||
|
let b;
|
||||||
|
})();
|
||||||
|
} catch (e) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user