Skip to content

Commit

Permalink
enhance comparisons & reduce_vars (#4841)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Apr 3, 2021
1 parent 0df0281 commit aed758e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/compress.js
Expand Up @@ -9674,6 +9674,7 @@ merge(Compressor.prototype, {
if (node instanceof AST_Sequence) return is_object(node.tail_node());
if (node instanceof AST_SymbolRef) return is_object(node.fixed_value());
return node instanceof AST_Array
|| node instanceof AST_Class
|| node instanceof AST_Lambda
|| node instanceof AST_New
|| node instanceof AST_Object;
Expand Down
51 changes: 51 additions & 0 deletions test/compress/classes.js
Expand Up @@ -583,6 +583,31 @@ single_use_6: {
node_version: ">=4"
}

single_use_7: {
options = {
passes: 2,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
"use strict";
class A {
static foo() {}
}
var a = "foo" in A;
console.log(a);
}
expect: {
"use strict";
console.log("foo" in class {
static foo() {}
});
}
expect_stdout: "true"
node_version: ">=4"
}

collapse_non_strict: {
options = {
collapse_vars: true,
Expand Down Expand Up @@ -654,6 +679,32 @@ collapse_rhs_static: {
node_version: ">=12"
}

self_comparison: {
options = {
booleans: true,
comparisons: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
"use strict";
class A {}
console.log(A == A, A != A);
console.log(A === A, A !== A);
}
expect: {
"use strict";
console.log(!0, !1);
console.log(!0, !1);
}
expect_stdout: [
"true false",
"true false",
]
node_version: ">=4"
}

property_side_effects: {
options = {
inline: true,
Expand Down

0 comments on commit aed758e

Please sign in to comment.