Socket
Socket
Sign inDemoInstall

uglify-js

Package Overview
Dependencies
0
Maintainers
3
Versions
284
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.12.1 to 3.12.2

99

lib/ast.js

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

if (!(node[prop] instanceof AST_Node)) throw new Error(prop + " must be AST_Node");
if (node[prop] instanceof AST_Statement && !(node[prop] instanceof AST_Function)) {
if (node[prop] instanceof AST_Hole) throw new Error(prop + " cannot be AST_Hole");
if (node[prop] instanceof AST_Spread) throw new Error(prop + " cannot be AST_Spread");
if (node[prop] instanceof AST_Statement && !is_function(node[prop])) {
throw new Error(prop + " cannot be AST_Statement");

@@ -282,3 +284,3 @@ }

if (!(node instanceof AST_Statement)) throw new Error("body must be AST_Statement[]");
if (node instanceof AST_Function) throw new Error("body cannot contain AST_Function");
if (is_function(node)) throw new Error("body cannot contain AST_Function");
});

@@ -299,3 +301,3 @@ },

if (!(this.body instanceof AST_Statement)) throw new Error("body must be AST_Statement");
if (this.body instanceof AST_Function) throw new Error("body cannot be AST_Function");
if (is_function(this.body)) throw new Error("body cannot be AST_Function");
},

@@ -394,3 +396,3 @@ }, AST_BlockScope);

if (this.init instanceof AST_Statement
&& !(this.init instanceof AST_Definitions || this.init instanceof AST_Function)) {
&& !(this.init instanceof AST_Definitions || is_function(this.init))) {
throw new Error("init cannot be AST_Statement");

@@ -552,2 +554,15 @@ }

