var lhs = get_lhs(candidate);
var side_effects = lhs && lhs.has_side_effects(compressor);
var scan_lhs = lhs && !side_effects && !is_lhs_read_only(lhs, compressor);
- var scan_rhs = foldable(get_rhs(candidate));
+ var scan_rhs = foldable(candidate);
if (!scan_lhs && !scan_rhs) continue;
var modify_toplevel = false;
// Locate symbols which may execute code outside of scanning range
}
}
- function get_rhs(expr) {
- return candidate instanceof AST_Assign && candidate.operator == "=" && candidate.right;
- }
-
function invariant(expr) {
if (expr instanceof AST_Array) return false;
if (expr instanceof AST_Binary && lazy_op[expr.operator]) {
}
function foldable(expr) {
- if (!expr) return false;
+ while (expr instanceof AST_Assign && expr.operator == "=") {
+ expr = expr.right;
+ }
if (expr instanceof AST_SymbolRef) {
var value = expr.evaluate(compressor);
if (value === expr) return rhs_exact_match;
}
expect_stdout: "function"
}
+
+issue_3894: {
+ options = {
+ collapse_vars: true,
+ inline: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ function log(msg) {
+ console.log(msg ? "FAIL" : "PASS");
+ }
+ var a, c;
+ (function(b) {
+ a = c = 0,
+ log(b);
+ })(-0);
+ log(a);
+ log(c);
+ }
+ expect: {
+ function log(msg) {
+ console.log(msg ? "FAIL" : "PASS");
+ }
+ var a, c;
+ void log(-(a = c = 0));
+ log(a);
+ log(c);
+ }
+ expect_stdout: [
+ "PASS",
+ "PASS",
+ "PASS",
+ ]
+}