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.20.0 to 5.21.0

lib/compress/global-defs.js

4

CHANGELOG.md
# Changelog
## v5.20.1
- Do not inline functions that would be retained in the toplevel (as this would cause code duplication).
- Fix precedence of arrow function and ternary operator when formatting output.
## v5.20.0

@@ -4,0 +8,0 @@ - Passing `minify()` zero files will now throw a clean exception (#1450)

2

lib/compress/common.js

@@ -347,3 +347,3 @@ /***********************************************************************

&& fn.name
&& compressor.top_retain(fn.name);
&& compressor.top_retain(fn.name.definition());
}

@@ -131,3 +131,3 @@ /***********************************************************************

self.variables.forEach(function(def) {
if (compressor.top_retain(def) && !in_use_ids.has(def.id)) {
if (compressor.top_retain(def)) {
in_use_ids.set(def.id, def);

@@ -147,5 +147,3 @@ }

var def = argname.definition();
if (!in_use_ids.has(def.id)) {
in_use_ids.set(def.id, def);
}
in_use_ids.set(def.id, def);
});

@@ -163,3 +161,3 @@ }

if (in_export || !drop_funcs && scope === self) {
if (node_def.global && !in_use_ids.has(node_def.id)) {
if (node_def.global) {
in_use_ids.set(node_def.id, node_def);

@@ -172,6 +170,8 @@ }

}
if (node instanceof AST_SymbolFunarg && scope === self) {
// In the root scope, we drop things. In inner scopes, we just check for uses.
const in_root_scope = scope === self;
if (node instanceof AST_SymbolFunarg && in_root_scope) {
map_add(var_defs_by_id, node.definition().id, node);
}
if (node instanceof AST_Definitions && scope === self) {
if (node instanceof AST_Definitions && in_root_scope) {
const in_export = tw.parent() instanceof AST_Export;

@@ -186,3 +186,3 @@ node.definitions.forEach(function(def) {

const def = node.definition();
if (def.global && !in_use_ids.has(def.id)) {
if (def.global) {
in_use_ids.set(def.id, def);

@@ -189,0 +189,0 @@ }

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

AST_This,
AST_Toplevel,
AST_True,

@@ -111,3 +110,2 @@ AST_Try,

TreeTransformer,
walk,

@@ -126,7 +124,5 @@ walk_abort,

member,
noop,
has_annotation,
HOP
} from "../utils/index.js";
import { make_node_from_constant, make_sequence, best_of_expression, read_property } from "./common.js";
import { make_sequence, best_of_expression, read_property } from "./common.js";

@@ -734,76 +730,2 @@ import { INLINED, UNDEFINED, has_flag } from "./compressor-flags.js";

(function(def_find_defs) {
function to_node(value, orig) {
if (value instanceof AST_Node) {
if (!(value instanceof AST_Constant)) {
// Value may be a function, an array including functions and even a complex assign / block expression,
// so it should never be shared in different places.
// Otherwise wrong information may be used in the compression phase
value = value.clone(true);
}
return make_node(value.CTOR, orig, value);
}
if (Array.isArray(value)) return make_node(AST_Array, orig, {
elements: value.map(function(value) {
return to_node(value, orig);
})
});
if (value && typeof value == "object") {
var props = [];
for (var key in value) if (HOP(value, key)) {
props.push(make_node(AST_ObjectKeyVal, orig, {
key: key,
value: to_node(value[key], orig)
}));
}
return make_node(AST_Object, orig, {
properties: props
});
}
return make_node_from_constant(value, orig);
}
AST_Toplevel.DEFMETHOD("resolve_defines", function(compressor) {
if (!compressor.option("global_defs")) return this;
this.figure_out_scope({ ie8: compressor.option("ie8") });
return this.transform(new TreeTransformer(function(node) {
var def = node._find_defs(compressor, "");
if (!def) return;
var level = 0, child = node, parent;
while (parent = this.parent(level++)) {
if (!(parent instanceof AST_PropAccess)) break;
if (parent.expression !== child) break;
child = parent;
}
if (is_lhs(child, parent)) {
return;
}
return def;
}));
});
def_find_defs(AST_Node, noop);
def_find_defs(AST_Chain, function(compressor, suffix) {
return this.expression._find_defs(compressor, suffix);
});
def_find_defs(AST_Dot, function(compressor, suffix) {
return this.expression._find_defs(compressor, "." + this.property + suffix);
});
def_find_defs(AST_SymbolDeclaration, function() {
if (!this.global()) return;
});
def_find_defs(AST_SymbolRef, function(compressor, suffix) {
if (!this.global()) return;
var defines = compressor.option("global_defs");
var name = this.name + suffix;
if (HOP(defines, name)) return to_node(defines[name], this);
});
def_find_defs(AST_ImportMeta, function(compressor, suffix) {
var defines = compressor.option("global_defs");
var name = "import.meta" + suffix;
if (HOP(defines, name)) return to_node(defines[name], this);
});
})(function(node, func) {
node.DEFMETHOD("_find_defs", func);
});
// method to negate an expression

@@ -810,0 +732,0 @@ (function(def_negate) {

@@ -293,4 +293,5 @@ /***********************************************************************

export function inline_into_call(self, fn, compressor) {
export function inline_into_call(self, compressor) {
var exp = self.expression;
var fn = exp;
var simple_args = self.args.every((arg) => !(arg instanceof AST_Expansion));

@@ -303,5 +304,11 @@

const fixed = fn.fixed_value();
if (!retain_top_func(fixed, compressor)) {
fn = fixed;
if (
retain_top_func(fixed, compressor)
|| !compressor.toplevel.funcs && exp.definition().global
) {
return self;
}
fn = fixed;
}

@@ -308,0 +315,0 @@

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

"license": "BSD-2-Clause",
"version": "5.20.0",
"version": "5.21.0",
"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