if (!stop_if_hit && in_conditional(node, parent)) {
stop_if_hit = parent;
}
+ // Skip transient nodes caused by single-use variable replacement
+ if (node.single_use && parent instanceof AST_VarDef && parent.value === node) return node;
// Replace variable with assignment when found
var hit_rhs;
if (can_replace
def.value = null;
head.push(def);
} else {
- var value = def.value
- && !def.value.single_use
- && def.value.drop_side_effect_free(compressor);
+ var value = def.value && def.value.drop_side_effect_free(compressor);
if (value) {
AST_Node.warn("Side effects in initialization of unused variable {name} [{file}:{line},{col}]", template(def.name));
side_effects.push(value);
}
expect_stdout: "2"
}
+
+issue_3520: {
+ options = {
+ collapse_vars: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ var a = 0;
+ var b = function(c) {
+ for (var i = 2; --i >= 0;) {
+ (function f() {
+ c = 0;
+ var i = void 0;
+ var f = f && f[i];
+ })();
+ a += b;
+ c && b++;
+ }
+ }(b = 1);
+ console.log(a);
+ }
+ expect: {
+ var a = 0;
+ var b = function(c) {
+ for (var i = 2; --i >= 0;) {
+ (function() {
+ c = 0;
+ var f = f && f[void 0];
+ })();
+ a += b;
+ c && b++;
+ }
+ }(b = 1);
+ console.log(a);
+ }
+ expect_stdout: "2"
+}