Skip to content

Commit

Permalink
Make class property assignment pure.
Browse files Browse the repository at this point in the history
Closes #724
  • Loading branch information
fabiosantoscode committed Jun 13, 2020
1 parent ee965e8 commit 283f44f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/compress/index.js
Expand Up @@ -2466,6 +2466,10 @@ function is_undefined(node, compressor) {
if (this.properties[i]._dot_throw(compressor)) return true;
return false;
});
// Do not be as strict with classes as we are with objects.
// Hopefully the community is not going to abuse static getters and setters.
// https://github.com/terser/terser/issues/724#issuecomment-643655656
def_may_throw_on_access(AST_Class, return_false);
def_may_throw_on_access(AST_ObjectProperty, return_false);
def_may_throw_on_access(AST_ObjectGetter, return_true);
def_may_throw_on_access(AST_Expansion, function(compressor) {
Expand Down
16 changes: 16 additions & 0 deletions test/compress/classes.js
Expand Up @@ -79,3 +79,19 @@ class_duplication_2: {
}
}

pure_prop_assignment_for_classes: {
options = {
defaults: true,
toplevel: true
}
input: {
class A {}
A.staticProp = "A"

class B {
static get danger() { }
}
B.staticProp = ""
}
expect: { }
}

0 comments on commit 283f44f

Please sign in to comment.