From 6c4f559920f84ec9d070e460be1f9739a46d9670 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Mon, 27 Mar 2017 00:04:52 +0800 Subject: [PATCH] simplify logic add tests --- lib/compress.js | 8 +------- test/compress/reduce_vars.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index f62becb0..590015ff 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -277,12 +277,6 @@ merge(Compressor.prototype, { d.fixed = false; } } - if (node instanceof AST_Lambda) { - node.variables.get("arguments").fixed = null; - node.argnames.forEach(function(arg) { - arg.definition().fixed = null; - }); - } if (node instanceof AST_Defun) { var d = node.name.definition(); if (!toplevel && d.global || is_safe(d)) { @@ -364,7 +358,7 @@ merge(Compressor.prototype, { function is_safe(def) { for (var i = safe_ids.length, id = def.id; --i >= 0;) { if (safe_ids[i][id]) { - if (def.fixed === null) { + if (def.fixed == null) { var orig = def.orig[0]; if (orig instanceof AST_SymbolFunarg || orig.name == "arguments") return false; def.fixed = make_node(AST_Undefined, orig); diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index a76d476f..87942ab9 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -1823,3 +1823,34 @@ redefine_farg_3: { } expect_stdout: "object number undefined" } + +delay_def: { + options = { + evaluate: true, + reduce_vars: true, + unused: true, + } + input: { + function f() { + return a; + var a; + } + function g() { + return a; + var a = 1; + } + console.log(f(), g()); + } + expect: { + function f() { + return a; + var a; + } + function g() { + return a; + var a = 1; + } + console.log(f(), g()); + } + expect_stdout: true +}