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

uglify-es

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uglify-es - npm Package Compare versions

Comparing version 3.0.10 to 3.0.11

69

lib/output.js

@@ -215,3 +215,27 @@ /***********************************************************************

var last = "";
var mapping_token, mapping_name, mappings = options.source_map && [];
var do_add_mapping = mappings ? function() {
mappings.forEach(function(mapping) {
try {
options.source_map.add(
mapping.token.file,
mapping.line, mapping.col,
mapping.token.line, mapping.token.col,
!mapping.name && mapping.token.type == "name" ? mapping.token.value : mapping.name
);
} catch(ex) {
AST_Node.warn("Couldn't figure out mapping for {file}:{line},{col} → {cline},{ccol} [{name}]", {
file: mapping.token.file,
line: mapping.token.line,
col: mapping.token.col,
cline: mapping.line,
ccol: mapping.col,
name: mapping.name || ""
})
}
});
mappings = [];
} : noop;
var ensure_line_len = options.max_line_len ? function() {

@@ -222,2 +246,9 @@ if (current_col > options.max_line_len) {

var right = OUTPUT.slice(might_add_newline);
if (mappings) {
var delta = right.length - current_col;
mappings.forEach(function(mapping) {
mapping.line++;
mapping.col += delta;
});
}
OUTPUT = left + "\n" + right;

@@ -232,3 +263,6 @@ current_line++;

}
might_add_newline = 0;
if (might_add_newline) {
might_add_newline = 0;
do_add_mapping();
}
} : noop;

@@ -293,2 +327,14 @@

}
if (mapping_token) {
mappings.push({
token: mapping_token,
name: mapping_name,
line: current_line,
col: current_col
});
mapping_token = false;
if (!might_add_newline) do_add_mapping();
}
OUTPUT += str;

@@ -392,20 +438,5 @@ current_pos += str.length;

var add_mapping = options.source_map ? function(token, name) {
try {
if (token) options.source_map.add(
token.file || "?",
current_line, current_col,
token.line, token.col,
(!name && token.type == "name") ? token.value : name
);
} catch(ex) {
AST_Node.warn("Couldn't figure out mapping for {file}:{line},{col} → {cline},{ccol} [{name}]", {
file: token.file,
line: token.line,
col: token.col,
cline: current_line,
ccol: current_col,
name: name || ""
})
}
var add_mapping = mappings ? function(token, name) {
mapping_token = token;
mapping_name = name;
} : noop;

@@ -412,0 +443,0 @@

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

to_mangle.forEach(function(def){
if (def.destructuring && !def.destructuring.is_array) return;
def.mangle(options);

@@ -575,0 +574,0 @@ });

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

"license": "BSD-2-Clause",
"version": "3.0.10",
"version": "3.0.11",
"engines": {

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

@@ -127,3 +127,3 @@ uglify-es

--stats Display operations run time on STDERR.
--toplevel Compress and/or mangle variables in toplevel scope.
--toplevel Compress and/or mangle variables in top level scope.
--verbose Print diagnostic messages.

@@ -203,3 +203,3 @@ --warn Print warning messages.

- `toplevel` — mangle names declared in the toplevel scope (disabled by
- `toplevel` — mangle names declared in the top level scope (disabled by
default).

@@ -303,5 +303,6 @@

There is a single high level minification function, `minify(code, options)`, which will
performs all the steps in a configurable manner.
Example:
There is a single high level function, **`minify(code, options)`**,
which will perform all minification [phases](#minify-options) in a configurable
manner. By default `minify()` will enable the options [`compress`](#compress-options)
and [`mangle`](#mangle-options). Example:
```javascript

@@ -314,3 +315,5 @@ var code = "function add(first, second) { return first + second; }";

You can also compress multiple files:
You can `minify` more than one JavaScript file at a time by using an object
for the first argument where the keys are file names and the values are source
code:
```javascript

@@ -322,3 +325,4 @@ var code = {

var result = UglifyJS.minify(code);
console.log(result.code); // function add(d,n){return d+n}console.log(add(3,7));
console.log(result.code);
// function add(d,n){return d+n}console.log(add(3,7));
```

@@ -334,5 +338,31 @@

var result = UglifyJS.minify(code, options);
console.log(result.code); // console.log(function(n,o){return n+o}(3,7));
console.log(result.code);
// console.log(function(n,o){return n+o}(3,7));
```
An example of a combination of `minify()` options:
```javascript
var code = {
"file1.js": "function add(first, second) { return first + second; }",
"file2.js": "console.log(add(1 + 2, 3 + 4));"
};
var options = {
toplevel: true,
compress: {
global_defs: {
"@console.log": "alert"
},
passes: 2
},
output: {
beautify: false,
preamble: "/* uglified */"
}
};
var result = UglifyJS.minify(code, options);
console.log(result.code);
// /* uglified */
// alert(10);"
```
To produce warnings:

@@ -354,3 +384,3 @@ ```javascript

```
Note: unlike `uglify-js@2.x`, the `3.x` API does not throw errors. To
Note: unlike `uglify-js@2.x`, the `3.x` API does not throw errors. To
achieve a similar effect one could do the following:

@@ -364,3 +394,3 @@ ```javascript

- `warnings` (default `false`) — pass `true` to return compressor warnings
- `warnings` (default `false`) — pass `true` to return compressor warnings
in `result.warnings`. Use the value `"verbose"` for more detailed warnings.

@@ -529,3 +559,3 @@

- `toplevel` -- drop unreferenced functions (`"funcs"`) and/or variables (`"vars"`)
in the toplevel scope (`false` by default, `true` to drop both unreferenced
in the top level scope (`false` by default, `true` to drop both unreferenced
functions and variables)

@@ -548,3 +578,3 @@

- `collapse_vars` -- Collapse single-use non-constant variables - side
- `collapse_vars` -- Collapse single-use non-constant variables - side
effects permitting.

@@ -611,3 +641,3 @@

- `toplevel` — mangle names declared in the toplevel scope (disabled by
- `toplevel` — mangle names declared in the top level scope (disabled by
default).

@@ -797,3 +827,3 @@

```javascript
var result = uglifyJS.minify(fs.readFileSync("input.js", "utf8"), {
var result = UglifyJS.minify(fs.readFileSync("input.js", "utf8"), {
compress: {

@@ -808,2 +838,28 @@ dead_code: true,

To replace an identifier with an arbitrary non-constant expression it is
necessary to prefix the `global_defs` key with `"@"` to instruct UglifyJS
to parse the value as an expression:
```javascript
UglifyJS.minify("alert('hello');", {
compress: {
global_defs: {
"@alert": "console.log"
}
}
}).code;
// returns: 'console.log("hello");'
```
Otherwise it would be replaced as string literal:
```javascript
UglifyJS.minify("alert('hello');", {
compress: {
global_defs: {
"alert": "console.log"
}
}
}).code;
// returns: '"console.log"("hello");'
```
### Using native Uglify AST with `minify()`

@@ -810,0 +866,0 @@ ```javascript

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