Skip to content

Commit 76803d6

Browse files
authored
enhance unsafe (#5903)
1 parent 15c8edb commit 76803d6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/compress.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12642,6 +12642,7 @@ Compressor.prototype.compress = function(node) {
1264212642
}
1264312643

1264412644
function is_indexFn(node) {
12645+
while (node instanceof AST_Assign && node.operator == "=") node = node.right;
1264512646
return node.TYPE == "Call"
1264612647
&& node.expression instanceof AST_Dot
1264712648
&& indexFns[node.expression.property];

test/compress/comparisons.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,28 @@ unsafe_indexOf: {
471471
]
472472
}
473473

474+
unsafe_indexOf_assignment: {
475+
options = {
476+
booleans: true,
477+
comparisons: true,
478+
unsafe: true,
479+
}
480+
input: {
481+
var a;
482+
if ((a = Object.keys({ foo: 42 }).indexOf("bar")) < 0) console.log("PASS");
483+
if (0 > (a = Object.keys({ foo: 42 }).indexOf("bar"))) console.log("PASS");
484+
}
485+
expect: {
486+
var a;
487+
if (!~(a = Object.keys({ foo: 42 }).indexOf("bar"))) console.log("PASS");
488+
if (!~(a = Object.keys({ foo: 42 }).indexOf("bar"))) console.log("PASS");
489+
}
490+
expect_stdout: [
491+
"PASS",
492+
"PASS",
493+
]
494+
}
495+
474496
issue_3413: {
475497
options = {
476498
comparisons: true,

0 commit comments

Comments
 (0)