Skip to content

Commit

Permalink
fix missing compressor argument in is_nullish and is_undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Jun 27, 2021
1 parent 215db3c commit 2835581
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions lib/compress/index.js
Expand Up @@ -3476,7 +3476,7 @@ const pure_prop_access_globals = new Set([
|| this.expression.has_side_effects(compressor);
});
def_has_side_effects(AST_Sub, function(compressor) {
if (this.optional && is_nullish(this.expression)) {
if (this.optional && is_nullish(this.expression, compressor)) {
return false;
}

Expand Down Expand Up @@ -3546,7 +3546,7 @@ const pure_prop_access_globals = new Set([
return any(this.body, compressor);
});
def_may_throw(AST_Call, function(compressor) {
if (this.optional && is_nullish(this.expression)) return false;
if (this.optional && is_nullish(this.expression, compressor)) return false;
if (any(this.args, compressor)) return true;
if (this.is_callee_pure(compressor)) return false;
if (this.expression.may_throw(compressor)) return true;
Expand Down Expand Up @@ -3609,7 +3609,7 @@ const pure_prop_access_globals = new Set([
|| this.expression.may_throw(compressor);
});
def_may_throw(AST_Sub, function(compressor) {
if (this.optional && is_nullish(this.expression)) return false;
if (this.optional && is_nullish(this.expression, compressor)) return false;

return !this.optional && this.expression.may_throw_on_access(compressor)
|| this.expression.may_throw(compressor)
Expand Down Expand Up @@ -4422,7 +4422,7 @@ AST_Scope.DEFMETHOD("hoist_properties", function(compressor) {
def_drop_side_effect_free(AST_Constant, return_null);
def_drop_side_effect_free(AST_This, return_null);
def_drop_side_effect_free(AST_Call, function(compressor, first_in_statement) {
if (this.optional && is_nullish(this.expression)) {
if (this.optional && is_nullish(this.expression, compressor)) {
return make_node(AST_Undefined, this);
}

Expand Down Expand Up @@ -4569,15 +4569,15 @@ AST_Scope.DEFMETHOD("hoist_properties", function(compressor) {
});
def_drop_side_effect_free(AST_Dot, function(compressor, first_in_statement) {
if (this.optional) {
return is_nullish(this.expression) ? make_node(AST_Undefined, this) : this;
return is_nullish(this.expression, compressor) ? make_node(AST_Undefined, this) : this;
}
if (this.expression.may_throw_on_access(compressor)) return this;

return this.expression.drop_side_effect_free(compressor, first_in_statement);
});
def_drop_side_effect_free(AST_Sub, function(compressor, first_in_statement) {
if (this.optional) {
return is_nullish(this.expression) ? make_node(AST_Undefined, this): this;
return is_nullish(this.expression, compressor) ? make_node(AST_Undefined, this): this;
}
if (this.expression.may_throw_on_access(compressor)) return this;

Expand Down Expand Up @@ -5144,7 +5144,7 @@ def_optimize(AST_Call, function(self, compressor) {
}
}

if (self.optional && is_nullish(fn)) {
if (self.optional && is_nullish(fn, compressor)) {
return make_node(AST_Undefined, self);
}

Expand Down Expand Up @@ -6170,7 +6170,7 @@ def_optimize(AST_Binary, function(self, compressor) {
}
break;
case "??":
if (is_nullish(self.left)) {
if (is_nullish(self.left, compressor)) {
return self.right;
}

Expand Down Expand Up @@ -6778,20 +6778,20 @@ def_optimize(AST_DefaultAssign, function(self, compressor) {
return self;
});

function is_nullish(node) {
function is_nullish(node, compressor) {
let fixed;
return (
node instanceof AST_Null
|| is_undefined(node)
|| (
node instanceof AST_SymbolRef
&& (fixed = node.definition().fixed) instanceof AST_Node
&& is_nullish(fixed)
&& is_nullish(fixed, compressor)
)
// Recurse into those optional chains!
|| node instanceof AST_PropAccess && node.optional && is_nullish(node.expression)
|| node instanceof AST_Call && node.optional && is_nullish(node.expression)
|| node instanceof AST_Chain && is_nullish(node.expression)
|| node instanceof AST_PropAccess && node.optional && is_nullish(node.expression, compressor)
|| node instanceof AST_Call && node.optional && is_nullish(node.expression, compressor)
|| node instanceof AST_Chain && is_nullish(node.expression, compressor)
);
}

Expand All @@ -6806,8 +6806,8 @@ function is_nullish_check(check, check_subject, compressor) {
&& check.operator === "=="
// which side is nullish?
&& (
(nullish_side = is_nullish(check.left) && check.left)
|| (nullish_side = is_nullish(check.right) && check.right)
(nullish_side = is_nullish(check.left, compressor) && check.left)
|| (nullish_side = is_nullish(check.right, compressor) && check.right)
)
// is the other side the same as the check_subject
&& (
Expand Down Expand Up @@ -6845,12 +6845,12 @@ function is_nullish_check(check, check_subject, compressor) {
null_cmp = cmp;
defined_side = cmp.left;
}
if (is_undefined(cmp.left)) {
if (is_undefined(cmp.left, compressor)) {
found++;
undefined_cmp = cmp;
defined_side = cmp.right;
}
if (is_undefined(cmp.right)) {
if (is_undefined(cmp.right, compressor)) {
found++;
undefined_cmp = cmp;
defined_side = cmp.left;
Expand Down Expand Up @@ -7351,7 +7351,7 @@ def_optimize(AST_Sub, function(self, compressor) {
ev = make_node_from_constant(ev, self).optimize(compressor);
return best_of(compressor, ev, self);
}
if (self.optional && is_nullish(self.expression)) {
if (self.optional && is_nullish(self.expression, compressor)) {
return make_node(AST_Undefined, self);
}
return self;
Expand Down Expand Up @@ -7425,7 +7425,7 @@ def_optimize(AST_Dot, function(self, compressor) {
ev = make_node_from_constant(ev, self).optimize(compressor);
return best_of(compressor, ev, self);
}
if (self.optional && is_nullish(self.expression)) {
if (self.optional && is_nullish(self.expression, compressor)) {
return make_node(AST_Undefined, self);
}
return self;
Expand Down Expand Up @@ -7590,7 +7590,7 @@ def_optimize(AST_TemplateString, function(self, compressor) {
&& (
segments[1].is_string(compressor)
|| segments[1].is_number(compressor)
|| is_nullish(segments[1])
|| is_nullish(segments[1], compressor)
|| compressor.option("unsafe")
)
) {
Expand Down

0 comments on commit 2835581

Please sign in to comment.