Skip to content

Commit

Permalink
fix corner case in functions & inline (#5767)
Browse files Browse the repository at this point in the history
fixes #5766
  • Loading branch information
alexlamsl authored Dec 27, 2022
1 parent f2b6f1d commit c911704
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
9 changes: 7 additions & 2 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
76 changes: 76 additions & 0 deletions test/compress/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit c911704

Please sign in to comment.