Socket
Socket
Sign inDemoInstall

terser

Package Overview
Dependencies
Maintainers
1
Versions
180
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

terser - npm Package Compare versions

Comparing version 5.17.1 to 5.17.2

5

CHANGELOG.md
# Changelog
## v5.17.2
- Be less conservative when detecting use-before-definition of `var` in hoisted functions.
- Support unusual (but perfectly valid) initializers of for-in and for-of loops.
- Fix issue where hoisted function would be dropped if it was after a `continue` statement
## v5.17.1

@@ -4,0 +9,0 @@ - Fix evaluating `.length` when the source array might've been mutated

2

lib/compress/inference.js

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

AST_False,
AST_ForIn,
AST_Function,

@@ -716,2 +717,3 @@ AST_If,

if (parent instanceof AST_Assign && parent.left === node) return node;
if (parent instanceof AST_ForIn && parent.init === node) return node;
}

@@ -718,0 +720,0 @@

37

lib/compress/reduce-vars.js

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

AST_SymbolConst,
AST_SymbolDeclaration,
AST_SymbolDefun,

@@ -96,2 +97,3 @@ AST_SymbolFunarg,

walk,
walk_parent,
walk_abort,

@@ -106,3 +108,3 @@ walk_body,

import { lazy_op, is_modified } from "./inference.js";
import { lazy_op, is_modified, is_lhs } from "./inference.js";
import { INLINED, clear_flag } from "./compressor-flags.js";

@@ -546,17 +548,28 @@ import { read_property, has_break_or_continue, is_recursive_ref } from "./common.js";

// Detect `call_defun(); var used_in_defun = ...`
// Because `used_in_defun` can no longer be fixed
let found_defun = false;
// Detect `call_defun(); var used_in_defun = X`
// Because `used_in_defun` is not certainly X when it's defined after.
let found_defun_ref = false;
let found_def_after_defun = false;
walk(parent, node => {
walk_parent(parent, (node, info) => {
if (node === defun) return true;
if (node instanceof AST_Symbol) {
if (!found_defun && node.thedef === fname_def) {
found_defun = true;
} else if (found_defun && node.thedef === def) {
found_def_after_defun = true;
return walk_abort;
}
// Step 1: find `call_defun()` or other refs to the defun
if (
!found_defun_ref
&& node.thedef === fname_def
&& node instanceof AST_Symbol
) {
found_defun_ref = true;
}
// Step 2: if Step 1 occurred, find a var the defun uses
if (
found_defun_ref
&& node.thedef === def
&& (node instanceof AST_SymbolDeclaration
|| is_lhs(node, info))
) {
found_def_after_defun = true;
return walk_abort;
}
});

@@ -563,0 +576,0 @@

@@ -1005,4 +1005,9 @@ /***********************************************************************

if (stat instanceof AST_If) {
var ab = aborts(stat.body);
if (can_merge_flow(ab)) {
let ab, new_else;
ab = aborts(stat.body);
if (
can_merge_flow(ab)
&& (new_else = as_statement_array_with_return(stat.body, ab))
) {
if (ab.label) {

@@ -1014,3 +1019,2 @@ remove(ab.label.thedef.references, ab);

stat.condition = stat.condition.negate(compressor);
var body = as_statement_array_with_return(stat.body, ab);
stat.body = make_node(AST_BlockStatement, stat, {

@@ -1020,3 +1024,3 @@ body: as_statement_array(stat.alternative).concat(extract_functions())

stat.alternative = make_node(AST_BlockStatement, stat, {
body: body
body: new_else
});

@@ -1027,4 +1031,7 @@ statements[i] = stat.transform(compressor);

var ab = aborts(stat.alternative);
if (can_merge_flow(ab)) {
ab = aborts(stat.alternative);
if (
can_merge_flow(ab)
&& (new_else = as_statement_array_with_return(stat.alternative, ab))
) {
if (ab.label) {

@@ -1038,5 +1045,4 @@ remove(ab.label.thedef.references, ab);

});
var body = as_statement_array_with_return(stat.alternative, ab);
stat.alternative = make_node(AST_BlockStatement, stat.alternative, {
body: body
body: new_else
});

@@ -1156,3 +1162,7 @@ statements[i] = stat.transform(compressor);

function as_statement_array_with_return(node, ab) {
var body = as_statement_array(node).slice(0, -1);
var body = as_statement_array(node);
if (ab !== body[body.length - 1]) {
return undefined;
}
body = body.slice(0, -1);
if (ab.value) {

@@ -1159,0 +1169,0 @@ body.push(make_node(AST_SimpleStatement, ab.value, {

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

"license": "BSD-2-Clause",
"version": "5.17.1",
"version": "5.17.2",
"engines": {

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

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc