Socket
Socket
Sign inDemoInstall

uglify-js

Package Overview
Dependencies
Maintainers
3
Versions
288
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uglify-js - npm Package Compare versions

Comparing version 2.2.5 to 2.3.0

LICENSE

21

lib/ast.js

@@ -288,2 +288,23 @@ /***********************************************************************

},
wrap_enclose: function(arg_parameter_pairs) {
var self = this;
var args = [];
var parameters = [];
arg_parameter_pairs.forEach(function(pair) {
var split = pair.split(":");
args.push(split[0]);
parameters.push(split[1]);
});
var wrapped_tl = "(function(" + parameters.join(",") + "){ '$ORIG'; })(" + args.join(",") + ")";
wrapped_tl = parse(wrapped_tl);
wrapped_tl = wrapped_tl.transform(new TreeTransformer(function before(node){
if (node instanceof AST_Directive && node.value == "$ORIG") {
return MAP.splice(self.body);
}
}));
return wrapped_tl;
},
wrap_commonjs: function(name, export_all) {

@@ -290,0 +311,0 @@ var self = this;

6

lib/mozilla-ast.js

@@ -151,3 +151,5 @@ /***********************************************************************

function From_Moz_Unary(M) {
return new (M.prefix ? AST_UnaryPrefix : AST_UnaryPostfix)({
var prefix = "prefix" in M ? M.prefix
: M.type == "UnaryExpression" ? true : false;
return new (prefix ? AST_UnaryPrefix : AST_UnaryPostfix)({
start : my_start_token(M),

@@ -157,3 +159,3 @@ end : my_end_token(M),

expression : from_moz(M.argument)
})
});
};

@@ -160,0 +162,0 @@

@@ -72,7 +72,12 @@ /***********************************************************************

function to_ascii(str) {
function to_ascii(str, identifier) {
return str.replace(/[\u0080-\uffff]/g, function(ch) {
var code = ch.charCodeAt(0).toString(16);
while (code.length < 4) code = "0" + code;
return "\\u" + code;
if (code.length <= 2 && !identifier) {
while (code.length < 2) code = "0" + code;
return "\\x" + code;
} else {
while (code.length < 4) code = "0" + code;
return "\\u" + code;
}
});

@@ -113,3 +118,3 @@ };

if (options.ascii_only)
name = to_ascii(name);
name = to_ascii(name, true);
return name;

@@ -1033,3 +1038,3 @@ };

if (output.option("quote_keys")) {
output.print_string(key);
output.print_string(key + "");
} else if ((typeof key == "number"

@@ -1036,0 +1041,0 @@ || !output.option("beautify")

@@ -152,3 +152,3 @@ /***********************************************************************

function is_identifier(name) {
return /^[a-z_$][a-z0-9_$]*$/i.test(name) && !RESERVED_WORDS(name);
return !RESERVED_WORDS(name) && /^[a-z_$][a-z0-9_$]*$/i.test(name);
};

@@ -194,8 +194,2 @@

function js_error(message, filename, line, col, pos) {
AST_Node.warn("ERROR: {message} [{file}:{line},{col}]", {
message: message,
file: filename,
line: line,
col: col
});
throw new JS_Parse_Error(message, line, col, pos);

@@ -202,0 +196,0 @@ };

@@ -60,3 +60,3 @@ /***********************************************************************

unmangleable: function(options) {
return this.global
return (this.global && !(options && options.toplevel))
|| this.undeclared

@@ -66,4 +66,8 @@ || (!(options && options.eval) && (this.scope.uses_eval || this.scope.uses_with));

mangle: function(options) {
if (!this.mangled_name && !this.unmangleable(options))
this.mangled_name = this.scope.next_mangled(options);
if (!this.mangled_name && !this.unmangleable(options)) {
var s = this.scope;
if (this.orig[0] instanceof AST_SymbolLambda && !options.screw_ie8)
s = s.parent_scope;
this.mangled_name = s.next_mangled(options);
}
}

@@ -126,9 +130,3 @@ };

if (node instanceof AST_SymbolLambda) {
//scope.def_function(node);
//
// https://github.com/mishoo/UglifyJS2/issues/24 — MSIE
// leaks function expression names into the containing
// scope. Don't like this fix but seems we can't do any
// better. IE: please die. Please!
(node.scope = scope.parent_scope).def_function(node);
scope.def_function(node);
}

@@ -285,3 +283,3 @@ else if (node instanceof AST_SymbolDefun) {

AST_Scope.DEFMETHOD("next_mangled", function(options){
var ext = this.enclosed, n = ext.length;
var ext = this.enclosed;
out: while (true) {

@@ -293,3 +291,3 @@ var m = base54(++this.cname);

// inner scopes.
for (var i = n; --i >= 0;) {
for (var i = ext.length; --i >= 0;) {
var sym = ext[i];

@@ -349,5 +347,7 @@ var name = sym.mangled_name || (sym.unmangleable(options) && sym.name);

return defaults(options, {
except : [],
eval : false,
sort : false
except : [],
eval : false,
sort : false,
toplevel : false,
screw_ie8 : false
});

@@ -354,0 +354,0 @@ });

@@ -6,3 +6,3 @@ {

"main": "tools/node.js",
"version": "2.2.5",
"version": "2.3.0",
"engines": { "node" : ">=0.4.0" },

@@ -19,2 +19,3 @@ "maintainers": [{

"dependencies": {
"async" : "~0.2.6",
"source-map" : "~0.1.7",

@@ -21,0 +22,0 @@ "optimist" : "~0.3.5"

@@ -57,2 +57,5 @@ UglifyJS 2

generated from some other original code.
--screw-ie8 Pass this flag if you don't care about full compliance with
Internet Explorer 6-8 quirks (by default UglifyJS will try
to be IE-proof).
-p, --prefix Skip prefix for original filenames that appear in source

@@ -145,9 +148,16 @@ maps. For example -p 3 will drop 3 directories from file

To enable the mangler you need to pass `--mangle` (`-m`). Optionally you
can pass `-m sort=true` (we'll possibly have other flags in the future) in order
to assign shorter names to most frequently used variables. This saves a few
hundred bytes on jQuery before gzip, but the output is _bigger_ after gzip
(and seems to happen for other libraries I tried it on) therefore it's not
enabled by default.
To enable the mangler you need to pass `--mangle` (`-m`). The following
(comma-separated) options are supported:
- `sort` — to assign shorter names to most frequently used variables. This
saves a few hundred bytes on jQuery before gzip, but the output is
_bigger_ after gzip (and seems to happen for other libraries I tried it
on) therefore it's not enabled by default.
- `toplevel` — mangle names declared in the toplevel scope (disabled by
default).
- `eval` — mangle names visible in scopes where `eval` or `when` are used
(disabled by default).
When mangling is enabled but you want to prevent certain names from being

@@ -168,5 +178,2 @@ mangled, you can declare those names with `--reserved` (`-r`) — pass a

The defaults should be tuned for maximum compression on most code. Here are
the available options (all are `true` by default, except `hoist_vars`):
- `sequences` -- join consecutive simple statements using the comma operator

@@ -177,3 +184,3 @@ - `properties` -- rewrite property access using the dot notation, for

- `drop_debugger` -- remove `debugger;` statements
- `unsafe` -- apply "unsafe" transformations (discussion below)
- `unsafe` (default: false) -- apply "unsafe" transformations (discussion below)
- `conditionals` -- apply optimizations for `if`-s and conditional

@@ -191,4 +198,4 @@ expressions

- `hoist_funs` -- hoist function declarations
- `hoist_vars` -- hoist `var` declarations (this is `false` by default
because it seems to increase the size of the output in general)
- `hoist_vars` (default: false) -- hoist `var` declarations (this is `false`
by default because it seems to increase the size of the output in general)
- `if_return` -- optimizations for if/return and if/continue

@@ -201,2 +208,18 @@ - `join_vars` -- join consecutive `var` statements

### The `unsafe` option
It enables some transformations that *might* break code logic in certain
contrived cases, but should be fine for most code. You might want to try it
on your own code, it should reduce the minified size. Here's what happens
when this flag is on:
- `new Array(1, 2, 3)` or `Array(1, 2, 3)` → `[1, 2, 3 ]`
- `new Object()` → `{}`
- `String(exp)` or `exp.toString()` → `"" + exp`
- `new Object/RegExp/Function/Error/Array (...)` → we discard the `new`
- `typeof foo == "undefined"` → `foo === void 0`
- `void 0` → `"undefined"` (if there is a variable named "undefined" in
scope; we do it because the variable name will be mangled, typically
reduced to a single character).
### Conditional compilation

@@ -203,0 +226,0 @@

@@ -26,1 +26,16 @@ keep_properties: {

}
dot_properties_es5: {
options = {
properties: true,
screw_ie8: true
};
input: {
a["foo"] = "bar";
a["if"] = "if";
}
expect: {
a.foo = "bar";
a.if = "if";
}
}

@@ -211,1 +211,51 @@ constant_switch_1: {

}
drop_default_1: {
options = { dead_code: true };
input: {
switch (foo) {
case 'bar': baz();
default:
}
}
expect: {
switch (foo) {
case 'bar': baz();
}
}
}
drop_default_2: {
options = { dead_code: true };
input: {
switch (foo) {
case 'bar': baz(); break;
default:
break;
}
}
expect: {
switch (foo) {
case 'bar': baz();
}
}
}
keep_default: {
options = { dead_code: true };
input: {
switch (foo) {
case 'bar': baz();
default:
something();
break;
}
}
expect: {
switch (foo) {
case 'bar': baz();
default:
something();
}
}
}

@@ -95,13 +95,14 @@ var path = require("path");

// 4. output
var map = null;
var inMap = null;
if (options.inSourceMap) {
var inMap = options.inSourceMap;
var output = {};
if (typeof options.inSourceMap == "string") {
inMap = fs.readFileSync(options.inSourceMap, "utf8");
}
if (options.outSourceMap) map = UglifyJS.SourceMap({
file: options.outSourceMap,
orig: inMap,
root: options.sourceRoot
});
var output = { source_map: map };
if (options.outSourceMap) {
output.source_map = UglifyJS.SourceMap({
file: options.outSourceMap,
orig: inMap,
root: options.sourceRoot
});
}
if (options.output) {

@@ -114,3 +115,3 @@ UglifyJS.merge(output, options.output);

code : stream + "",
map : map + ""
map : output.source_map + ""
};

@@ -117,0 +118,0 @@ };

Sorry, the diff of this file is not supported yet

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