Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

terser

Package Overview
Dependencies
Maintainers
1
Versions
182
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.16.1 to 5.16.2

10

CHANGELOG.md
# Changelog
## v5.16.2
- Fix sourcemaps with non-ascii characters (#1318)
- Support string module name and export * as (#1336)
- Do not move `let` out of `for` initializers, as it can change scoping
- Fix a corner case that would generate the invalid syntax `if (something) let x` ("let" in braceless if body)
- Knowledge of more native object properties (#1330)
- Got rid of Travis (#1323)
- Added semi-secret `asObject` sourcemap option to typescript defs (#1321)
## v5.16.1

@@ -4,0 +14,0 @@

5

lib/compress/common.js

@@ -244,5 +244,6 @@ /***********************************************************************

/**
* Used to determine whether the node can benefit from negation.
* Not the case with arrow functions (you need an extra set of parens). */
export function is_iife_call(node) {
// Used to determine whether the node can benefit from negation.
// Not the case with arrow functions (you need an extra set of parens).
if (node.TYPE != "Call") return false;

@@ -249,0 +250,0 @@ return node.expression instanceof AST_Function || is_iife_call(node.expression);

@@ -82,2 +82,5 @@ /***********************************************************************

Array: [
"at",
"flat",
"includes",
"indexOf",

@@ -103,18 +106,37 @@ "join",

String: [
"at",
"charAt",
"charCodeAt",
"charPointAt",
"concat",
"endsWith",
"fromCharCode",
"fromCodePoint",
"includes",
"indexOf",
"italics",
"lastIndexOf",
"localeCompare",
"match",
"matchAll",
"normalize",
"padStart",
"padEnd",
"repeat",
"replace",
"replaceAll",
"search",
"slice",
"split",
"startsWith",
"substr",
"substring",
"repeat",
"toLocaleLowerCase",
"toLocaleUpperCase",
"toLowerCase",
"toUpperCase",
"trim",
"trimEnd",
"trimStart",
...object_methods,

@@ -121,0 +143,0 @@ ],

11

lib/compress/tighten-body.js

@@ -1407,3 +1407,6 @@ /***********************************************************************

statements[++j] = stat;
} else if (prev instanceof AST_Var && (!stat.init || stat.init.TYPE == prev.TYPE)) {
} else if (
prev instanceof AST_Var
&& (!stat.init || stat.init.TYPE == prev.TYPE)
) {
if (stat.init) {

@@ -1415,3 +1418,7 @@ prev.definitions = prev.definitions.concat(stat.init.definitions);

CHANGED = true;
} else if (defs && stat.init && defs.TYPE == stat.init.TYPE && declarations_only(stat.init)) {
} else if (
defs instanceof AST_Var
&& stat.init instanceof AST_Var
&& declarations_only(stat.init)
) {
defs.definitions = defs.definitions.concat(stat.init.definitions);

@@ -1418,0 +1425,0 @@ stat.init = null;

@@ -22,8 +22,11 @@ "use strict";

var to_ascii = typeof atob == "undefined" ? function(b64) {
return Buffer.from(b64, "base64").toString();
} : atob;
var to_base64 = typeof btoa == "undefined" ? function(str) {
return Buffer.from(str).toString("base64");
} : btoa;
// to/from base64 functions
// Prefer built-in Buffer, if available, then use hack
// https://developer.mozilla.org/en-US/docs/Glossary/Base64#The_Unicode_Problem
var to_ascii = typeof Buffer !== "undefined"
? (b64) => Buffer.from(b64, "base64").toString()
: (b64) => decodeURIComponent(escape(atob(b64)));
var to_base64 = typeof Buffer !== "undefined"
? (str) => Buffer.from(str).toString("base64")
: (str) => btoa(unescape(encodeURIComponent(str)));

@@ -30,0 +33,0 @@ function read_source_map(code) {

@@ -532,20 +532,7 @@ /***********************************************************************

M.specifiers.forEach(function (specifier) {
if (specifier.type === "ImportSpecifier") {
if (specifier.type === "ImportSpecifier" || specifier.type === "ImportNamespaceSpecifier") {
if (!imported_names) { imported_names = []; }
imported_names.push(new AST_NameMapping({
start: my_start_token(specifier),
end: my_end_token(specifier),
foreign_name: from_moz(specifier.imported),
name: from_moz(specifier.local)
}));
imported_names.push(from_moz(specifier));
} else if (specifier.type === "ImportDefaultSpecifier") {
imported_name = from_moz(specifier.local);
} else if (specifier.type === "ImportNamespaceSpecifier") {
if (!imported_names) { imported_names = []; }
imported_names.push(new AST_NameMapping({
start: my_start_token(specifier),
end: my_end_token(specifier),
foreign_name: new AST_SymbolImportForeign({ name: "*" }),
name: from_moz(specifier.local)
}));
imported_name = from_moz(specifier);
}

@@ -563,3 +550,28 @@ });

ImportSpecifier: function(M) {
return new AST_NameMapping({
start: my_start_token(M),
end: my_end_token(M),
foreign_name: from_moz(M.imported),
name: from_moz(M.local)
});
},
ImportDefaultSpecifier: function(M) {
return from_moz(M.local);
},
ImportNamespaceSpecifier: function(M) {
return new AST_NameMapping({
start: my_start_token(M),
end: my_end_token(M),
foreign_name: new AST_SymbolImportForeign({ name: "*" }),
name: from_moz(M.local)
});
},
ExportAllDeclaration: function(M) {
var foreign_name = M.exported == null ?
new AST_SymbolExportForeign({ name: "*" }) :
from_moz(M.exported);
return new AST_Export({

@@ -571,3 +583,3 @@ start: my_start_token(M),

name: new AST_SymbolExportForeign({ name: "*" }),
foreign_name: new AST_SymbolExportForeign({ name: "*" })
foreign_name: foreign_name
})

@@ -586,6 +598,3 @@ ],

exported_names: M.specifiers && M.specifiers.length ? M.specifiers.map(function (specifier) {
return new AST_NameMapping({
foreign_name: from_moz(specifier.exported),
name: from_moz(specifier.local)
});
return from_moz(specifier);
}) : null,

@@ -606,2 +615,9 @@ module_name: from_moz(M.source),

ExportSpecifier: function(M) {
return new AST_NameMapping({
foreign_name: from_moz(M.exported),
name: from_moz(M.local)
});
},
Literal: function(M) {

@@ -632,2 +648,18 @@ var val = M.value, args = {

case "string":
args.quote = "\"";
var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
if (p.type == "ImportSpecifier") {
args.name = val;
return new AST_SymbolImportForeign(args);
} else if (p.type == "ExportSpecifier") {
args.name = val;
if (M == p.exported) {
return new AST_SymbolExportForeign(args);
} else {
return new AST_SymbolExport(args);
}
} else if (p.type == "ExportAllDeclaration" && M == p.exported) {
args.name = val;
return new AST_SymbolExportForeign(args);
}
args.value = val;

@@ -1337,6 +1369,13 @@ return new AST_String(args);

if (M.exported_names) {
if (M.exported_names[0].name.name === "*") {
var first_exported = M.exported_names[0];
var first_exported_name = first_exported.name;
if (first_exported_name.name === "*" && !first_exported_name.quote) {
var foreign_name = first_exported.foreign_name;
var exported = foreign_name.name === "*" && !foreign_name.quote
? null
: to_moz(foreign_name);
return {
type: "ExportAllDeclaration",
source: to_moz(M.module_name),
exported: exported,
assertions: assert_clause_to_moz(M.assert_clause)

@@ -1373,15 +1412,18 @@ };

}
if (M.imported_names && M.imported_names[0].foreign_name.name === "*") {
specifiers.push({
type: "ImportNamespaceSpecifier",
local: to_moz(M.imported_names[0].name)
});
} else if (M.imported_names) {
M.imported_names.forEach(function(name_mapping) {
if (M.imported_names) {
var first_imported_foreign_name = M.imported_names[0].foreign_name;
if (first_imported_foreign_name.name === "*" && !first_imported_foreign_name.quote) {
specifiers.push({
type: "ImportSpecifier",
local: to_moz(name_mapping.name),
imported: to_moz(name_mapping.foreign_name)
type: "ImportNamespaceSpecifier",
local: to_moz(M.imported_names[0].name)
});
});
} else {
M.imported_names.forEach(function(name_mapping) {
specifiers.push({
type: "ImportSpecifier",
local: to_moz(name_mapping.name),
imported: to_moz(name_mapping.foreign_name)
});
});
}
}

@@ -1650,3 +1692,10 @@ return {

def_to_moz(AST_Symbol, function To_Moz_Identifier(M, parent) {
if (M instanceof AST_SymbolMethod && parent.quote) {
if (
(M instanceof AST_SymbolMethod && parent.quote) ||
((
M instanceof AST_SymbolImportForeign ||
M instanceof AST_SymbolExportForeign ||
M instanceof AST_SymbolExport
) && M.quote)
) {
return {

@@ -1653,0 +1702,0 @@ type: "Literal",

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

AST_ForIn,
AST_ForOf,
AST_Function,

@@ -234,4 +235,5 @@ AST_Import,

scope.uses_eval = save_scope.uses_eval;
if (options.safari10) {
if (node instanceof AST_For || node instanceof AST_ForIn) {
if (node instanceof AST_For || node instanceof AST_ForIn || node instanceof AST_ForOf) {
for_scopes.push(scope);

@@ -238,0 +240,0 @@ }

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

"license": "BSD-2-Clause",
"version": "5.16.1",
"version": "5.16.2",
"engines": {

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

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

[![NPM Downloads][downloads-image]][downloads-url]
[![Travis Build][travis-image]][travis-url]
[![CI pipeline][ci-image]][ci-url]
[![Opencollective financial contributors][opencollective-contributors]][opencollective-url]

@@ -25,4 +25,4 @@

[downloads-url]: https://npmjs.org/package/terser
[travis-image]: https://app.travis-ci.com/terser/terser.svg?branch=master
[travis-url]: https://app.travis-ci.com/github/terser/terser
[ci-image]: https://github.com/terser/terser/actions/workflows/ci.yml/badge.svg
[ci-url]: https://github.com/terser/terser/actions/workflows/ci.yml
[opencollective-contributors]: https://opencollective.com/terser/tiers/badge.svg

@@ -763,3 +763,3 @@ [opencollective-url]: https://opencollective.com/terser

- `join_vars` (default: `true`) -- join consecutive `var` statements
- `join_vars` (default: `true`) -- join consecutive `var`, `let` and `const` statements

@@ -766,0 +766,0 @@ - `keep_classnames` (default: `false`) -- Pass `true` to prevent the compressor from

@@ -207,2 +207,3 @@ /// <reference lib="es2015" />

root?: string;
asObject?: boolean;
url?: string | 'inline';

@@ -209,0 +210,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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc