Socket
Socket
Sign inDemoInstall

terser

Package Overview
Dependencies
11
Maintainers
1
Versions
170
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.17.4 to 5.17.5

3

CHANGELOG.md
# Changelog
## v5.17.5
- Take into account the non-deferred bits of a class, such as static properties, while dropping unused code.
## v5.17.4

@@ -4,0 +7,0 @@

59

lib/compress/drop-side-effect-free.js

@@ -58,2 +58,3 @@ /***********************************************************************

AST_Constant,
AST_DefClass,
AST_Dot,

@@ -72,2 +73,3 @@ AST_Expansion,

AST_Sequence,
AST_SimpleStatement,
AST_Sub,

@@ -161,29 +163,41 @@ AST_SymbolRef,

with_effects.push(trimmed_extends);
for (const prop of this.properties) {
if (prop instanceof AST_ClassStaticBlock) {
if (prop.body.some(stat => stat.has_side_effects(compressor))) {
return this;
} else {
continue;
if (prop.has_side_effects(compressor)) {
return this; // Be cautious about these
}
}
} else {
const trimmed_prop = prop.drop_side_effect_free(compressor);
if (trimmed_prop) {
if (trimmed_prop.contains_this()) return this;
if (
prop instanceof AST_ClassProperty
&& prop.static
&& prop.value.has_side_effects(compressor)
&& prop.contains_this()
) {
return this;
with_effects.push(trimmed_prop);
}
}
}
const trimmed_prop = prop.drop_side_effect_free(compressor);
if (trimmed_prop)
with_effects.push(trimmed_prop);
}
if (!with_effects.length)
return null;
return make_sequence(this, with_effects);
const exprs = make_sequence(this, with_effects);
if (this instanceof AST_DefClass) {
// We want a statement
return make_node(AST_SimpleStatement, this, { body: exprs });
} else {
return exprs;
}
});
def_drop_side_effect_free(AST_ClassProperty, function (compressor) {
const key = this.computed_key() && this.key.drop_side_effect_free(compressor);
const value = this.static && this.value
&& this.value.drop_side_effect_free(compressor);
if (key && value)
return make_sequence(this, [key, value]);
return key || value || null;
});
def_drop_side_effect_free(AST_Binary, function (compressor, first_in_statement) {

@@ -292,13 +306,2 @@ var right = this.right.drop_side_effect_free(compressor);

def_drop_side_effect_free(AST_ClassProperty, function (compressor) {
const key = this.computed_key() && this.key.drop_side_effect_free(compressor);
const value = this.static && this.value
&& this.value.drop_side_effect_free(compressor);
if (key && value)
return make_sequence(this, [key, value]);
return key || value || null;
});
def_drop_side_effect_free(AST_ConciseMethod, function () {

@@ -305,0 +308,0 @@ return this.computed_key() ? this.key : null;

@@ -50,2 +50,3 @@ /***********************************************************************

AST_ClassExpression,
AST_ClassStaticBlock,
AST_DefaultAssign,

@@ -156,2 +157,7 @@ AST_DefClass,

if (node === self) return;
if (node instanceof AST_Class) {
if (node.has_side_effects(compressor)) {
node.visit_nondeferred_class_parts(tw);
}
}
if (node instanceof AST_Defun || node instanceof AST_DefClass) {

@@ -165,19 +171,3 @@ var node_def = node.name.definition();

}
if (node instanceof AST_DefClass) {
if (
node.extends
&& (node.extends.has_side_effects(compressor)
|| node.extends.may_throw(compressor))
) {
node.extends.walk(tw);
}
for (const prop of node.properties) {
if (
prop.has_side_effects(compressor) ||
prop.may_throw(compressor)
) {
prop.walk(tw);
}
}
}
map_add(initializations, node_def.id, node);

@@ -247,5 +237,5 @@ return true; // don't go in nested scopes

}
} else if (!in_use) return in_list ? MAP.skip : make_node(AST_Number, node, {
value: 0
});
} else if (!in_use) {
return in_list ? MAP.skip : make_node(AST_Number, node, { value: 0 });
}
}

@@ -293,7 +283,14 @@ }

const keep = def.global && !drop_funcs || in_use_ids.has(def.id);
// Class "extends" and static blocks may have side effects
const has_side_effects = !keep
&& node instanceof AST_Class
&& node.has_side_effects(compressor);
if (!keep && !has_side_effects) {
if (!keep) {
// Class "extends" and static blocks may have side effects
if (node instanceof AST_Class) {
const kept = node.drop_side_effect_free(compressor);
if (kept !== node) {
def.eliminated++;
if (kept) return kept;
return in_list ? MAP.skip : make_node(AST_EmptyStatement, node);
} else {
return kept;
}
}
def.eliminated++;

@@ -394,5 +391,3 @@ return in_list ? MAP.skip : make_node(AST_EmptyStatement, node);

default:
return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, {
body: body
});
return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, { body });
}

@@ -440,3 +435,3 @@ }

}
if (node instanceof AST_Scope) {
if (node instanceof AST_Scope && !(node instanceof AST_ClassStaticBlock)) {
const save_scope = scope;

@@ -480,3 +475,7 @@ scope = node;

}
if (node instanceof AST_Scope) {
if (node instanceof AST_Class) {
descend();
return true;
}
if (node instanceof AST_Scope && !(node instanceof AST_ClassStaticBlock)) {
var save_scope = scope;

@@ -483,0 +482,0 @@ scope = node;

@@ -7,3 +7,3 @@ {

"license": "BSD-2-Clause",
"version": "5.17.4",
"version": "5.17.5",
"engines": {

@@ -10,0 +10,0 @@ "node": ">=10"

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc