@@ -5399,7 +5399,7 @@ Compressor.prototype.compress = function(node) {
|
||||
return any(this.properties, compressor);
|
||||
});
|
||||
def(AST_Dot, function(compressor) {
|
||||
return !this.optional && this.expression.may_throw_on_access(compressor)
|
||||
return this.expression.may_throw_on_access(compressor)
|
||||
|| this.expression.has_side_effects(compressor);
|
||||
});
|
||||
def(AST_EmptyStatement, return_false);
|
||||
@@ -5430,7 +5430,7 @@ Compressor.prototype.compress = function(node) {
|
||||
return this.body.has_side_effects(compressor);
|
||||
});
|
||||
def(AST_Sub, function(compressor) {
|
||||
return !this.optional && this.expression.may_throw_on_access(compressor)
|
||||
return this.expression.may_throw_on_access(compressor)
|
||||
|| this.expression.has_side_effects(compressor)
|
||||
|| this.property.has_side_effects(compressor);
|
||||
});
|
||||
@@ -8370,7 +8370,7 @@ Compressor.prototype.compress = function(node) {
|
||||
});
|
||||
def(AST_Dot, function(compressor, first_in_statement) {
|
||||
var expr = this.expression;
|
||||
if (!this.optional && expr.may_throw_on_access(compressor)) return this;
|
||||
if (expr.may_throw_on_access(compressor)) return this;
|
||||
return expr.drop_side_effect_free(compressor, first_in_statement);
|
||||
});
|
||||
def(AST_Function, function(compressor) {
|
||||
@@ -8429,17 +8429,8 @@ Compressor.prototype.compress = function(node) {
|
||||
});
|
||||
def(AST_Sub, function(compressor, first_in_statement) {
|
||||
var expr = this.expression;
|
||||
if (expr.may_throw_on_access(compressor)) return this;
|
||||
var prop = this.property;
|
||||
if (expr.may_throw_on_access(compressor)) {
|
||||
if (!this.optional) return this;
|
||||
if (prop.has_side_effects(compressor)) {
|
||||
prop = prop.drop_side_effect_free(compressor);
|
||||
if (!prop) return expr.drop_side_effect_free(compressor, first_in_statement);
|
||||
var node = this.clone();
|
||||
node.property = prop;
|
||||
return node;
|
||||
}
|
||||
}
|
||||
expr = expr.drop_side_effect_free(compressor, first_in_statement);
|
||||
if (!expr) return prop.drop_side_effect_free(compressor, first_in_statement);
|
||||
prop = prop.drop_side_effect_free(compressor);
|
||||
|
||||
@@ -361,7 +361,9 @@ issue_4906: {
|
||||
} while (console.log("PASS"));
|
||||
}
|
||||
expect: {
|
||||
do {} while (console.log("PASS"));
|
||||
do {
|
||||
var a = a?.[42];
|
||||
} while (console.log("PASS"));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=14"
|
||||
@@ -434,7 +436,7 @@ issue_5039: {
|
||||
console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
(function f() {});
|
||||
var a = a?.[function f() {}];
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
@@ -466,3 +468,152 @@ issue_5091: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=14"
|
||||
}
|
||||
|
||||
issue_5292_dot: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("PASS");
|
||||
}
|
||||
};
|
||||
o?.p;
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("PASS");
|
||||
}
|
||||
};
|
||||
o?.p;
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=14"
|
||||
}
|
||||
|
||||
issue_5292_dot_pure_getters: {
|
||||
options = {
|
||||
pure_getters: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("PASS");
|
||||
}
|
||||
};
|
||||
o?.p;
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("PASS");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
issue_5292_dot_pure_getters_strict: {
|
||||
options = {
|
||||
pure_getters: "strict",
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("PASS");
|
||||
}
|
||||
};
|
||||
o?.p;
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("PASS");
|
||||
}
|
||||
};
|
||||
o?.p;
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=14"
|
||||
}
|
||||
|
||||
issue_5292_sub: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("foo");
|
||||
}
|
||||
};
|
||||
o?.[console.log("bar"), "p"];
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("foo");
|
||||
}
|
||||
};
|
||||
o?.[console.log("bar"), "p"];
|
||||
}
|
||||
expect_stdout: [
|
||||
"bar",
|
||||
"foo",
|
||||
]
|
||||
node_version: ">=14"
|
||||
}
|
||||
|
||||
issue_5292_sub_pure_getters: {
|
||||
options = {
|
||||
pure_getters: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("foo");
|
||||
}
|
||||
};
|
||||
o?.[console.log("bar"), "p"];
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("foo");
|
||||
}
|
||||
};
|
||||
console.log("bar");
|
||||
}
|
||||
}
|
||||
|
||||
issue_5292_sub_pure_getters_strict: {
|
||||
options = {
|
||||
pure_getters: "strict",
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("foo");
|
||||
}
|
||||
};
|
||||
o?.[console.log("bar"), "p"];
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("foo");
|
||||
}
|
||||
};
|
||||
o?.[console.log("bar"), "p"];
|
||||
}
|
||||
expect_stdout: [
|
||||
"bar",
|
||||
"foo",
|
||||
]
|
||||
node_version: ">=14"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user