Skip to content

Commit c911704

Browse files
authoredDec 27, 2022
fix corner case in functions & inline (#5767)
fixes #5766
1 parent f2b6f1d commit c911704

File tree

3 files changed

+84
-3
lines changed

3 files changed

+84
-3
lines changed
 

‎.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
test:
88
strategy:
99
matrix:
10-
node: [ '0.10', '0.12', '4', '6', '8', '10', '12', '14', '16', latest ]
10+
node: [ '0.10', '0.12', '4', '6', '8', '10', '12', '14', '16', '18' ]
1111
os: [ ubuntu-latest, windows-latest ]
1212
script: [ compress, mocha, release/benchmark, release/jetstream ]
1313
name: ${{ matrix.node }} ${{ matrix.os }} ${{ matrix.script }}

‎lib/compress.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -7498,6 +7498,7 @@ Compressor.prototype.compress = function(node) {
74987498
});
74997499
body.push(defun);
75007500
if (value !== fn) [].push.apply(side_effects, value.expressions.slice(0, -1));
7501+
sym.eliminated++;
75017502
} else {
75027503
if (drop_sym
75037504
&& var_defs[sym.id] > 1
@@ -14065,8 +14066,12 @@ Compressor.prototype.compress = function(node) {
1406514066
def.single_use = false;
1406614067
if (!in_loop) return;
1406714068
if (def.references.length == def.replaced) return;
14068-
if (def.orig.length == def.eliminated) return;
14069-
if (def.orig.length == 1 && fn.functions.has(name)) return;
14069+
switch (def.orig.length - def.eliminated) {
14070+
case 0:
14071+
return;
14072+
case 1:
14073+
if (fn.functions.has(name)) return;
14074+
}
1407014075
if (!all(def.orig, function(sym) {
1407114076
if (sym instanceof AST_SymbolConst) return false;
1407214077
if (sym instanceof AST_SymbolFunarg) return !sym.unused && def.scope.resolve() !== fn;

‎test/compress/functions.js

+76
Original file line numberDiff line numberDiff line change
@@ -8741,3 +8741,79 @@ issue_5692: {
87418741
}
87428742
expect_stdout: "PASS"
87438743
}
8744+
8745+
issue_5766_1: {
8746+
options = {
8747+
booleans: true,
8748+
evaluate: true,
8749+
functions: true,
8750+
inline: true,
8751+
passes: 2,
8752+
reduce_vars: true,
8753+
toplevel: true,
8754+
unused: true,
8755+
}
8756+
input: {
8757+
log = function(a) {
8758+
console.log(typeof a);
8759+
};
8760+
do {
8761+
(function() {
8762+
try {
8763+
var f = function() {};
8764+
log(f && f);
8765+
} catch (e) {}
8766+
})();
8767+
} while (0);
8768+
}
8769+
expect: {
8770+
log = function(a) {
8771+
console.log(typeof a);
8772+
};
8773+
do {
8774+
try {
8775+
function f() {}
8776+
log(f);
8777+
} catch (e) {}
8778+
} while (0);
8779+
}
8780+
expect_stdout: "function"
8781+
}
8782+
8783+
issue_5766_2: {
8784+
options = {
8785+
evaluate: true,
8786+
functions: true,
8787+
inline: true,
8788+
passes: 2,
8789+
reduce_vars: true,
8790+
side_effects: true,
8791+
toplevel: true,
8792+
unused: true,
8793+
}
8794+
input: {
8795+
log = function(a) {
8796+
console.log(typeof a);
8797+
};
8798+
do {
8799+
(function() {
8800+
try {
8801+
var f = function() {};
8802+
log(f && f);
8803+
} catch (e) {}
8804+
})();
8805+
} while (0);
8806+
}
8807+
expect: {
8808+
log = function(a) {
8809+
console.log(typeof a);
8810+
};
8811+
do {
8812+
try {
8813+
function f() {}
8814+
log(f);
8815+
} catch (e) {}
8816+
} while (0);
8817+
}
8818+
expect_stdout: "function"
8819+
}

0 commit comments

Comments
 (0)
Please sign in to comment.