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.13.1 to 5.14.0

7

CHANGELOG.md
# Changelog
## v5.14.0
- Switched to @jridgewell/source-map for sourcemap generation (#1190, #1181)
- Fixed source maps with non-terminated segments (#1106)
- Enabled typescript types to be imported from the package (#1194)
- Extra DOM props have been added (#1191)
- Delete the AST while generating code, as a means to save RAM
## v5.13.1

@@ -4,0 +11,0 @@ - Removed self-assignments (`varname=varname`) (closes #1081)

61

lib/minify.js

@@ -10,3 +10,3 @@ "use strict";

} from "./utils/index.js";
import { AST_Toplevel, AST_Node } from "./ast.js";
import { AST_Toplevel, AST_Node, walk, AST_Scope } from "./ast.js";
import { parse } from "./parse.js";

@@ -198,2 +198,4 @@ import { OutputStream } from "./output.js";

}
// -- Parse phase --
if (timings) timings.parse = Date.now();

@@ -248,2 +250,4 @@ var toplevel;

}
// -- Compress phase --
if (timings) timings.compress = Date.now();

@@ -255,2 +259,4 @@ if (options.compress) {

}
// -- Mangle phase --
if (timings) timings.scope = Date.now();

@@ -268,2 +274,4 @@ if (options.mangle) toplevel.figure_out_scope(options.mangle);

}
// Format phase
if (timings) timings.format = Date.now();

@@ -278,15 +286,30 @@ var result = {};

if (!HOP(options.format, "code") || options.format.code) {
if (!options.format.ast) {
// Destroy stuff to save RAM. (unless the deprecated `ast` option is on)
options.format._destroy_ast = true;
walk(toplevel, node => {
if (node instanceof AST_Scope) {
node.variables = undefined;
node.enclosed = undefined;
node.parent_scope = undefined;
}
if (node.block_scope) {
node.block_scope.variables = undefined;
node.block_scope.enclosed = undefined;
node.parent_scope = undefined;
}
});
}
if (options.sourceMap) {
if (options.sourceMap.includeSources && files instanceof AST_Toplevel) {
throw new Error("original source content unavailable");
}
options.format.source_map = await SourceMap({
file: options.sourceMap.filename,
orig: options.sourceMap.content,
root: options.sourceMap.root
root: options.sourceMap.root,
files: options.sourceMap.includeSources ? files : null,
});
if (options.sourceMap.includeSources) {
if (files instanceof AST_Toplevel) {
throw new Error("original source content unavailable");
} else for (var name in files) if (HOP(files, name)) {
options.format.source_map.get().setSourceContent(name, files[name]);
}
}
}

@@ -300,7 +323,17 @@ delete options.format.ast;

if (options.sourceMap) {
if(options.sourceMap.asObject) {
result.map = options.format.source_map.get().toJSON();
} else {
result.map = options.format.source_map.toString();
}
Object.defineProperty(result, "map", {
configurable: true,
enumerable: true,
get() {
const map = options.format.source_map.getEncoded();
return (result.map = options.sourceMap.asObject ? map : JSON.stringify(map));
},
set(value) {
Object.defineProperty(result, "map", {
value,
writable: true,
});
}
});
result.decoded_map = options.format.source_map.getDecoded();
if (options.sourceMap.url == "inline") {

@@ -307,0 +340,0 @@ var sourceMap = typeof result.map === "object" ? JSON.stringify(result.map) : result.map;

@@ -46,8 +46,6 @@ /***********************************************************************

import MOZ_SourceMap from "source-map";
import {
defaults,
} from "./utils/index.js";
import {SourceMapConsumer, SourceMapGenerator} from "@jridgewell/source-map";
import {defaults, HOP} from "./utils/index.js";
// a small wrapper around fitzgen's source-map library
// a small wrapper around source-map and @jridgewell/source-map
async function SourceMap(options) {

@@ -58,9 +56,7 @@ options = defaults(options, {

orig : null,
orig_line_diff : 0,
dest_line_diff : 0,
files: {},
});
var orig_map;
var generator = new MOZ_SourceMap.SourceMapGenerator({
var generator = new SourceMapGenerator({
file : options.file,

@@ -70,13 +66,25 @@ sourceRoot : options.root

let sourcesContent = {__proto__: null};
let files = options.files;
for (var name in files) if (HOP(files, name)) {
sourcesContent[name] = files[name];
}
if (options.orig) {
orig_map = await new MOZ_SourceMap.SourceMapConsumer(options.orig);
orig_map.sources.forEach(function(source) {
var sourceContent = orig_map.sourceContentFor(source, true);
if (sourceContent) {
generator.setSourceContent(source, sourceContent);
}
});
// We support both @jridgewell/source-map (which has a sync
// SourceMapConsumer) and source-map (which has an async
// SourceMapConsumer).
orig_map = await new SourceMapConsumer(options.orig);
if (orig_map.sourcesContent) {
orig_map.sources.forEach(function(source, i) {
var content = orig_map.sourcesContent[i];
if (content) {
sourcesContent[source] = content;
}
});
}
}
function add(source, gen_line, gen_col, orig_line, orig_col, name) {
let generatedPos = { line: gen_line, column: gen_col };
if (orig_map) {

@@ -88,2 +96,8 @@ var info = orig_map.originalPositionFor({

if (info.source === null) {
generator.addMapping({
generated: generatedPos,
original: null,
source: null,
name: null
});
return;

@@ -97,18 +111,38 @@ }

generator.addMapping({
generated : { line: gen_line + options.dest_line_diff, column: gen_col },
original : { line: orig_line + options.orig_line_diff, column: orig_col },
generated : generatedPos,
original : { line: orig_line, column: orig_col },
source : source,
name : name
});
generator.setSourceContent(source, sourcesContent[source]);
}
function clean(map) {
const allNull = map.sourcesContent && map.sourcesContent.every(c => c == null);
if (allNull) delete map.sourcesContent;
if (map.file === undefined) delete map.file;
if (map.sourceRoot === undefined) delete map.sourceRoot;
return map;
}
function getDecoded() {
if (!generator.toDecodedMap) return null;
return clean(generator.toDecodedMap());
}
function getEncoded() {
return clean(generator.toJSON());
}
function destroy() {
// @jridgewell/source-map's SourceMapConsumer does not need to be
// manually freed.
if (orig_map && orig_map.destroy) orig_map.destroy();
}
return {
add : add,
get : function() { return generator; },
toString : function() { return generator.toString(); },
destroy : function () {
if (orig_map && orig_map.destroy) {
orig_map.destroy();
}
}
add,
getDecoded,
getEncoded,
destroy,
};

@@ -115,0 +149,0 @@ }

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

"license": "BSD-2-Clause",
"version": "5.13.1",
"version": "5.14.0",
"engines": {

@@ -22,2 +22,3 @@ "node": ">=10"

{
"types": "./tools/terser.d.ts",
"import": "./main.js",

@@ -48,5 +49,5 @@ "require": "./dist/bundle.min.js"

"dependencies": {
"@jridgewell/source-map": "^0.3.2",
"acorn": "^8.5.0",
"commander": "^2.20.0",
"source-map": "~0.8.0-beta.0",
"source-map-support": "~0.5.20"

@@ -64,3 +65,4 @@ },

"rollup": "2.56.3",
"semver": "^7.3.4"
"semver": "^7.3.4",
"source-map": "~0.8.0-beta.0"
},

@@ -67,0 +69,0 @@ "scripts": {

/// <reference lib="es2015" />
import { RawSourceMap } from 'source-map';
import { SectionedSourceMapInput, EncodedSourceMap, DecodedSourceMap } from '@jridgewell/source-map';

@@ -9,2 +9,3 @@ export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020;

bare_returns?: boolean;
/** @deprecated legacy option. Currently, all supported EcmaScript is valid to parse. */
ecma?: ECMA;

@@ -196,3 +197,4 @@ html5_comments?: boolean;

code?: string;
map?: RawSourceMap | string;
map?: EncodedSourceMap | string;
decoded_map?: DecodedSourceMap | null;
}

@@ -202,3 +204,3 @@

/** Source map object, 'inline' or source map file content */
content?: RawSourceMap | string;
content?: SectionedSourceMapInput | string;
includeSources?: boolean;

@@ -205,0 +207,0 @@ filename?: string;

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