handle AST_Super in collapse_vars & side_effects
This commit is contained in:
@@ -579,6 +579,7 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
|
||||
function is_lhs_read_only(lhs) {
|
||||
if (lhs instanceof AST_Super) return true;
|
||||
if (lhs instanceof AST_This) return true;
|
||||
if (lhs instanceof AST_SymbolRef) return lhs.definition().orig[0] instanceof AST_SymbolLambda;
|
||||
if (lhs instanceof AST_PropAccess) {
|
||||
@@ -2109,6 +2110,7 @@ merge(Compressor.prototype, {
|
||||
|
||||
def(AST_EmptyStatement, return_false);
|
||||
def(AST_Constant, return_false);
|
||||
def(AST_Super, return_false);
|
||||
def(AST_This, return_false);
|
||||
|
||||
def(AST_Call, function(compressor){
|
||||
@@ -2787,6 +2789,7 @@ merge(Compressor.prototype, {
|
||||
|
||||
def(AST_Node, return_this);
|
||||
def(AST_Constant, return_null);
|
||||
def(AST_Super, return_null);
|
||||
def(AST_This, return_null);
|
||||
def(AST_Call, function(compressor, first_in_statement){
|
||||
if (!this.is_expr_pure(compressor)) {
|
||||
|
||||
@@ -672,3 +672,51 @@ issue_2313_6: {
|
||||
x();
|
||||
}
|
||||
}
|
||||
|
||||
issue_2313_7: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
conditionals: true,
|
||||
pure_getters: true,
|
||||
}
|
||||
input: {
|
||||
var a = 0, b = 0;
|
||||
class foo {
|
||||
get c() {
|
||||
a++;
|
||||
return 42;
|
||||
}
|
||||
set c(c) {
|
||||
b++;
|
||||
}
|
||||
}
|
||||
class bar extends foo {
|
||||
d() {
|
||||
super.c++;
|
||||
if (super.c) console.log(a, b);
|
||||
}
|
||||
}
|
||||
new bar().d();
|
||||
}
|
||||
expect: {
|
||||
var a = 0, b = 0;
|
||||
class foo {
|
||||
get c() {
|
||||
a++;
|
||||
return 42;
|
||||
}
|
||||
set c(c) {
|
||||
b++;
|
||||
}
|
||||
}
|
||||
class bar extends foo {
|
||||
d() {
|
||||
super.c++;
|
||||
super.c && console.log(a, b);
|
||||
}
|
||||
}
|
||||
new bar().d();
|
||||
}
|
||||
expect_stdout: "2 1"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user