🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@fabiosantoscode/uglify-es

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fabiosantoscode/uglify-es - npm Package Compare versions

Comparing version
3.3.11
to
3.4.0
+26
-9
lib/ast.js

@@ -167,6 +167,17 @@ /***********************************************************************

var AST_Block = DEFNODE("Block", "body", {
function clone_block_scope(deep) {
var clone = this._clone(deep);
if (this.block_scope) {
// TODO this is sometimes undefined during compression.
// But it should always have a value!
clone.block_scope = this.block_scope.clone();
}
return clone;
}
var AST_Block = DEFNODE("Block", "body block_scope", {
$documentation: "A body of statements (usually bracketed)",
$propdoc: {
body: "[AST_Statement*] an array of statements"
body: "[AST_Statement*] an array of statements",
block_scope: "[AST_Scope] the block scope"
},

@@ -177,3 +188,4 @@ _walk: function(visitor) {

});
}
},
clone: clone_block_scope
}, AST_Statement);

@@ -224,4 +236,8 @@

var AST_IterationStatement = DEFNODE("IterationStatement", null, {
$documentation: "Internal class. All loops inherit from it."
var AST_IterationStatement = DEFNODE("IterationStatement", "block_scope", {
$documentation: "Internal class. All loops inherit from it.",
$propdoc: {
block_scope: "[AST_Scope] the block scope for this iteration statement."
},
clone: clone_block_scope
}, AST_StatementWithBody);

@@ -451,3 +467,3 @@

}
})
});

@@ -650,3 +666,3 @@ var AST_TemplateString = DEFNODE("TemplateString", "segments", {

}
})
});

@@ -1079,6 +1095,7 @@ var AST_Import = DEFNODE("Import", "imported_name imported_names module_name", {

var AST_RegExp = DEFNODE("RegExp", "value", {
var AST_RegExp = DEFNODE("RegExp", "value raw", {
$documentation: "A regexp literal",
$propdoc: {
value: "[RegExp] the actual regexp"
value: "[RegExp] the actual regexp",
raw: "[string] the raw regexp source"
}

@@ -1085,0 +1102,0 @@ }, AST_Constant);

@@ -55,2 +55,3 @@ "use strict";

mangle: {},
module: false,
nameCache: null,

@@ -80,2 +81,3 @@ output: {},

set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
set_shorthand("module", options, [ "parse", "compress", "mangle" ]);
set_shorthand("safari10", options, [ "mangle", "output" ]);

@@ -92,2 +94,3 @@ set_shorthand("toplevel", options, [ "compress", "mangle" ]);

keep_fnames: false,
module: false,
properties: false,

@@ -94,0 +97,0 @@ reserved: [],

@@ -74,2 +74,75 @@ /***********************************************************************

},
ArrayPattern: function(M) {
return new AST_Destructuring({
start: my_start_token(M),
end: my_end_token(M),
names: M.elements.map(function(elm) {
if (elm === null) {
return new AST_Hole();
}
return from_moz(elm);
}),
is_array: true
});
},
ObjectPattern: function(M) {
return new AST_Destructuring({
start: my_start_token(M),
end: my_end_token(M),
names: M.properties.map(from_moz),
});
},
AssignmentPattern: function(M) {
return new AST_Binary({
start: my_start_token(M),
end: my_end_token(M),
left: from_moz(M.left),
operator: "=",
right: from_moz(M.right)
});
},
SpreadElement: function(M) {
return new AST_Expansion({
start: my_start_token(M),
end: my_end_token(M),
expression: from_moz(M.argument)
});
},
RestElement: function(M) {
return new AST_Expansion({
start: my_start_token(M),
end: my_end_token(M),
expression: from_moz(M.argument)
});
},
TemplateElement: function(M) {
return new AST_TemplateSegment({
start: my_start_token(M),
end: my_end_token(M),
value: M.value.cooked,
raw: M.value.raw
});
},
TemplateLiteral: function(M) {
var segments = [];
for (var i = 0; i < M.quasis.length; i++) {
segments.push(from_moz(M.quasis[i]));
if (M.expressions[i]) {
segments.push(from_moz(M.expressions[i]));
}
}
return new AST_TemplateString({
start: my_start_token(M),
end: my_end_token(M),
segments: segments
});
},
TaggedTemplateExpression: function(M) {
return new AST_PrefixedTemplateString({
start: my_start_token(M),
end: my_end_token(M),
template_string: from_moz(M.quasi),
prefix: from_moz(M.tag)
});
},
FunctionDeclaration: function(M) {

@@ -81,2 +154,4 @@ return new AST_Defun({

argnames: M.params.map(from_moz),
is_generator: M.generator,
async: M.async,
body: normalize_directives(from_moz(M.body).body)

@@ -91,5 +166,16 @@ });

argnames: M.params.map(from_moz),
is_generator: M.generator,
async: M.async,
body: normalize_directives(from_moz(M.body).body)
});
},
ArrowFunctionExpression: function(M) {
return new AST_Arrow({
start: my_start_token(M),
end: my_end_token(M),
argnames: M.params.map(from_moz),
body: from_moz(M.body),
async: M.async,
});
},
ExpressionStatement: function(M) {

@@ -123,3 +209,18 @@ return new AST_SimpleStatement({

};
if (M.kind == "init") return new AST_ObjectKeyVal(args);
if (M.method) {
args.is_generator = M.value.generator;
args.async = M.value.async;
if (!M.computed) {
args.key = new AST_SymbolMethod({ name: args.key });
} else {
args.key = from_moz(M.key);
}
return new AST_ConciseMethod(args);
}
if (M.kind == "init") {
if (key.type != "Identifier") {
args.key = from_moz(key);
}
return new AST_ObjectKeyVal(args);
}
args.key = new AST_SymbolMethod({

@@ -131,3 +232,27 @@ name: args.key

if (M.kind == "set") return new AST_ObjectSetter(args);
if (M.kind == "method") {
args.async = M.value.async;
args.is_generator = M.value.generator;
args.quote = M.computed ? "\"" : null;
return new AST_ConciseMethod(args);
}
},
MethodDefinition: function(M) {
var args = {
start : my_start_token(M),
end : my_end_token(M),
key : M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || M.key.value }),
value : from_moz(M.value),
static : M.static,
};
if (M.kind == "get") {
return new AST_ObjectGetter(args);
}
if (M.kind == "set") {
return new AST_ObjectSetter(args);
}
args.is_generator = M.value.generator;
args.async = M.value.async;
return new AST_ConciseMethod(args);
},
ArrayExpression: function(M) {

@@ -176,3 +301,4 @@ return new AST_Array({

VariableDeclaration: function(M) {
return new (M.kind === "const" ? AST_Const : AST_Var)({
return new (M.kind === "const" ? AST_Const :
M.kind === "let" ? AST_Let : AST_Var)({
start : my_start_token(M),

@@ -183,2 +309,70 @@ end : my_end_token(M),

},
ImportDeclaration: function(M) {
var imported_name = null;
var imported_names = null;
M.specifiers.forEach(function (specifier) {
if (specifier.type === "ImportSpecifier") {
if (!imported_names) { imported_names = []; }
imported_names.push(new AST_NameMapping({
start: my_start_token(specifier),
end: my_end_token(specifier),
foreign_name: from_moz(specifier.imported),
name: from_moz(specifier.local)
}));
} else if (specifier.type === "ImportDefaultSpecifier") {
imported_name = from_moz(specifier.local);
} else if (specifier.type === "ImportNamespaceSpecifier") {
if (!imported_names) { imported_names = []; }
imported_names.push(new AST_NameMapping({
start: my_start_token(specifier),
end: my_end_token(specifier),
foreign_name: new AST_SymbolImportForeign({ name: "*" }),
name: from_moz(specifier.local)
}));
}
});
return new AST_Import({
start : my_start_token(M),
end : my_end_token(M),
imported_name: imported_name,
imported_names : imported_names,
module_name : from_moz(M.source)
})
},
ExportAllDeclaration: function(M) {
return new AST_Export({
start: my_start_token(M),
end: my_end_token(M),
exported_names: [
new AST_NameMapping({
name: new AST_SymbolExportForeign({ name: "*" }),
foreign_name: new AST_SymbolExportForeign({ name: "*" })
})
],
module_name: from_moz(M.source)
});
},
ExportNamedDeclaration: function(M) {
return new AST_Export({
start: my_start_token(M),
end: my_end_token(M),
exported_definition: from_moz(M.declaration),
exported_names: M.specifiers && M.specifiers.length ? M.specifiers.map(function (specifier) {
return new AST_NameMapping({
foreign_name: from_moz(specifier.exported),
name: from_moz(specifier.local)
})
}) : null,
module_name: from_moz(M.source)
});
},
ExportDefaultDeclaration: function(M) {
return new AST_Export({
start: my_start_token(M),
end: my_end_token(M),
exported_value: from_moz(M.declaration),
is_default: true
});
},
Literal: function(M) {

@@ -190,2 +384,14 @@ var val = M.value, args = {

if (val === null) return new AST_Null(args);
var rx = M.regex;
if (rx && rx.pattern) {
// RegExpLiteral as per ESTree AST spec
args.value = new RegExp(rx.pattern, rx.flags).toString();
args.raw = "/" + rx.pattern + "/" + rx.flags;
return new AST_RegExp(args);
} else {
// support legacy RegExp
args.value = M.regex && M.raw ? M.raw : val;
args.raw = M.raw || val;
return new AST_RegExp(args);
}
switch (typeof val) {

@@ -200,20 +406,24 @@ case "string":

return new (val ? AST_True : AST_False)(args);
default:
var rx = M.regex;
if (rx && rx.pattern) {
// RegExpLiteral as per ESTree AST spec
args.value = new RegExp(rx.pattern, rx.flags).toString();
} else {
// support legacy RegExp
args.value = M.regex && M.raw ? M.raw : val;
}
return new AST_RegExp(args);
}
},
MetaProperty: function(M) {
if (M.meta.name === "new" && M.property.name === "target") {
return new AST_NewTarget({
start: my_start_token(M),
end: my_end_token(M)
});
}
},
Identifier: function(M) {
var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
return new ( p.type == "LabeledStatement" ? AST_Label
: p.type == "VariableDeclarator" && p.id === M ? (p.kind == "const" ? AST_SymbolConst : AST_SymbolVar)
: p.type == "VariableDeclarator" && p.id === M ? (p.kind == "const" ? AST_SymbolConst : p.kind == "let" ? AST_SymbolLet : AST_SymbolVar)
: /Import.*Specifier/.test(p.type) ? (p.local === M ? AST_SymbolImport : AST_SymbolImportForeign)
: p.type == "ExportSpecifier" ? (p.local === M ? AST_SymbolExport : AST_SymbolExportForeign)
: p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
: p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
: p.type == "ArrowFunctionExpression" ? (p.params.indexOf(M) !== -1) ? AST_SymbolFunarg : AST_SymbolRef
: p.type == "ClassExpression" ? (p.id === M ? AST_SymbolClass : AST_SymbolRef)
: p.type == "ClassDeclaration" ? (p.id === M ? AST_SymbolDefClass : AST_SymbolRef)
: p.type == "MethodDefinition" ? (p.computed ? AST_SymbolRef : AST_SymbolMethod)
: p.type == "CatchClause" ? AST_SymbolCatch

@@ -241,2 +451,13 @@ : p.type == "BreakStatement" || p.type == "ContinueStatement" ? AST_LabelRef

MOZ_TO_ME.ClassDeclaration =
MOZ_TO_ME.ClassExpression = function From_Moz_Class(M) {
return new AST_Class({
start : my_start_token(M),
end : my_end_token(M),
name : from_moz(M.id),
extends : from_moz(M.superClass),
properties: M.body.body.map(from_moz)
});
};
map("EmptyStatement", AST_EmptyStatement);

@@ -256,2 +477,5 @@ map("BlockStatement", AST_BlockStatement, "body@body");

map("ForInStatement", AST_ForIn, "left>init, right>object, body>body");
map("ForOfStatement", AST_ForOf, "left>init, right>object, body>body");
map("AwaitExpression", AST_Await, "argument>expression");
map("YieldExpression", AST_Yield, "argument>expression, delegate=is_star");
map("DebuggerStatement", AST_Debugger);

@@ -273,2 +497,41 @@ map("VariableDeclarator", AST_VarDef, "id>name, init>value");

def_to_moz(AST_Expansion, function To_Moz_Spread(M, parent) {
return {
type: to_moz_in_destructuring() ? "RestElement" : "SpreadElement",
argument: to_moz(M.expression)
};
});
def_to_moz(AST_PrefixedTemplateString, function To_Moz_TaggedTemplateExpression(M) {
return {
type: "TaggedTemplateExpression",
tag: to_moz(M.prefix),
quasi: to_moz(M.template_string)
};
});
def_to_moz(AST_TemplateString, function To_Moz_TemplateLiteral(M) {
var quasis = [];
var expressions = [];
for (var i = 0; i < M.segments.length; i++) {
if (i % 2 !== 0) {
expressions.push(to_moz(M.segments[i]));
} else {
quasis.push({
type: "TemplateElement",
value: {
raw: M.segments[i].raw,
cooked: M.segments[i].value
},
tail: i === M.segments.length - 1
});
}
}
return {
type: "TemplateLiteral",
quasis: quasis,
expressions: expressions
};
});
def_to_moz(AST_Defun, function To_Moz_FunctionDeclaration(M) {

@@ -279,2 +542,4 @@ return {

params: M.argnames.map(to_moz),
generator: M.is_generator,
async: M.async,
body: to_moz_scope("BlockStatement", M)

@@ -284,3 +549,5 @@ }

def_to_moz(AST_Function, function To_Moz_FunctionExpression(M) {
def_to_moz(AST_Function, function To_Moz_FunctionExpression(M, parent) {
var is_generator = parent.is_generator !== undefined ?
parent.is_generator : M.is_generator
return {

@@ -290,2 +557,4 @@ type: "FunctionExpression",

params: M.argnames.map(to_moz),
generator: is_generator,
async: M.async,
body: to_moz_scope("BlockStatement", M)

@@ -295,2 +564,28 @@ }

def_to_moz(AST_Arrow, function To_Moz_ArrowFunctionExpression(M) {
var body = M.body instanceof Array ? {
type: "BlockStatement",
body: M.body.map(to_moz)
} : to_moz(M.body);
return {
type: "ArrowFunctionExpression",
params: M.argnames.map(to_moz),
async: M.async,
body: body
}
});
def_to_moz(AST_Destructuring, function To_Moz_ObjectPattern(M) {
if (M.is_array) {
return {
type: "ArrayPattern",
elements: M.names.map(to_moz)
}
}
return {
type: "ObjectPattern",
properties: M.names.map(to_moz)
};
});
def_to_moz(AST_Directive, function To_Moz_Directive(M) {

@@ -343,3 +638,5 @@ return {

type: "VariableDeclaration",
kind: M instanceof AST_Const ? "const" : "var",
kind:
M instanceof AST_Const ? "const" :
M instanceof AST_Let ? "let" : "var",
declarations: M.definitions.map(to_moz)

@@ -349,2 +646,58 @@ };

def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) {
if (M.exported_names) {
if (M.exported_names[0].name.name === "*") {
return {
type: "ExportAllDeclaration",
source: to_moz(M.module_name)
};
}
return {
type: "ExportNamedDeclaration",
specifiers: M.exported_names.map(function (name_mapping) {
return {
type: "ExportSpecifier",
exported: to_moz(name_mapping.foreign_name),
local: to_moz(name_mapping.name)
};
}),
declaration: to_moz(M.exported_definition),
source: to_moz(M.module_name)
};
}
return {
type: M.is_default ? "ExportDefaultDeclaration" : "ExportNamedDeclaration",
declaration: to_moz(M.is_default ? M.exported_value : M.exported_definition)
};
});
def_to_moz(AST_Import, function To_Moz_ImportDeclaration(M) {
var specifiers = [];
if (M.imported_name) {
specifiers.push({
type: "ImportDefaultSpecifier",
local: to_moz(M.imported_name)
});
}
if (M.imported_names && M.imported_names[0].foreign_name.name === '*') {
specifiers.push({
type: "ImportNamespaceSpecifier",
local: to_moz(M.imported_names[0].name)
});
} else if (M.imported_names) {
M.imported_names.forEach(function(name_mapping) {
specifiers.push({
type: "ImportSpecifier",
local: to_moz(name_mapping.name),
imported: to_moz(name_mapping.foreign_name)
});
});
}
return {
type: "ImportDeclaration",
specifiers: specifiers,
source: to_moz(M.module_name)
}
});
def_to_moz(AST_Sequence, function To_Moz_SequenceExpression(M) {

@@ -377,2 +730,9 @@ return {

def_to_moz(AST_Binary, function To_Moz_BinaryExpression(M) {
if (to_moz_in_destructuring()) {
return {
type: "AssignmentPattern",
left: to_moz(M.left),
right: to_moz(M.right)
};
}
return {

@@ -400,10 +760,18 @@ type: M.operator == "&&" || M.operator == "||" ? "LogicalExpression" : "BinaryExpression",

def_to_moz(AST_ObjectProperty, function To_Moz_Property(M) {
var key = {
type: "Literal",
value: M.key instanceof AST_SymbolMethod ? M.key.name : M.key
def_to_moz(AST_ObjectProperty, function To_Moz_Property(M, parent) {
var key = M.key instanceof AST_Node ? to_moz(M.key) : {
type: "Identifier",
value: M.key
};
if (typeof M.key === "string") {
key = {
type: "Identifier",
name: M.key
};
}
var kind;
var computed = typeof M.key === "string" ? false : !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef;
if (M instanceof AST_ObjectKeyVal) {
kind = "init";
computed = typeof M.key !== "string";
} else

@@ -416,4 +784,15 @@ if (M instanceof AST_ObjectGetter) {

}
if (parent instanceof AST_Class) {
return {
type: "MethodDefinition",
computed: computed,
kind: kind,
static: M.static,
key: to_moz(M.key),
value: to_moz(M.value)
};
}
return {
type: "Property",
computed: computed,
kind: kind,

@@ -425,3 +804,58 @@ key: key,

def_to_moz(AST_Symbol, function To_Moz_Identifier(M) {
def_to_moz(AST_ConciseMethod, function To_Moz_MethodDefinition(M, parent) {
if (parent instanceof AST_Object) {
return {
type: "Property",
computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
kind: "init",
method: true,
shorthand: false,
key: to_moz(M.key),
value: to_moz(M.value)
};
}
return {
type: "MethodDefinition",
computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef,
kind: M.key === "constructor" ? "constructor" : "method",
static: M.static,
key: to_moz(M.key),
value: to_moz(M.value)
};
});
def_to_moz(AST_Class, function To_Moz_Class(M) {
var type = M instanceof AST_ClassExpression ? "ClassExpression" : "ClassDeclaration";
return {
type: type,
superClass: to_moz(M.extends),
id: M.name ? to_moz(M.name) : null,
body: {
type: "ClassBody",
body: M.properties.map(to_moz)
}
}
});
def_to_moz(AST_NewTarget, function To_Moz_MetaProperty(M) {
return {
type: "MetaProperty",
meta: {
type: "Identifier",
name: "new"
},
property: {
type: "Identifier",
name: "target"
}
};
});
def_to_moz(AST_Symbol, function To_Moz_Identifier(M, parent) {
if (M instanceof AST_SymbolMethod && parent.quote) {
return {
type: "Literal",
value: M.name
};
}
var def = M.definition();

@@ -435,10 +869,10 @@ return {

def_to_moz(AST_RegExp, function To_Moz_RegExpLiteral(M) {
var value = M.value;
var value = M.raw;
return {
type: "Literal",
value: value,
raw: value.toString(),
raw: value,
regex: {
pattern: value.source,
flags: value.toString().match(/[gimuy]*$/)[0]
pattern: value.replace(/(^\/|\/[gimuy]*$)/g, ""),
flags: value.match(/[gimuy]*$/)[0]
}

@@ -612,11 +1046,28 @@ };

function def_to_moz(mytype, handler) {
mytype.DEFMETHOD("to_mozilla_ast", function() {
return set_moz_loc(this, handler(this));
mytype.DEFMETHOD("to_mozilla_ast", function(parent) {
return set_moz_loc(this, handler(this, parent));
});
};
var TO_MOZ_STACK = null;
function to_moz(node) {
return node != null ? node.to_mozilla_ast() : null;
if (TO_MOZ_STACK === null) { TO_MOZ_STACK = []; }
TO_MOZ_STACK.push(node);
var ast = node != null ? node.to_mozilla_ast(TO_MOZ_STACK[TO_MOZ_STACK.length - 2]) : null;
TO_MOZ_STACK.pop();
if (TO_MOZ_STACK.length === 0) { TO_MOZ_STACK = null; }
return ast
};
function to_moz_in_destructuring() {
var i = TO_MOZ_STACK.length;
while (i--) {
if (TO_MOZ_STACK[i] instanceof AST_Destructuring) {
return true;
}
}
return false;
};
function to_moz_block(node) {

@@ -623,0 +1074,0 @@ return {

@@ -517,5 +517,9 @@ /***********************************************************************

keep_fnames : false,
module : false,
reserved : [],
toplevel : false,
});
if (options["module"]) {
options.toplevel = true;
}
if (!Array.isArray(options.reserved)) options.reserved = [];

@@ -522,0 +526,0 @@ // Never mangle arguments

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

"license": "BSD-2-Clause",
"version": "3.3.11",
"version": "3.4.0",
"engines": {

@@ -33,2 +33,3 @@ "node": ">=0.8.0"

"acorn": "~5.4.1",
"escodegen": "^1.9.1",
"mocha": "~3.5.1",

@@ -35,0 +36,0 @@ "semver": "~5.5.0"

@@ -113,2 +113,4 @@ uglify-es

code relying on Function.prototype.name.
--module Input is an ES6 module. If `compress` or `mangle` is
enabled then the `toplevel` option will be enabled.
--name-cache <file> File to hold mangled name mappings.

@@ -500,2 +502,6 @@ --safari10 Support non-standard Safari 10/11.

- `module` (default `false`) — Use when minifying an ES6 module. "use strict"
is implied and names can be mangled on the top scope. If `compress` or
`mangle` is enabled then the `toplevel` option will be enabled.
- `output` (default `null`) — pass an object if you wish to specify

@@ -559,2 +565,3 @@ additional [output options](#output-options). The defaults are optimized

ie8: false,
module: false,
nameCache: null, // or specify a name cache object

@@ -708,2 +715,5 @@ safari10: false,

- `module` (default `false`) -- Pass `true` when compressing an ES6 module. Strict
mode is implied and the `toplevel` option as well.
- `negate_iife` (default: `true`) -- negate "Immediately-Called Function Expressions"

@@ -830,2 +840,5 @@ where the return value is discarded, to avoid the parens that the

- `module` (default `false`) -- Pass `true` an ES6 modules, where the toplevel
scope is not the global scope. Implies `toplevel`.
- `reserved` (default `[]`) -- Pass an array of identifiers that should be

@@ -832,0 +845,0 @@ excluded from mangling. Example: `["foo", "bar"]`.

Sorry, the diff of this file is not supported yet

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