diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 53c44d3f..0e49efca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: test: strategy: matrix: - node: [ '0.10', '0.12', '4', '6', '8', '10', '12', '14', '16', latest ] + node: [ '0.10', '0.12', '4', '6', '8', '10', '12', '14', '16', '18' ] os: [ ubuntu-latest, windows-latest ] script: [ compress, mocha, release/benchmark, release/jetstream ] name: ${{ matrix.node }} ${{ matrix.os }} ${{ matrix.script }} diff --git a/lib/compress.js b/lib/compress.js index d7723c00..034a9e03 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -7498,6 +7498,7 @@ Compressor.prototype.compress = function(node) { }); body.push(defun); if (value !== fn) [].push.apply(side_effects, value.expressions.slice(0, -1)); + sym.eliminated++; } else { if (drop_sym && var_defs[sym.id] > 1 @@ -14065,8 +14066,12 @@ Compressor.prototype.compress = function(node) { def.single_use = false; if (!in_loop) return; if (def.references.length == def.replaced) return; - if (def.orig.length == def.eliminated) return; - if (def.orig.length == 1 && fn.functions.has(name)) return; + switch (def.orig.length - def.eliminated) { + case 0: + return; + case 1: + if (fn.functions.has(name)) return; + } if (!all(def.orig, function(sym) { if (sym instanceof AST_SymbolConst) return false; if (sym instanceof AST_SymbolFunarg) return !sym.unused && def.scope.resolve() !== fn; diff --git a/test/compress/functions.js b/test/compress/functions.js index 8a46879c..e0d504d7 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -8741,3 +8741,79 @@ issue_5692: { } expect_stdout: "PASS" } + +issue_5766_1: { + options = { + booleans: true, + evaluate: true, + functions: true, + inline: true, + passes: 2, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + log = function(a) { + console.log(typeof a); + }; + do { + (function() { + try { + var f = function() {}; + log(f && f); + } catch (e) {} + })(); + } while (0); + } + expect: { + log = function(a) { + console.log(typeof a); + }; + do { + try { + function f() {} + log(f); + } catch (e) {} + } while (0); + } + expect_stdout: "function" +} + +issue_5766_2: { + options = { + evaluate: true, + functions: true, + inline: true, + passes: 2, + reduce_vars: true, + side_effects: true, + toplevel: true, + unused: true, + } + input: { + log = function(a) { + console.log(typeof a); + }; + do { + (function() { + try { + var f = function() {}; + log(f && f); + } catch (e) {} + })(); + } while (0); + } + expect: { + log = function(a) { + console.log(typeof a); + }; + do { + try { + function f() {} + log(f); + } catch (e) {} + } while (0); + } + expect_stdout: "function" +}