Socket
Socket
Sign inDemoInstall

terser

Package Overview
Dependencies
4
Maintainers
1
Versions
171
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.16.9 to 5.17.0

5

CHANGELOG.md
# Changelog
## v5.17.0
- Drop vestigial `= undefined` default argument in IIFE calls (#1366)
- Evaluate known arrays' `.length` property when statically determinable
- Add `@__KEY__` annotation to mangle string literals (#1365)
## v5.16.9

@@ -4,0 +9,0 @@ - Fix parentheses in output of optional chains (`a?.b`) (#1374)

29

lib/compress/evaluate.js

@@ -355,2 +355,29 @@ /***********************************************************************

if (obj === nullish || (this.optional && obj == null)) return nullish;
// `.length` of strings and arrays is always safe
if (this.property === "length") {
if (typeof obj === "string") {
return obj.length;
}
const is_spreadless_array = obj =>
obj instanceof AST_Array
&& obj.elements.every(el => !(el instanceof AST_Expansion));
if (
is_spreadless_array(obj)
&& obj.elements.every(el => !el.has_side_effects(compressor))
) {
return obj.elements.length;
}
let fixed;
if (
obj instanceof AST_SymbolRef
&& is_spreadless_array((fixed = obj.definition().fixed_value()))
) {
return fixed.elements.length;
}
}
if (compressor.option("unsafe")) {

@@ -363,5 +390,5 @@ var key = this.property;

}
var exp = this.expression;
if (is_undeclared_ref(exp)) {
var aa;

@@ -368,0 +395,0 @@ var first_arg = exp.name === "hasOwnProperty"

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

push_uniq,
has_annotation,
clear_annotation,
} from "./utils/index.js";

@@ -71,2 +73,3 @@ import { base54 } from "./scope.js";

TreeWalker,
_KEY,
} from "./ast.js";

@@ -268,2 +271,4 @@ import { domprops } from "../tools/domprops.js";

addStrings(node.left, add);
} else if (node instanceof AST_String && has_annotation(node, _KEY)) {
add(node.value);
}

@@ -302,2 +307,6 @@ }));

node.left = mangleStrings(node.left);
} else if (node instanceof AST_String && has_annotation(node, _KEY)) {
// Clear _KEY annotation to prevent double mangling
clear_annotation(node, _KEY);
node.value = mangle(node.value);
}

@@ -368,2 +377,4 @@ }));

} else if (node instanceof AST_String) {
// Clear _KEY annotation to prevent double mangling
clear_annotation(node, _KEY);
node.value = mangle(node.value);

@@ -370,0 +381,0 @@ } else if (node instanceof AST_Conditional) {

@@ -265,2 +265,6 @@ /***********************************************************************

function clear_annotation(node, annotation) {
node._annotations &= ~annotation;
}
export {

@@ -290,3 +294,4 @@ characters,

has_annotation,
set_annotation
set_annotation,
clear_annotation,
};

2

package.json

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

"license": "BSD-2-Clause",
"version": "5.16.9",
"version": "5.17.0",
"engines": {

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

@@ -1191,2 +1191,3 @@ <h1><img src="https://terser.org/img/terser-banner-logo.png" alt="Terser" width="400"></h1>

* `/*@__PURE__*/` - Marks a function call as pure. That means, it can safely be dropped.
* `/*@__KEY__*/` - Marks a string literal as a property to also mangle it when mangling properties.

@@ -1205,2 +1206,5 @@ You can use either a `@` sign at the start, or a `#`.

const x = /*#__PURE__*/i_am_dropped_if_x_is_not_used()
function lookup(object, key) { return object[key]; }
lookup({ i_will_be_mangled_too: "bar" }, /*@__KEY__*/ "i_will_be_mangled_too");
```

@@ -1207,0 +1211,0 @@

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

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

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc