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

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 3.12.7 to 3.12.8

203

lib/ast.js

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

},
_validate: noop,
_validate: function() {
if (this.TYPE == "Node") throw new Error("should not instantiate AST_Node");
},
validate: function() {

@@ -191,2 +193,5 @@ var ctor = this.CTOR;

$documentation: "Base class of all statements",
_validate: function() {
if (this.TYPE == "Statement") throw new Error("should not instantiate AST_Statement");
},
});

@@ -220,3 +225,3 @@

if (value instanceof AST_Spread && !allow_spread) throw new Error(prop + " cannot " + multiple + " AST_Spread");
if (value instanceof AST_Statement && !is_function(value)) {
if (value instanceof AST_Statement && !(value instanceof AST_LambdaExpression)) {
throw new Error(prop + " cannot " + multiple + " AST_Statement");

@@ -271,2 +276,3 @@ }

_validate: function() {
if (this.TYPE == "BlockScope") throw new Error("should not instantiate AST_BlockScope");
if (this.parent_scope == null) return;

@@ -296,5 +302,6 @@ if (!(this.parent_scope instanceof AST_BlockScope)) throw new Error("parent_scope must be AST_BlockScope");

_validate: function() {
if (this.TYPE == "Block") throw new Error("should not instantiate AST_Block");
this.body.forEach(function(node) {
if (!(node instanceof AST_Statement)) throw new Error("body must be AST_Statement[]");
if (is_function(node)) throw new Error("body cannot contain AST_Function");
if (node instanceof AST_LambdaExpression) throw new Error("body cannot contain AST_LambdaExpression");
});

@@ -314,4 +321,5 @@ },

_validate: function() {
if (this.TYPE == "StatementWithBody") throw new Error("should not instantiate AST_StatementWithBody");
if (!(this.body instanceof AST_Statement)) throw new Error("body must be AST_Statement");
if (is_function(this.body)) throw new Error("body cannot be AST_Function");
if (this.body instanceof AST_LambdaExpression) throw new Error("body cannot be AST_LambdaExpression");
},

@@ -355,3 +363,6 @@ }, AST_BlockScope);

var AST_IterationStatement = DEFNODE("IterationStatement", null, {
$documentation: "Internal class. All loops inherit from it."
$documentation: "Internal class. All loops inherit from it.",
_validate: function() {
if (this.TYPE == "IterationStatement") throw new Error("should not instantiate AST_IterationStatement");
},
}, AST_StatementWithBody);

@@ -365,2 +376,3 @@

_validate: function() {
if (this.TYPE == "DWLoop") throw new Error("should not instantiate AST_DWLoop");
must_be_expression(this, "condition");

@@ -412,3 +424,3 @@ },

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

@@ -422,7 +434,7 @@ }

var AST_ForIn = DEFNODE("ForIn", "init object", {
$documentation: "A `for ... in` statement",
var AST_ForEnumeration = DEFNODE("ForEnumeration", "init object", {
$documentation: "Base class for enumeration loops, i.e. `for ... in`, `for ... of` & `for await ... of`",
$propdoc: {
init: "[AST_Node] the `for/in` initialization code",
object: "[AST_Node] the object that we're looping through"
init: "[AST_Node] the assignment target during iteration",
object: "[AST_Node] the object to iterate over"
},

@@ -438,2 +450,3 @@ walk: function(visitor) {

_validate: function() {
if (this.TYPE == "ForEnumeration") throw new Error("should not instantiate AST_ForEnumeration");
if (this.init instanceof AST_Definitions) {

@@ -452,2 +465,14 @@ if (this.init.definitions.length != 1) throw new Error("init must have single declaration");

var AST_ForIn = DEFNODE("ForIn", null, {
$documentation: "A `for ... in` statement",
}, AST_ForEnumeration);
var AST_ForOf = DEFNODE("ForOf", null, {
$documentation: "A `for ... of` statement",
}, AST_ForEnumeration);
var AST_ForAwaitOf = DEFNODE("ForAwaitOf", null, {
$documentation: "A `for await ... of` statement",
}, AST_ForOf);
var AST_With = DEFNODE("With", "expression", {

@@ -482,2 +507,5 @@ $documentation: "A `with` statement",

resolve: return_this,
_validate: function() {
if (this.TYPE == "Scope") throw new Error("should not instantiate AST_Scope");
},
}, AST_Block);

@@ -533,4 +561,5 @@

argnames: "[(AST_DefaultValue|AST_Destructured|AST_SymbolFunarg)*] array of function arguments and/or destructured literals",
length_read: "[boolean/S] whether length property of this function is accessed",
rest: "[(AST_Destructured|AST_SymbolFunarg)?] rest parameter, or null if absent",
uses_arguments: "[boolean/S] tells whether this function accesses the arguments array",
uses_arguments: "[boolean/S] whether this function accesses the arguments array",
},

@@ -566,2 +595,3 @@ each_argname: function(visit) {

_validate: function() {
if (this.TYPE == "Lambda") throw new Error("should not instantiate AST_Lambda");
this.argnames.forEach(function(node) {

@@ -585,10 +615,31 @@ validate_destructured(node, function(node) {

var AST_LambdaExpression = DEFNODE("LambdaExpression", "inlined", {
$documentation: "Base class for function expressions",
$propdoc: {
inlined: "[boolean/S] whether this function has been inlined",
},
_validate: function() {
if (this.TYPE == "LambdaExpression") throw new Error("should not instantiate AST_LambdaExpression");
},
}, AST_Lambda);
function is_arrow(node) {
return node instanceof AST_AsyncArrow || node instanceof AST_Arrow;
return node instanceof AST_Arrow || node instanceof AST_AsyncArrow;
}
function is_function(node) {
return is_arrow(node) || node instanceof AST_AsyncFunction || node instanceof AST_Function;
function is_async(node) {
return node instanceof AST_AsyncArrow
|| node instanceof AST_AsyncDefun
|| node instanceof AST_AsyncFunction
|| node instanceof AST_AsyncGeneratorDefun
|| node instanceof AST_AsyncGeneratorFunction;
}
function is_generator(node) {
return node instanceof AST_AsyncGeneratorDefun
|| node instanceof AST_AsyncGeneratorFunction
|| node instanceof AST_GeneratorDefun
|| node instanceof AST_GeneratorFunction;
}
function walk_lambda(node, tw) {

@@ -602,3 +653,3 @@ if (is_arrow(node) && node.value) {

var AST_Arrow = DEFNODE("Arrow", "inlined value", {
var AST_Arrow = DEFNODE("Arrow", "value", {
$documentation: "An arrow function expression",

@@ -630,9 +681,5 @@ $propdoc: {

},
}, AST_Lambda);
}, AST_LambdaExpression);
function is_async(node) {
return node instanceof AST_AsyncArrow || node instanceof AST_AsyncDefun || node instanceof AST_AsyncFunction;
}
var AST_AsyncArrow = DEFNODE("AsyncArrow", "inlined value", {
var AST_AsyncArrow = DEFNODE("AsyncArrow", "value", {
$documentation: "An asynchronous arrow function expression",

@@ -664,5 +711,5 @@ $propdoc: {

},
}, AST_Lambda);
}, AST_LambdaExpression);
var AST_AsyncFunction = DEFNODE("AsyncFunction", "inlined name", {
var AST_AsyncFunction = DEFNODE("AsyncFunction", "name", {
$documentation: "An asynchronous function expression",

@@ -677,5 +724,17 @@ $propdoc: {

},
}, AST_Lambda);
}, AST_LambdaExpression);
var AST_Function = DEFNODE("Function", "inlined name", {
var AST_AsyncGeneratorFunction = DEFNODE("AsyncGeneratorFunction", "name", {
$documentation: "An asynchronous generator function expression",
$propdoc: {
name: "[AST_SymbolLambda?] the name of this function",
},
_validate: function() {
if (this.name != null) {
if (!(this.name instanceof AST_SymbolLambda)) throw new Error("name must be AST_SymbolLambda");
}
},
}, AST_LambdaExpression);
var AST_Function = DEFNODE("Function", "name", {
$documentation: "A function expression",

@@ -690,24 +749,24 @@ $propdoc: {

},
}, AST_Lambda);
}, AST_LambdaExpression);
function is_defun(node) {
return node instanceof AST_AsyncDefun || node instanceof AST_Defun;
}
var AST_AsyncDefun = DEFNODE("AsyncDefun", "inlined name", {
$documentation: "An asynchronous function definition",
var AST_GeneratorFunction = DEFNODE("GeneratorFunction", "name", {
$documentation: "A generator function expression",
$propdoc: {
name: "[AST_SymbolDefun] the name of this function",
name: "[AST_SymbolLambda?] the name of this function",
},
_validate: function() {
if (!(this.name instanceof AST_SymbolDefun)) throw new Error("name must be AST_SymbolDefun");
if (this.name != null) {
if (!(this.name instanceof AST_SymbolLambda)) throw new Error("name must be AST_SymbolLambda");
}
},
}, AST_Lambda);
}, AST_LambdaExpression);
var AST_Defun = DEFNODE("Defun", "inlined name", {
$documentation: "A function definition",
var AST_LambdaDefinition = DEFNODE("LambdaDefinition", "inlined name", {
$documentation: "Base class for function definitions",
$propdoc: {
inlined: "[boolean/S] whether this function has been inlined",
name: "[AST_SymbolDefun] the name of this function",
},
_validate: function() {
if (this.TYPE == "LambdaDefinition") throw new Error("should not instantiate AST_LambdaDefinition");
if (!(this.name instanceof AST_SymbolDefun)) throw new Error("name must be AST_SymbolDefun");

@@ -717,6 +776,25 @@ },

var AST_AsyncDefun = DEFNODE("AsyncDefun", null, {
$documentation: "An asynchronous function definition",
}, AST_LambdaDefinition);
var AST_AsyncGeneratorDefun = DEFNODE("AsyncGeneratorDefun", null, {
$documentation: "An asynchronous generator function definition",
}, AST_LambdaDefinition);
var AST_Defun = DEFNODE("Defun", null, {
$documentation: "A function definition",
}, AST_LambdaDefinition);
var AST_GeneratorDefun = DEFNODE("GeneratorDefun", null, {
$documentation: "A generator function definition",
}, AST_LambdaDefinition);
/* -----[ JUMPS ]----- */
var AST_Jump = DEFNODE("Jump", null, {
$documentation: "Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)"
$documentation: "Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)",
_validate: function() {
if (this.TYPE == "Jump") throw new Error("should not instantiate AST_Jump");
},
}, AST_Statement);

@@ -734,3 +812,6 @@

});
}
},
_validate: function() {
if (this.TYPE == "Exit") throw new Error("should not instantiate AST_Exit");
},
}, AST_Jump);

@@ -764,2 +845,3 @@

_validate: function() {
if (this.TYPE == "LoopControl") throw new Error("should not instantiate AST_LoopControl");
if (this.label != null) {

@@ -799,3 +881,3 @@ if (!(this.label instanceof AST_LabelRef)) throw new Error("label must be AST_LabelRef");

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

@@ -829,2 +911,5 @@ },

$documentation: "Base class for `switch` branches",
_validate: function() {
if (this.TYPE == "SwitchBranch") throw new Error("should not instantiate AST_SwitchBranch");
},
}, AST_Block);

@@ -918,2 +1003,3 @@

_validate: function() {
if (this.TYPE == "Definitions") throw new Error("should not instantiate AST_Definitions");
if (this.definitions.length < 1) throw new Error("must have at least one definition");

@@ -1066,2 +1152,3 @@ },

_validate: function() {
if (this.TYPE == "PropAccess") throw new Error("should not instantiate AST_PropAccess");
must_be_expression(this, "expression");

@@ -1127,2 +1214,3 @@ },

_validate: function() {
if (this.TYPE == "Unary") throw new Error("should not instantiate AST_Unary");
if (typeof this.operator != "string") throw new Error("operator must be string");

@@ -1215,2 +1303,23 @@ must_be_expression(this, "expression");

var AST_Yield = DEFNODE("Yield", "expression nested", {
$documentation: "A yield expression",
$propdoc: {
expression: "[AST_Node?] return value for iterator, or null if undefined",
nested: "[boolean] whether to iterate over expression as generator",
},
walk: function(visitor) {
var node = this;
visitor.visit(node, function() {
if (node.expression) node.expression.walk(visitor);
});
},
_validate: function() {
if (this.expression != null) {
must_be_expression(this, "expression");
} else if (this.nested) {
throw new Error("yield* must contain expression");
}
},
});
/* -----[ LITERALS ]----- */

@@ -1241,2 +1350,5 @@

},
_validate: function() {
if (this.TYPE == "Destructured") throw new Error("should not instantiate AST_Destructured");
},
});

@@ -1353,2 +1465,3 @@

_validate: function() {
if (this.TYPE == "ObjectProperty") throw new Error("should not instantiate AST_ObjectProperty");
if (typeof this.key != "string") {

@@ -1391,2 +1504,3 @@ if (!(this.key instanceof AST_Node)) throw new Error("key must be string or AST_Node");

_validate: function() {
if (this.TYPE == "Symbol") throw new Error("should not instantiate AST_Symbol");
if (typeof this.name != "string") throw new Error("name must be string");

@@ -1484,2 +1598,5 @@ },

$documentation: "Base class for all constants",
_validate: function() {
if (this.TYPE == "Constant") throw new Error("should not instantiate AST_Constant");
},
});

@@ -1533,2 +1650,5 @@

$documentation: "Base class for atoms",
_validate: function() {
if (this.TYPE == "Atom") throw new Error("should not instantiate AST_Atom");
},
}, AST_Constant);

@@ -1563,2 +1683,5 @@

$documentation: "Base class for booleans",
_validate: function() {
if (this.TYPE == "Boolean") throw new Error("should not instantiate AST_Boolean");
},
}, AST_Atom);

@@ -1565,0 +1688,0 @@

94

lib/output.js

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

PARENS(AST_AsyncFunction, needs_parens_function);
PARENS(AST_AsyncGeneratorFunction, needs_parens_function);
PARENS(AST_Function, needs_parens_function);
PARENS(AST_GeneratorFunction, needs_parens_function);

@@ -686,10 +688,15 @@ // same goes for an object literal, because otherwise it would be

PARENS(AST_Unary, function(output) {
function needs_parens_unary(output) {
var p = output.parent();
// (-x) ** y
if (p instanceof AST_Binary) return p.operator == "**" && p.left === this;
// (x++).toString(3)
// (typeof x).length
return (p instanceof AST_Call || p instanceof AST_PropAccess) && p.expression === this;
});
// (await x)(y)
// new (await x)
if (p instanceof AST_Call) return p.expression === this;
// (x++)[y]
// (typeof x).y
if (p instanceof AST_PropAccess) return p.expression === this;
}
PARENS(AST_Await, needs_parens_unary);
PARENS(AST_Unary, needs_parens_unary);

@@ -713,5 +720,9 @@ PARENS(AST_Sequence, function(output) {

|| p instanceof AST_DefaultValue
// { [(1, 2)]: foo } = bar
// { 1: (2, foo) } = bar
|| p instanceof AST_DestructuredKeyVal
// for (foo of (bar, baz));
|| p instanceof AST_ForOf
// { [(1, 2)]: 3 }[2] ---> 3
// { foo: (1, 2) }.foo ---> 2
|| p instanceof AST_DestructuredKeyVal
|| p instanceof AST_ObjectProperty

@@ -725,3 +736,5 @@ // (1, {foo:2}).foo or (1, {foo:2})["foo"] ---> 2

// var a = (1, 2), b = a + a; ---> b == 4
|| p instanceof AST_VarDef;
|| p instanceof AST_VarDef
// yield (foo, bar)
|| p instanceof AST_Yield;
});

@@ -833,13 +846,4 @@

});
PARENS(AST_Await, function(output) {
var p = output.parent();
// (await x) ** y
if (p instanceof AST_Binary) return p.operator == "**" && p.left === this;
// 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;
PARENS(AST_Yield, function(output) {
return needs_parens_assign_cond(this, output);
});

@@ -986,16 +990,21 @@

});
DEFPRINT(AST_ForIn, function(output) {
var self = this;
output.print("for");
output.space();
output.with_parens(function() {
self.init.print(output);
function print_for_enum(prefix, infix) {
return function(output) {
var self = this;
output.print(prefix);
output.space();
output.print("in");
output.with_parens(function() {
self.init.print(output);
output.space();
output.print(infix);
output.space();
self.object.print(output);
});
output.space();
self.object.print(output);
});
output.space();
force_statement(self.body, output);
});
force_statement(self.body, output);
};
}
DEFPRINT(AST_ForAwaitOf, print_for_enum("for await", "of"));
DEFPRINT(AST_ForIn, print_for_enum("for", "in"));
DEFPRINT(AST_ForOf, print_for_enum("for", "of"));
DEFPRINT(AST_With, function(output) {

@@ -1070,2 +1079,16 @@ var self = this;

DEFPRINT(AST_AsyncFunction, print_async);
function print_async_generator(output) {
output.print("async");
output.space();
output.print("function*");
print_lambda(this, output);
}
DEFPRINT(AST_AsyncGeneratorDefun, print_async_generator);
DEFPRINT(AST_AsyncGeneratorFunction, print_async_generator);
function print_generator(output) {
output.print("function*");
print_lambda(this, output);
}
DEFPRINT(AST_GeneratorDefun, print_generator);
DEFPRINT(AST_GeneratorFunction, print_generator);

@@ -1222,3 +1245,3 @@ /* -----[ jumps ]----- */

var p = output.parent();
if (p && p.init !== self || !(p instanceof AST_For || p instanceof AST_ForIn)) output.semicolon();
if (!(p instanceof AST_IterationStatement && p.init === self)) output.semicolon();
};

@@ -1250,3 +1273,3 @@ }

var p = output.parent(1);
var noin = p instanceof AST_For || p instanceof AST_ForIn;
var noin = p instanceof AST_For || p instanceof AST_ForEnumeration;
parenthesize_for_noin(self.value, output, noin);

@@ -1372,2 +1395,9 @@ }

});
DEFPRINT(AST_Yield, function(output) {
output.print(this.nested ? "yield*" : "yield");
if (this.expression) {
output.space();
this.expression.print(output);
}
});

@@ -1374,0 +1404,0 @@ /* -----[ literals ]----- */

@@ -124,3 +124,3 @@ /***********************************************************************

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

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

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

@@ -453,3 +453,3 @@ return def;

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

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

@@ -85,3 +85,3 @@ /***********************************************************************

});
DEF(AST_ForIn, function(self, tw) {
DEF(AST_ForEnumeration, function(self, tw) {
self.init = self.init.transform(tw);

@@ -161,2 +161,5 @@ self.object = self.object.transform(tw);

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

@@ -163,0 +166,0 @@ self.expression = self.expression.transform(tw);

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

"license": "BSD-2-Clause",
"version": "3.12.7",
"version": "3.12.8",
"engines": {

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

@@ -814,2 +814,4 @@ UglifyJS 3

- `yields` (default: `true`) -- apply optimizations to `yield` expressions
## Mangle options

@@ -1274,1 +1276,10 @@

UglifyJS may modify the input which in turn may suppress those errors.
- Some versions of JavaScript will throw `SyntaxError` with the
following:
```javascript
try {} catch (e) {
for (var e of []);
}
// SyntaxError: Identifier 'e' has already been declared
```
UglifyJS may modify the input which in turn may suppress those errors.

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