Skip to content

Commit

Permalink
fix corner case in pure_getters (#5617)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl authored Aug 13, 2022
1 parent 612701a commit dd90135
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -4469,7 +4469,13 @@ Compressor.prototype.compress = function(node) {
def(AST_Binary, function(compressor) {
return lazy_op[this.operator] && (this.left._dot_throw(compressor) || this.right._dot_throw(compressor));
});
def(AST_Class, return_false);
def(AST_Class, function(compressor, force) {
return is_strict(compressor, force) && !all(this.properties, function(prop) {
if (prop.private) return true;
if (!prop.static) return true;
return !(prop instanceof AST_ClassGetter || prop instanceof AST_ClassSetter);
});
});
def(AST_Conditional, function(compressor) {
return this.consequent._dot_throw(compressor) || this.alternative._dot_throw(compressor);
});
Expand All @@ -4484,7 +4490,7 @@ Compressor.prototype.compress = function(node) {
def(AST_Null, return_true);
def(AST_Object, function(compressor, force) {
return is_strict(compressor, force) && !all(this.properties, function(prop) {
if (!(prop instanceof AST_ObjectKeyVal)) return false;
if (prop instanceof AST_ObjectGetter || prop instanceof AST_ObjectSetter) return false;
return !(prop.key === "__proto__" && prop.value._dot_throw(compressor, force));
});
});
Expand Down
50 changes: 50 additions & 0 deletions test/compress/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,56 @@ separate_name: {
node_version: ">=4"
}

static_getter: {
options = {
pure_getters: "strict",
side_effects: true,
}
input: {
"use strict";
(class {
static get p() {
console.log("PASS");
};
}).p;
}
expect: {
"use strict";
(class {
static get p() {
console.log("PASS");
};
}).p;
}
expect_stdout: "PASS"
node_version: ">=4"
}

static_setter: {
options = {
pure_getters: "strict",
side_effects: true,
}
input: {
"use strict";
(class {
static set p(v) {
console.log(v);
};
}).p = "PASS";
}
expect: {
"use strict";
(class {
static set p(v) {
console.log(v);
};
}).p = "PASS";
}
expect_stdout: "PASS"
node_version: ">=4"
}

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

0 comments on commit dd90135

Please sign in to comment.