Skip to content

Commit

Permalink
enhance unsafe (#5903)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl authored Aug 1, 2024
1 parent 15c8edb commit 76803d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -12642,6 +12642,7 @@ Compressor.prototype.compress = function(node) {
}

function is_indexFn(node) {
while (node instanceof AST_Assign && node.operator == "=") node = node.right;
return node.TYPE == "Call"
&& node.expression instanceof AST_Dot
&& indexFns[node.expression.property];
Expand Down
22 changes: 22 additions & 0 deletions test/compress/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,28 @@ unsafe_indexOf: {
]
}

unsafe_indexOf_assignment: {
options = {
booleans: true,
comparisons: true,
unsafe: true,
}
input: {
var a;
if ((a = Object.keys({ foo: 42 }).indexOf("bar")) < 0) console.log("PASS");
if (0 > (a = Object.keys({ foo: 42 }).indexOf("bar"))) console.log("PASS");
}
expect: {
var a;
if (!~(a = Object.keys({ foo: 42 }).indexOf("bar"))) console.log("PASS");
if (!~(a = Object.keys({ foo: 42 }).indexOf("bar"))) console.log("PASS");
}
expect_stdout: [
"PASS",
"PASS",
]
}

issue_3413: {
options = {
comparisons: true,
Expand Down

0 comments on commit 76803d6

Please sign in to comment.