function is_function(node) {
return node instanceof AST_AsyncFunction || node instanceof AST_Function;
}
var AST_AsyncFunction = DEFNODE("AsyncFunction", "inlined", {
$documentation: "An asynchronous function expression",
_validate: function() {
if (this.name != null) {
if (!(this.name instanceof AST_SymbolLambda)) throw new Error("name must be AST_SymbolLambda");
}
},
}, AST_Lambda);
var AST_Function = DEFNODE("Function", "inlined", {

@@ -562,2 +577,13 @@ $documentation: "A function expression",

function is_defun(node) {
return node instanceof AST_AsyncDefun || node instanceof AST_Defun;
}
var AST_AsyncDefun = DEFNODE("AsyncDefun", "inlined", {
$documentation: "An asynchronous function definition",
_validate: function() {
if (!(this.name instanceof AST_SymbolDefun)) throw new Error("name must be AST_SymbolDefun");
},
}, AST_Lambda);
var AST_Defun = DEFNODE("Defun", "inlined", {

@@ -649,3 +675,3 @@ $documentation: "A function definition",

if (!(this.alternative instanceof AST_Statement)) throw new Error("alternative must be AST_Statement");
if (this.alternative instanceof AST_Function) throw new error("alternative cannot be AST_Function");
if (is_function(this.alternative)) throw new error("alternative cannot be AST_Function");
}

@@ -827,6 +853,8 @@ },

function must_be_expressions(node, prop) {
function must_be_expressions(node, prop, allow_spread, allow_hole) {
node[prop].forEach(function(node) {
if (!(node instanceof AST_Node)) throw new Error(prop + " must be AST_Node[]");
if (node instanceof AST_Statement && !(node instanceof AST_Function)) {
if (!allow_hole && node instanceof AST_Hole) throw new Error(prop + " cannot be AST_Hole");
if (!allow_spread && node instanceof AST_Spread) throw new Error(prop + " cannot be AST_Spread");
if (node instanceof AST_Statement && !is_function(node)) {
throw new Error(prop + " cannot contain AST_Statement");

@@ -854,3 +882,3 @@ }

must_be_expression(this, "expression");
must_be_expressions(this, "args");
must_be_expressions(this, "args", true);
},

@@ -932,2 +960,18 @@ });

var AST_Spread = DEFNODE("Spread", "expression", {
$documentation: "Spread expression in array/object literals or function calls",
$propdoc: {
expression: "[AST_Node] expression to be expanded",
},
walk: function(visitor) {
var node = this;
visitor.visit(node, function() {
node.expression.walk(visitor);
});
},
_validate: function() {
must_be_expression(this, "expression");
},
});
var AST_Unary = DEFNODE("Unary", "operator expression", {

@@ -1017,2 +1061,18 @@ $documentation: "Base class for unary expressions",

var AST_Await = DEFNODE("Await", "expression", {
$documentation: "An await expression",
$propdoc: {
expression: "[AST_Node] expression with Promise to resolve on",
},
walk: function(visitor) {
var node = this;
visitor.visit(node, function() {
node.expression.walk(visitor);
});
},
_validate: function() {
must_be_expression(this, "expression");
},
});
/* -----[ LITERALS ]----- */

@@ -1034,3 +1094,3 @@

_validate: function() {
must_be_expressions(this, "elements");
must_be_expressions(this, "elements", true, true);
},

@@ -1113,3 +1173,3 @@ });

$propdoc: {
properties: "[AST_ObjectProperty*] array of properties"
properties: "[(AST_ObjectProperty|AST_Spread)*] array of properties"
},

@@ -1126,3 +1186,5 @@ walk: function(visitor) {

this.properties.forEach(function(node) {
if (!(node instanceof AST_ObjectProperty)) throw new Error("properties must be AST_ObjectProperty[]");
if (!(node instanceof AST_ObjectProperty || node instanceof AST_Spread)) {
throw new Error("properties must contain AST_ObjectProperty and/or AST_Spread only");
}
});

@@ -1406,10 +1468,9 @@ },

} else if (p instanceof AST_Return) {
var fn;
do {
fn = this.parent(++i);
if (!fn) return false;
} while (!(fn instanceof AST_Lambda));
if (fn.name) return false;
self = this.parent(++i);
if (!self || self.TYPE != "Call" || self.expression !== fn) return false;
for (var call, fn = p; call = this.parent(++i); fn = call) {
if (call.TYPE == "Call") {
if (!(fn instanceof AST_Lambda) || fn.name) return false;
} else if (fn instanceof AST_Lambda) {
return false;
}
}
} else {

@@ -1416,0 +1477,0 @@ return false;

@@ -664,3 +664,3 @@ /***********************************************************************

// the first token to appear in a statement.
PARENS(AST_Function, function(output) {
function needs_parens_function(output) {
if (!output.has_parens() && first_in_statement(output)) return true;

@@ -675,3 +675,5 @@ if (output.option("webkit")) {

}
});
}
PARENS(AST_AsyncFunction, needs_parens_function);
PARENS(AST_Function, needs_parens_function);

@@ -694,2 +696,4 @@ // same goes for an object literal, because otherwise it would be

return p instanceof AST_Array
// await (foo, bar)
|| p instanceof AST_Await
// 1 + (2, 3) + 4 ==> 8

@@ -708,2 +712,4 @@ || p instanceof AST_Binary

|| p instanceof AST_PropAccess && p.expression === this
// ...(foo, bar, baz)
|| p instanceof AST_Spread
// !(foo, bar, baz)

@@ -717,2 +723,4 @@ || p instanceof AST_Unary

var p = output.parent();
// await (foo && bar)
if (p instanceof AST_Await) return true;
// this deals with precedence: 3 * (2 + 1)

@@ -785,2 +793,4 @@ if (p instanceof AST_Binary) {

var p = output.parent();
// await (a = foo)
if (p instanceof AST_Await) return true;
// 1 + (a = 2) + 3 → 6, side effect setting a = 2

@@ -809,2 +819,12 @@ if (p instanceof AST_Binary) return !(p instanceof AST_Assign);

PARENS(AST_Await, function(output) {
var p = output.parent();
// new (await foo)
// (await foo)(bar)
if (p instanceof AST_Call) return p.expression === this;
// (await foo).prop
// (await foo)["prop"]
if (p instanceof AST_PropAccess) return p.expression === this;
});
/* -----[ PRINTERS ]----- */

@@ -975,7 +995,3 @@

/* -----[ functions ]----- */
DEFPRINT(AST_Lambda, function(output, nokeyword) {
var self = this;
if (!nokeyword) {
output.print("function");
}
function print_lambda(self, output) {
if (self.name) {

@@ -993,3 +1009,15 @@ output.space();

print_braced(self, output, true);
}
DEFPRINT(AST_Lambda, function(output) {
output.print("function");
print_lambda(this, output);
});
function print_async(output) {
output.print("async");
output.space();
output.print("function");
print_lambda(this, output);
}
DEFPRINT(AST_AsyncDefun, print_async);
DEFPRINT(AST_AsyncFunction, print_async);

@@ -1243,2 +1271,6 @@ /* -----[ jumps ]----- */

});
DEFPRINT(AST_Spread, function(output) {
output.print("...");
this.expression.print(output);
});
DEFPRINT(AST_UnaryPrefix, function(output) {

@@ -1279,2 +1311,7 @@ var op = this.operator;

});
DEFPRINT(AST_Await, function(output) {
output.print("await");
output.space();
this.expression.print(output);
});

@@ -1383,3 +1420,3 @@ /* -----[ literals ]----- */

print_property_key(self, output);
self.value._codegen(output, true);
print_lambda(self.value, output);
};

@@ -1386,0 +1423,0 @@ }

129

lib/parse.js

@@ -50,3 +50,3 @@ /***********************************************************************

var RESERVED_WORDS = [
"abstract boolean byte char class double enum export extends final float goto implements import int interface let long native package private protected public short static super synchronized this throws transient volatile yield",
"await abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized this throws transient volatile yield",
KEYWORDS_ATOM,

@@ -505,3 +505,12 @@ KEYWORDS,

next();
return is_digit(peek().charCodeAt(0)) ? read_num(".") : token("punc", ".");
var ch = peek();
if (ch == ".") {
var op = ".";
do {
op += ".";
next();
} while (peek() == ".");
return token("operator", op);
}
return is_digit(ch.charCodeAt(0)) ? read_num(".") : token("punc", ".");
}

@@ -649,9 +658,11 @@

: $TEXT,
token : null,
prev : null,
peeked : null,
in_async : false,
in_directives : true,
in_funarg : -1,
in_function : 0,
in_directives : true,
in_loop : 0,
labels : []
labels : [],
peeked : null,
prev : null,
token : null,
};

@@ -783,5 +794,16 @@

case "name":
return is_token(peek(), "punc", ":")
? labeled_statement()
: simple_statement();
switch (S.token.value) {
case "async":
if (is_token(peek(), "keyword", "function")) {
next();
next();
return function_(AST_AsyncDefun);
}
case "await":
if (S.in_async) return simple_statement();
default:
return is_token(peek(), "punc", ":")
? labeled_statement()
: simple_statement();
}

@@ -1024,15 +1046,23 @@ case "punc":

var function_ = function(ctor) {
var in_statement = ctor === AST_Defun;
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
if (in_statement && !name)
expect_token("name");
var was_async = S.in_async;
var name;
if (ctor === AST_AsyncDefun) {
name = as_symbol(AST_SymbolDefun);
S.in_async = true;
} else if (ctor === AST_Defun) {
name = as_symbol(AST_SymbolDefun);
S.in_async = false;
} else {
S.in_async = ctor === AST_AsyncFunction;
name = as_symbol(AST_SymbolLambda, true);
}
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
unexpected(prev());
expect("(");
var argnames = [];
for (var first = true; !is("punc", ")");) {
if (first) first = false; else expect(",");
argnames.push(maybe_destructured(AST_SymbolFunarg));
}
next();
var was_funarg = S.in_funarg;
S.in_funarg = S.in_function;
var argnames = expr_list(")", !options.strict, false, function() {
return maybe_destructured(AST_SymbolFunarg);
});
S.in_funarg = was_funarg;
var loop = S.in_loop;

@@ -1054,2 +1084,3 @@ var labels = S.labels;

S.labels = labels;
S.in_async = was_async;
return new ctor({

@@ -1212,3 +1243,3 @@ name: name,

next();
args = expr_list(")");
args = expr_list(")", !options.strict);
} else {

@@ -1305,5 +1336,12 @@ args = [];

}
if (is("keyword", "function")) {
var ctor;
if (is("name", "async") && is_token(peek(), "keyword", "function")) {
next();
var func = function_(AST_Function);
ctor = AST_AsyncFunction;
} else if (is("keyword", "function")) {
ctor = AST_Function;
}
if (ctor) {
next();
var func = function_(ctor);
func.start = start;

@@ -1325,4 +1363,10 @@ func.end = prev();

if (allow_trailing_comma && is("punc", closing)) break;
if (is("punc", ",") && allow_empty) {
if (allow_empty && is("punc", ",")) {
a.push(new AST_Hole({ start: S.token, end: S.token }));
} else if (parser === expression && is("operator", "...")) {
a.push(new AST_Spread({
start: S.token,
expression: (next(), parser()),
end: prev(),
}));
} else {

@@ -1355,2 +1399,11 @@ a.push(parser());

var start = S.token;
if (is("operator", "...")) {
next();
a.push(new AST_Spread({
start: start,
expression: expression(false),
end: prev(),
}));
continue;
}
var key = as_property_key();

@@ -1440,2 +1493,3 @@ if (is("punc", "(")) {

var name = token.value;
if (name === "await" && S.in_async) unexpected(token);
return new (name === "this" ? AST_This : type)({

@@ -1554,3 +1608,3 @@ name: "" + name,

expression : expr,
args : expr_list(")"),
args : expr_list(")", !options.strict),
end : prev()

@@ -1564,3 +1618,3 @@ });

var maybe_unary = function(allow_calls) {
function maybe_unary() {
var start = S.token;

@@ -1570,3 +1624,3 @@ if (is("operator") && UNARY_PREFIX[start.value]) {

handle_regexp();
var ex = make_unary(AST_UnaryPrefix, start, maybe_unary(allow_calls));
var ex = make_unary(AST_UnaryPrefix, start, maybe_await());
ex.start = start;

@@ -1576,3 +1630,3 @@ ex.end = prev();

}
var val = expr_atom(allow_calls);
var val = expr_atom(true);
while (is("operator") && UNARY_POSTFIX[S.token.value] && !has_newline_before(S.token)) {

@@ -1585,3 +1639,3 @@ val = make_unary(AST_UnaryPostfix, S.token, val);

return val;
};
}

@@ -1604,2 +1658,15 @@ function make_unary(ctor, token, expr) {

function maybe_await() {
var start = S.token;
if (!(S.in_async && is("name", "await"))) return maybe_unary();
if (S.in_funarg === S.in_function) croak("Invalid use of await in function argument");
S.input.context().regex_allowed = true;
next();
return new AST_Await({
start: start,
expression: maybe_await(),
end: prev(),
});
}
var expr_op = function(left, min_prec, no_in) {

@@ -1611,3 +1678,3 @@ var op = is("operator") ? S.token.value : null;

next();
var right = expr_op(maybe_unary(true), prec, no_in);
var right = expr_op(maybe_await(), prec, no_in);
return expr_op(new AST_Binary({

@@ -1625,3 +1692,3 @@ start : left.start,

function expr_ops(no_in) {
return expr_op(maybe_unary(true), 0, no_in);
return expr_op(maybe_await(), 0, no_in);
}

@@ -1628,0 +1695,0 @@

@@ -115,3 +115,3 @@ /***********************************************************************

var tw = new TreeWalker(function(node, descend) {
if (node instanceof AST_Defun) {
if (is_defun(node)) {
node.name.walk(tw);

@@ -194,3 +194,3 @@ walk_scope(function() {

node.mark_enclosed(options);
var def = scope.find_variable(node);
var def = scope.find_variable(node.name);
if (node.thedef === def) return;

@@ -224,2 +224,17 @@ node.thedef = def;

}
// ensure mangling works if `catch` reuses a scope variable
if (node instanceof AST_SymbolCatch) {
var def = node.definition().redefined();
if (def) for (var s = node.scope; s; s = s.parent_scope) {
push_uniq(s.enclosed, def);
if (s === def.scope) break;
}
return true;
}
// ensure compression works if `const` reuses a scope variable
if (node instanceof AST_SymbolConst) {
var redef = node.definition().redefined();
if (redef) redef.const_redefs = true;
return true;
}
if (node instanceof AST_SymbolRef) {

@@ -264,17 +279,2 @@ var name = node.name;

}
// ensure mangling works if `catch` reuses a scope variable
if (node instanceof AST_SymbolCatch) {
var def = node.definition().redefined();
if (def) for (var s = node.scope; s; s = s.parent_scope) {
push_uniq(s.enclosed, def);
if (s === def.scope) break;
}
return true;
}
// ensure compression works if `const` reuses a scope variable
if (node instanceof AST_SymbolConst) {
var redef = node.definition().redefined();
if (redef) redef.const_redefs = true;
return true;
}
});

@@ -397,5 +397,4 @@ self.walk(tw);

AST_BlockScope.DEFMETHOD("find_variable", function(name) {
if (name instanceof AST_Symbol) name = name.name;
return this.variables.get(name)
|| (this.parent_scope && this.parent_scope.find_variable(name));
|| this.parent_scope && this.parent_scope.find_variable(name);
});

@@ -405,3 +404,3 @@

var def = this.def_variable(symbol, init);
if (!def.init || def.init instanceof AST_Defun) def.init = init;
if (!def.init || is_defun(def.init)) def.init = init;
this.functions.set(symbol.name, def);

@@ -415,3 +414,3 @@ return def;

def.orig.push(symbol);
if (def.init instanceof AST_Function) def.init = init;
if (is_function(def.init)) def.init = init;
} else {

@@ -418,0 +417,0 @@ def = this.make_def(symbol, init);

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

});
DEF(AST_Await, function(self, tw) {
self.expression = self.expression.transform(tw);
});
DEF(AST_Dot, function(self, tw) {

@@ -149,2 +152,5 @@ self.expression = self.expression.transform(tw);

});
DEF(AST_Spread, function(self, tw) {
self.expression = self.expression.transform(tw);
});
DEF(AST_Unary, function(self, tw) {

@@ -151,0 +157,0 @@ self.expression = self.expression.transform(tw);

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

"license": "BSD-2-Clause",
"version": "3.12.1",
"version": "3.12.2",
"engines": {

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

@@ -7,6 +7,8 @@ UglifyJS 3

#### Note:
- **`uglify-js@3` has a simplified [API](#api-reference) and [CLI](#command-line-usage) that is not backwards compatible with [`uglify-js@2`](https://github.com/mishoo/UglifyJS/tree/v2.x)**.
- **`uglify-js@3` has a simplified [API](#api-reference) and [CLI](#command-line-usage)
that is not backwards compatible with [`uglify-js@2`](https://github.com/mishoo/UglifyJS/tree/v2.x)**.
- **Documentation for UglifyJS `2.x` releases can be found [here](https://github.com/mishoo/UglifyJS/tree/v2.x)**.
- `uglify-js` only supports JavaScript (ECMAScript 5).
- To minify ECMAScript 2015 or above, transpile using tools like [Babel](https://babeljs.io/).
- `uglify-js` supports ECMAScript 5 and some newer language features.
- To minify ECMAScript 2015 or above, you may need to transpile using tools like
[Babel](https://babeljs.io/).

@@ -755,2 +757,4 @@ Install

- `spread` (default: `true`) -- flatten spread expressions.
- `strings` (default: `true`) -- compact string concatenations.

@@ -1178,2 +1182,14 @@

`Object.preventExtensions()` or `Object.seal()`).
- Earlier versions of JavaScript will throw `SyntaxError` with the following:
```js
({
p: 42,
get p() {},
});
// SyntaxError: Object literal may not have data and accessor property with
// the same name
```
UglifyJS may modify the input which in turn may suppress those errors.
- Iteration order of keys over an object which contains spread syntax in later
versions of Chrome and Node.js may be altered.
- When `toplevel` is enabled, UglifyJS effectively assumes input code is wrapped

@@ -1180,0 +1196,0 @@ within `function(){ ... }`, thus forbids aliasing of declared global variables:

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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc