Socket
Socket
Sign inDemoInstall

uglify-js-harmony

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uglify-js-harmony - npm Package Compare versions

Comparing version 2.6.2 to 2.7.5

233

lib/ast.js

@@ -74,3 +74,3 @@ /***********************************************************************

}
if (methods) for (i in methods) if (methods.hasOwnProperty(i)) {
if (methods) for (i in methods) if (HOP(methods, i)) {
if (/^\$/.test(i)) {

@@ -298,2 +298,9 @@ ctor[i.substr(1)] = methods[i];

},
get_defun_scope: function () {
var self = this;
while (self.is_block_scope() && self.parent_scope) {
self = self.parent_scope;
}
return self;
}
}, AST_Block);

@@ -368,6 +375,6 @@

var AST_Expansion = DEFNODE("Expansion", "symbol", {
var AST_Expansion = DEFNODE("Expansion", "expression", {
$documentation: "An expandible argument, such as ...rest, a splat, such as [1,2,...all], or an expansion in a variable declaration, such as var [first, ...rest] = list",
$propdoc: {
symbol: "AST_Symbol the thing to be expanded"
expression: "AST_Symbol the thing to be expanded"
},

@@ -377,3 +384,3 @@ _walk: function(visitor) {

return visitor._visit(this, function(){
self.symbol.walk(visitor);
self.expression.walk(visitor);
});

@@ -393,4 +400,2 @@ }

if (ex instanceof AST_Object) {
if (ex.properties.length == 0)
croak("Invalid destructuring function parameter", ex.start.line, ex.start.col);
return new AST_Destructuring({

@@ -403,8 +408,10 @@ start: ex.start,

});
} else if (ex instanceof AST_ObjectSymbol) {
return new AST_SymbolFunarg({
name: ex.symbol.name,
start: ex.start,
end: ex.end
});
} else if (ex instanceof AST_ObjectKeyVal) {
if (ex.key instanceof AST_SymbolRef) {
ex.key = to_fun_args(ex.key, 0, [ex.key], ex.default);
}
ex.value = to_fun_args(ex.value, 0, [ex.key], ex.default);
return ex;
} else if (ex instanceof AST_Hole) {
return ex;
} else if (ex instanceof AST_Destructuring) {

@@ -425,4 +432,2 @@ if (ex.names.length == 0)

} else if (ex instanceof AST_Array) {
if (ex.elements.length === 0)
croak("Invalid destructuring function parameter", ex.start.line, ex.start.col);
return new AST_Destructuring({

@@ -447,5 +452,6 @@ start: ex.start,

var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments", {
var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments is_generator", {
$documentation: "Base class for functions",
$propdoc: {
is_generator: "[boolean] is generatorFn or not",
name: "[AST_SymbolDeclaration?] the name of this function",

@@ -489,9 +495,2 @@ argnames: "[AST_SymbolFunarg|AST_Destructuring|AST_Expansion*] array of function arguments, destructurings, or expanding arguments",

var AST_ConciseMethod = DEFNODE("ConciseMethod", "static", {
$propdoc: {
static: "[boolean] whether this method is static (classes only)",
},
$documentation: "An ES6 concise method inside an object or class"
}, AST_Lambda);
var AST_Defun = DEFNODE("Defun", null, {

@@ -504,2 +503,7 @@ $documentation: "A function definition"

$documentation: "A destructuring of several names. Used in destructuring assignment and with destructuring function argument names",
$propdoc: {
"names": "[AST_Destructuring|AST_Expansion|AST_Hole|AST_ObjectKeyVal|AST_Symbol] Array of properties or elements",
"is_array": "[Boolean] Whether the destructuring represents an object or array",
"default": "[AST_Node?] Default assign value"
},
_walk: function(visitor) {

@@ -519,3 +523,3 @@ return visitor._visit(this, function(){

if (node instanceof AST_Expansion) {
out.push(node.symbol);
out.push(node.expression);
}

@@ -542,3 +546,3 @@ }));

$propdoc: {
segments: "[string|AST_Expression]* One or more segments. They can be the parts that are evaluated, or the raw string parts."
segments: "[AST_TemplateSegment|AST_Expression]* One or more segments, starting with AST_TemplateSegment. AST_Expression may follow AST_TemplateSegment, but each AST_Expression must be followed by AST_TemplateSegment."
},

@@ -556,2 +560,10 @@ _walk: function(visitor) {

var AST_TemplateSegment = DEFNODE("TemplateSegment", "value raw", {
$documentation: "A segment of a template string literal",
$propdoc: {
value: "Content of the segment",
raw: "Raw content of the segment"
}
});
/* -----[ JUMPS ]----- */

@@ -718,2 +730,57 @@

var AST_NameImport = DEFNODE("NameImport", "foreign_name name", {
$documentation: "The part of the import statement that imports names from a module.",
$propdoc: {
foreign_name: "[AST_SymbolImportForeign] The name being imported (as specified in the module)",
name: "[AST_SymbolImport] The name as it becomes available to this module."
},
_walk: function (visitor) {
return visitor._visit(this, function() {
this.foreign_name._walk(visitor);
this.name._walk(visitor);
});
}
})
var AST_Import = DEFNODE("Import", "imported_name imported_names module_name", {
$documentation: "An `import` statement",
$propdoc: {
imported_name: "[AST_SymbolImport] The name of the variable holding the module's default export.",
imported_names: "[AST_NameImport*] The names of non-default imported variables",
module_name: "[AST_String] String literal describing where this module came from",
},
_walk: function(visitor) {
return visitor._visit(this, function() {
if (this.imported_name) {
this.imported_name._walk(visitor);
}
if (this.imported_names) {
this.imported_names.forEach(function (name_import) {
name_import._walk(visitor);
});
}
this.module_name._walk(visitor);
});
}
});
var AST_Export = DEFNODE("Export", "exported_definition exported_value is_default", {
$documentation: "An `export` statement",
$propdoc: {
exported_definition: "[AST_Defun|AST_Definitions|AST_DefClass?] An exported definition",
exported_value: "[AST_Node?] An exported value",
is_default: "[Boolean] Whether this is the default exported value of this module"
},
_walk: function (visitor) {
visitor._visit(this, function () {
if (this.exported_definition) {
this.exported_definition._walk(visitor);
}
if (this.exported_value) {
this.exported_value._walk(visitor);
}
});
}
}, AST_Statement);
var AST_VarDef = DEFNODE("VarDef", "name value", {

@@ -809,2 +876,9 @@ $documentation: "A variable declaration; only appears in a AST_Definitions node",

},
len: function() {
if (this.cdr instanceof AST_Seq) {
return this.cdr.len() + 1;
} else {
return 2;
}
},
_walk: function(visitor) {

@@ -934,7 +1008,10 @@ return visitor._visit(this, function(){

$propdoc: {
key: "[string] the property name converted to a string for ObjectKeyVal. For setters and getters this is an arbitrary AST_Node.",
value: "[AST_Node] property value. For setters and getters this is an AST_Function."
key: "[string|AST_Node] the property name converted to a string for ObjectKeyVal. For setters, getters and computed property this is an arbitrary AST_Node",
value: "[AST_Node] property value. For setters and getters this is an AST_Function.",
default: "[AST_Expression] The default for this parameter, only used when nested inside a binding pattern"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
if (this.key instanceof AST_Node)
this.key._walk(visitor);
this.value._walk(visitor);

@@ -945,33 +1022,13 @@ });

var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", {
var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote default", {
$documentation: "A key: value object property",
$propdoc: {
quote: "[string] the original quote character"
quote: "[string] the original quote character",
default: "[AST_Expression] The default parameter value, only used when nested inside a binding pattern"
}
}, AST_ObjectProperty);
var AST_ObjectComputedKeyVal = DEFNODE("ObjectComputedKeyVal", null, {
$documentation: "An object property whose key is computed. Like `[Symbol.iterator]: function...` or `[routes.homepage]: renderHomepage`",
_walk: function(visitor) {
return visitor._visit(this, function(){
this.key._walk(visitor);
this.value._walk(visitor);
});
}
}, AST_ObjectProperty);
var AST_ObjectSymbol = DEFNODE("ObjectSymbol", "symbol", {
var AST_ObjectSetter = DEFNODE("ObjectSetter", "quote static", {
$propdoc: {
symbol: "[AST_SymbolRef] what symbol it is"
},
$documentation: "A symbol in an object",
_walk: function (visitor) {
return visitor._visit(this, function(){
this.symbol._walk(visitor);
});
}
}, AST_ObjectProperty);
var AST_ObjectSetter = DEFNODE("ObjectSetter", "static", {
$propdoc: {
quote: "[string|undefined] the original quote character, if any",
static: "[boolean] whether this is a static setter (classes only)"

@@ -982,4 +1039,5 @@ },

var AST_ObjectGetter = DEFNODE("ObjectGetter", "static", {
var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", {
$propdoc: {
quote: "[string|undefined] the original quote character, if any",
static: "[boolean] whether this is a static getter (classes only)"

@@ -990,2 +1048,11 @@ },

var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator", {
$propdoc: {
quote: "[string|undefined] the original quote character, if any",
static: "[boolean] whether this method is static (classes only)",
is_generator: "[boolean] is generatorFn or not",
},
$documentation: "An ES6 concise method inside an object or class"
}, AST_ObjectProperty);
var AST_Class = DEFNODE("Class", "name extends properties", {

@@ -1021,9 +1088,15 @@ $propdoc: {

var AST_Symbol = DEFNODE("Symbol", "scope name thedef", {
var AST_Symbol = DEFNODE("Symbol", "scope name thedef default", {
$propdoc: {
name: "[string] name of this symbol",
scope: "[AST_Scope/S] the current scope (not necessarily the definition scope)",
thedef: "[SymbolDef/S] the definition of this symbol"
thedef: "[SymbolDef/S] the definition of this symbol",
default: "[AST_Expression] The default parameter value, only used when nested inside a binding pattern"
},
$documentation: "Base class for all symbols",
_walk: function (visitor) {
return visitor._visit(this, function() {
if (this.default) this.default._walk(visitor);
});
}
});

@@ -1039,13 +1112,7 @@

var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init default", {
var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", {
$documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)",
$propdoc: {
init: "[AST_Node*/S] array of initializers for this declaration.",
default: "[AST_Expression] The default for this parameter. For example, `= 6`"
init: "[AST_Node*/S] array of initializers for this declaration."
},
_walk: function (visitor) {
return visitor._visit(this, function() {
if (this.default) this.default._walk(visitor);
});
}
}, AST_Symbol);

@@ -1057,6 +1124,14 @@

var AST_SymbolBlockDeclaration = DEFNODE("SymbolBlockDeclaration", null, {
$documentation: "Base class for block-scoped declaration symbols"
}, AST_SymbolDeclaration);
var AST_SymbolConst = DEFNODE("SymbolConst", null, {
$documentation: "A constant declaration"
}, AST_SymbolDeclaration);
}, AST_SymbolBlockDeclaration);
var AST_SymbolLet = DEFNODE("SymbolLet", null, {
$documentation: "A block-scoped `let` declaration"
}, AST_SymbolBlockDeclaration);
var AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, {

@@ -1080,3 +1155,3 @@ $documentation: "Symbol naming a function argument",

$documentation: "Symbol naming a class's name in a class declaration. Lexically scoped to its containing scope, and accessible within the class."
}, AST_SymbolDeclaration);
}, AST_SymbolBlockDeclaration);

@@ -1089,4 +1164,12 @@ var AST_SymbolClass = DEFNODE("SymbolClass", null, {

$documentation: "Symbol naming the exception in catch",
}, AST_SymbolDeclaration);
}, AST_SymbolBlockDeclaration);
var AST_SymbolImport = DEFNODE("SymbolImport", null, {
$documentation: "Symbol refering to an imported name",
}, AST_SymbolBlockDeclaration);
var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", null, {
$documentation: "A symbol imported from a module, but it is defined in the other module, and its real name is irrelevant for this module's purposes",
}, AST_Symbol);
var AST_Label = DEFNODE("Label", "references", {

@@ -1192,2 +1275,17 @@ $documentation: "Symbol naming a label (declaration)",

/* -----[ Yield ]----- */
var AST_Yield = DEFNODE("Yield", "expression is_star", {
$documentation: "A `yield` statement",
$propdoc: {
expression: "[AST_Node?] the value returned or thrown by this statement; could be null (representing undefined) but only when is_star is set to false",
is_star: "[Boolean] Whether this is a yield or yield* statement"
},
_walk: function(visitor) {
return visitor._visit(this, this.expression && function(){
this.expression._walk(visitor);
});
}
});
/* -----[ TreeWalker ]----- */

@@ -1220,2 +1318,5 @@

this.directives[node.value] = this.directives[node.value] ? "up" : true;
} else if (node instanceof AST_Class) {
this.directives = Object.create(this.directives);
this.directives["use strict"] = this.directives["use strict"] ? "up" : true;
}

@@ -1226,3 +1327,3 @@ this.stack.push(node);

this.stack.pop();
if (node instanceof AST_Lambda) {
if (node instanceof AST_Lambda || node instanceof AST_Class) {
this.directives = Object.getPrototypeOf(this.directives);

@@ -1229,0 +1330,0 @@ }

@@ -48,16 +48,51 @@ /***********************************************************************

var normalize_directives = function(body) {
var in_directive = true;
for (var i = 0; i < body.length; i++) {
if (in_directive && body[i] instanceof AST_Statement && body[i].body instanceof AST_String) {
body[i] = new AST_Directive({
start: body[i].start,
end: body[i].end,
value: body[i].body.value
});
} else if (in_directive && !(body[i] instanceof AST_Statement && body[i].body instanceof AST_String)) {
in_directive = false;
}
}
return body;
};
var MOZ_TO_ME = {
Program: function(M) {
return new AST_Toplevel({
start: my_start_token(M),
end: my_end_token(M),
body: normalize_directives(M.body.map(from_moz))
});
},
FunctionDeclaration: function(M) {
return new AST_Defun({
start: my_start_token(M),
end: my_end_token(M),
name: from_moz(M.id),
argnames: M.params.map(from_moz),
body: normalize_directives(from_moz(M.body).body)
});
},
FunctionExpression: function(M) {
return new AST_Function({
start: my_start_token(M),
end: my_end_token(M),
name: from_moz(M.id),
argnames: M.params.map(from_moz),
body: normalize_directives(from_moz(M.body).body)
});
},
ExpressionStatement: function(M) {
var expr = M.expression;
if (expr.type === "Literal" && typeof expr.value === "string") {
return new AST_Directive({
start: my_start_token(M),
end: my_end_token(M),
value: expr.value
});
}
return new AST_SimpleStatement({
start: my_start_token(M),
end: my_end_token(M),
body: from_moz(expr)
body: from_moz(M.expression)
});

@@ -98,2 +133,11 @@ },

},
ArrayExpression: function(M) {
return new AST_Array({
start : my_start_token(M),
end : my_end_token(M),
elements : M.elements.map(function(elem){
return elem === null ? new AST_Hole() : from_moz(elem);
})
});
},
ObjectExpression: function(M) {

@@ -190,3 +234,2 @@ return new AST_Object({

map("Program", AST_Toplevel, "body@body");
map("EmptyStatement", AST_EmptyStatement);

@@ -207,3 +250,2 @@ map("BlockStatement", AST_BlockStatement, "body@body");

map("DebuggerStatement", AST_Debugger);
map("FunctionDeclaration", AST_Defun, "id>name, params@argnames, body%body");
map("VariableDeclarator", AST_VarDef, "id>name, init>value");

@@ -213,4 +255,2 @@ map("CatchClause", AST_Catch, "param>argname, body%body");

map("ThisExpression", AST_This);
map("ArrayExpression", AST_Array, "elements@elements");
map("FunctionExpression", AST_Function, "id>name, params@argnames, body%body");
map("BinaryExpression", AST_Binary, "operator=operator, left>left, right>right");

@@ -223,2 +263,27 @@ map("LogicalExpression", AST_Binary, "operator=operator, left>left, right>right");

def_to_moz(AST_Toplevel, function To_Moz_Program(M) {
return {
type: "Program",
body: M.body.map(to_moz)
};
});
def_to_moz(AST_Defun, function To_Moz_FunctionDeclaration(M) {
return {
type: "FunctionDeclaration",
id: to_moz(M.name),
params: M.argnames.map(to_moz),
body: to_moz_block(M)
}
});
def_to_moz(AST_Function, function To_Moz_FunctionExpression(M) {
return {
type: "FunctionExpression",
id: to_moz(M.name),
params: M.argnames.map(to_moz),
body: to_moz_block(M)
}
});
def_to_moz(AST_Directive, function To_Moz_Directive(M) {

@@ -311,2 +376,9 @@ return {

def_to_moz(AST_Array, function To_Moz_ArrayExpression(M) {
return {
type: "ArrayExpression",
elements: M.elements.map(to_moz)
};
});
def_to_moz(AST_Object, function To_Moz_ObjectExpression(M) {

@@ -313,0 +385,0 @@ return {

@@ -46,2 +46,18 @@ /***********************************************************************

var EXPECT_DIRECTIVE = /^$|[;{][\s\n]*$/;
function is_some_comments(comment) {
var text = comment.value;
var type = comment.type;
if (type == "comment2") {
// multiline comment
return /@preserve|@license|@cc_on/i.test(text);
}
return type == "comment5";
}
function is_comment5(comment) {
return comment.type == "comment5";
}
function OutputStream(options) {

@@ -55,2 +71,3 @@

ascii_only : false,
ascii_identifiers: undefined,
unescape_regexps : false,

@@ -67,7 +84,45 @@ inline_script : false,

preserve_line : false,
screw_ie8 : false,
screw_ie8 : true,
preamble : null,
quote_style : 0
quote_style : 0,
keep_quoted_props: false,
shorthand : undefined,
ecma : 5,
wrap_iife : false,
}, true);
if (typeof options.ascii_identifiers === 'undefined')
options.ascii_identifiers = options.ascii_only;
if (options.shorthand === undefined)
options.shorthand = options.ecma > 5;
// Convert comment option to RegExp if neccessary and set up comments filter
var comment_filter = options.shebang ? is_comment5 : return_false; // Default case, throw all comments away except shebangs
if (options.comments) {
var comments = options.comments;
if (typeof options.comments === "string" && /^\/.*\/[a-zA-Z]*$/.test(options.comments)) {
var regex_pos = options.comments.lastIndexOf("/");
comments = new RegExp(
options.comments.substr(1, regex_pos - 1),
options.comments.substr(regex_pos + 1)
);
}
if (comments instanceof RegExp) {
comment_filter = function(comment) {
return comment.type == "comment5" || comments.test(comment.value);
};
}
else if (typeof comments === "function") {
comment_filter = function(comment) {
return comment.type == "comment5" || comments(this, comment);
};
}
else if (comments === "some") {
comment_filter = is_some_comments;
} else { // NOTE includes "all" option
comment_filter = return_true;
}
}
var indentation = 0;

@@ -80,5 +135,15 @@ var current_col = 0;

function to_ascii(str, identifier) {
return str.replace(/[\u0080-\uffff]/g, function(ch) {
var code = ch.charCodeAt(0).toString(16);
if (code.length <= 2 && !identifier) {
return str.replace(/[\ud800-\udbff][\udc00-\udfff]|[\u0000-\u001f\u007f-\uffff]/g, function(ch) {
var code = get_full_char_code(ch, 0).toString(16);
if ((identifier && code.length === 1 && options.ecma >= 6) || code.length > 4) {
if (options.ecma < 6) {
if (identifier) {
return ch; // no \u{} support
}
return "\\u" + ch.charCodeAt(0).toString(16) + "\\u"
+ ch.charCodeAt(1).toString(16);
}
return "\\u{" + code + "}";
} else if (code.length <= 2 && !identifier) {
while (code.length < 2) code = "0" + code;

@@ -95,16 +160,19 @@ return "\\x" + code;

var dq = 0, sq = 0;
str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g, function(s){
str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g,
function(s, i){
switch (s) {
case '"': ++dq; return '"';
case "'": ++sq; return "'";
case "\\": return "\\\\";
case "\n": return "\\n";
case "\r": return "\\r";
case "\t": return "\\t";
case "\b": return "\\b";
case "\f": return "\\f";
case "\n": return "\\n";
case "\r": return "\\r";
case "\x0B": return options.screw_ie8 ? "\\v" : "\\x0B";
case "\u2028": return "\\u2028";
case "\u2029": return "\\u2029";
case '"': ++dq; return '"';
case "'": ++sq; return "'";
case "\0": return "\\x00";
case "\ufeff": return "\\ufeff";
case "\0":
return /[0-7]/.test(get_full_char(str, i+1)) ? "\\x00" : "\\0";
}

@@ -119,3 +187,18 @@ return s;

}
function quote_template() {
if (!options.ascii_only) {
str = str.replace(/\\(n|r|u2028|u2029)/g, function(s, c) {
switch(c) {
case "n": return "\n";
case "r": return "\r";
case "u2028": return "\u2028";
case "u2029": return "\u2029";
}
return s;
});
}
return '`' + str.replace(/`/g, '\\`') + '`';
}
if (options.ascii_only) str = to_ascii(str);
if (quote === "`") return quote_template();
switch (options.quote_style) {

@@ -145,3 +228,3 @@ case 1:

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

@@ -162,3 +245,9 @@ return name;

function last_char() {
return last.charAt(last.length - 1);
var char = last.charAt(last.length - 1);
if (is_surrogate_pair_tail(char)) {
return last.charAt(last.length - 2) + char;
}
return char;
};

@@ -175,3 +264,3 @@

str = String(str);
var ch = str.charAt(0);
var ch = get_full_char(str, 0);
if (might_need_semicolon) {

@@ -238,2 +327,6 @@ might_need_semicolon = false;

var star = function(){
print("*");
}
var space = options.beautify ? function() {

@@ -356,2 +449,3 @@ print(" ");

print : print,
star : star,
space : space,

@@ -365,3 +459,18 @@ comma : comma,

print_name : function(name) { print(make_name(name)) },
print_string : function(str, quote) { print(encode_string(str, quote)) },
print_string : function(str, quote, escape_directive) {
var encoded = encode_string(str, quote);
if (escape_directive === true && encoded.indexOf("\\") === -1) {
// Insert semicolons to break directive prologue
if (!EXPECT_DIRECTIVE.test(OUTPUT)) {
force_semicolon();
}
force_semicolon();
}
print(encoded);
},
print_template_string_chars: function(str) {
var encoded = encode_string(str, '`').replace(/\${/g, "\\${");
return print(encoded.substr(1, encoded.length - 2));
},
encode_string : encode_string,
next_indent : next_indent,

@@ -374,2 +483,3 @@ with_indent : with_indent,

option : function(opt) { return options[opt] },
comment_filter : comment_filter,
line : function() { return current_line },

@@ -399,6 +509,7 @@ col : function() { return current_col },

var use_asm = false;
var in_directive = false;
AST_Node.DEFMETHOD("print", function(stream, force_parens){
var self = this, generator = self._codegen, prev_use_asm = use_asm;
if (self instanceof AST_Directive && self.value == "use asm") {
if (self instanceof AST_Directive && self.value == "use asm" && stream.parent() instanceof AST_Scope) {
use_asm = true;

@@ -418,3 +529,3 @@ }

stream.pop_node();
if (self instanceof AST_Lambda) {
if (self instanceof AST_Scope) {
use_asm = prev_use_asm;

@@ -426,2 +537,3 @@ }

var s = OutputStream(options);
if (!options) s._readonly = true;
this.print(s);

@@ -434,3 +546,4 @@ return s.get();

AST_Node.DEFMETHOD("add_comments", function(output){
var c = output.option("comments"), self = this;
if (output._readonly) return;
var self = this;
var start = self.start;

@@ -458,15 +571,3 @@ if (start && !start._comments_dumped) {

if (!c) {
comments = comments.filter(function(comment) {
return comment.type == "comment5";
});
} else if (c.test) {
comments = comments.filter(function(comment){
return c.test(comment.value) || comment.type == "comment5";
});
} else if (typeof c == "function") {
comments = comments.filter(function(comment){
return c(self, comment) || comment.type == "comment5";
});
}
comments = comments.filter(output.comment_filter, self);

@@ -522,3 +623,12 @@ // Keep single line comments after nlb, after nlb

PARENS(AST_Function, function(output){
return first_in_statement(output);
if (first_in_statement(output)) {
return true;
}
if (output.option('wrap_iife')) {
var p = output.parent();
return p instanceof AST_Call && p.expression === this;
}
return false;
});

@@ -534,3 +644,10 @@

var p = output.parent();
return p instanceof AST_PropAccess && p.expression === this;
return p instanceof AST_PropAccess && p.expression === this
|| p instanceof AST_Call && p.expression === this
|| p instanceof AST_Binary
&& p.operator === "**"
&& this instanceof AST_UnaryPrefix
&& p.left === this
&& this.operator !== "++"
&& this.operator !== "--";
});

@@ -547,4 +664,9 @@

|| p instanceof AST_ObjectProperty // { foo: (1, 2) }.foo ==> 2
|| (p instanceof AST_SymbolConst && p.default === this) // const { xCover = (0, function() {}) }
|| (p instanceof AST_SymbolLet && p.default === this) // let { xCover = (0, function() {}) }
|| (p instanceof AST_SymbolVar && p.default === this) // var { xCover = (0, function() {}) }
|| (p instanceof AST_SymbolCatch && p.default === this) // } catch (xCover = (0, function() {}) ) {
|| p instanceof AST_Conditional /* (false, true) ? (a = 10, b = 20) : (c = 30)
* ==> 20 (side effect, set a := 10 and b := 20) */
|| p instanceof AST_Arrow // x => (x, x)
;

@@ -576,2 +698,22 @@ });

PARENS(AST_Yield, function(output){
var p = output.parent();
// (yield 1) + (yield 2)
// a = yield 3
if (p instanceof AST_Binary && p.operator !== "=")
return true;
// (yield 1) ? yield 2 : yield 3
if (p instanceof AST_Conditional && p.condition === this)
return true;
// -(yield 4)
if (p instanceof AST_Unary)
return true;
// (yield x).foo
if (p instanceof AST_Dot && p.expression === this)
return true;
// (yield x)['foo']
if (p instanceof AST_Sub && p.expression === this)
return true;
});
PARENS(AST_PropAccess, function(output){

@@ -613,3 +755,3 @@ var p = output.parent();

var p = output.parent();
if (no_constructor_parens(this, output)
if (!need_constructor_parens(this, output)
&& (p instanceof AST_PropAccess // (new Date).getTime(), (new Date)["getTime"]()

@@ -622,4 +764,8 @@ || p instanceof AST_Call && p.expression === this)) // (new foo)(bar)

var p = output.parent();
if (this.getValue() < 0 && p instanceof AST_PropAccess && p.expression === this)
return true;
if (p instanceof AST_PropAccess && p.expression === this) {
var value = this.getValue();
if (value < 0 || /^0/.test(make_num(value))) {
return true;
}
}
});

@@ -655,3 +801,3 @@

output.print('...');
self.symbol.print(output);
self.expression.print(output);
});

@@ -662,5 +808,11 @@

var first = true;
self.names.forEach(function (name) {
var len = self.names.length;
self.names.forEach(function (name, i) {
if (first) first = false; else { output.comma(); output.space(); }
name.print(output);
// If the final element is a hole, we need to make sure it
// doesn't look like a trailing comma, by inserting an actual
// trailing comma.
if (i === len - 1 && name instanceof AST_Hole)
output.comma();
})

@@ -674,3 +826,3 @@ output.print(self.is_array ? "]" : "}");

}
})
});

@@ -684,5 +836,12 @@ DEFPRINT(AST_Debugger, function(self, output){

function display_body(body, is_toplevel, output) {
function display_body(body, is_toplevel, output, allow_directives) {
var last = body.length - 1;
in_directive = allow_directives;
body.forEach(function(stmt, i){
if (in_directive === true && !(stmt instanceof AST_Directive ||
stmt instanceof AST_EmptyStatement ||
(stmt instanceof AST_SimpleStatement && stmt.body instanceof AST_String)
)) {
in_directive = false;
}
if (!(stmt instanceof AST_EmptyStatement)) {

@@ -696,3 +855,10 @@ output.indent();

}
if (in_directive === true &&
stmt instanceof AST_SimpleStatement &&
stmt.body instanceof AST_String
) {
in_directive = false;
}
});
in_directive = false;
};

@@ -709,3 +875,3 @@

DEFPRINT(AST_Toplevel, function(self, output){
display_body(self.body, true, output);
display_body(self.body, true, output, true);
output.print("");

@@ -722,5 +888,5 @@ });

});
function print_bracketed(body, output) {
function print_bracketed(body, output, allow_directives) {
if (body.length > 0) output.with_block(function(){
display_body(body, false, output);
display_body(body, false, output, allow_directives);
});

@@ -817,2 +983,5 @@ else output.print("{}");

output.print("function");
if (this.is_generator) {
output.star();
}
if (self.name) {

@@ -822,4 +991,8 @@ output.space();

}
if (self.name) {
if (self.name instanceof AST_Symbol) {
self.name.print(output);
} else if (nokeyword && self.name instanceof AST_Node) {
output.with_square(function() {
self.name.print(output); // Computed method name
});
}

@@ -833,3 +1006,3 @@ output.with_parens(function(){

output.space();
print_bracketed(self.body, output);
print_bracketed(self.body, output, true);
});

@@ -845,10 +1018,14 @@ DEFPRINT(AST_Lambda, function(self, output){

DEFPRINT(AST_TemplateString, function(self, output) {
var is_tagged = output.parent() instanceof AST_PrefixedTemplateString;
output.print("`");
for (var i = 0; i < self.segments.length; i++) {
if (typeof self.segments[i] !== "string") {
if (!(self.segments[i] instanceof AST_TemplateSegment)) {
output.print("${");
self.segments[i].print(output);
output.print("}");
} else if (is_tagged) {
output.print(self.segments[i].raw);
} else {
output.print(self.segments[i]);
output.print_template_string_chars(self.segments[i].value);
}

@@ -864,5 +1041,5 @@ }

parent instanceof AST_Unary ||
parent instanceof AST_Call;
(parent instanceof AST_Call && self === parent.expression);
if (needs_parens) { output.print("(") }
if (self.argnames.length === 1 && self.argnames[0] instanceof AST_Symbol) {
if (self.argnames.length === 1 && self.argnames[0] instanceof AST_Symbol && !self.argnames[0].default) {
self.argnames[0].print(output);

@@ -887,9 +1064,2 @@ } else {

});
DEFPRINT(AST_ConciseMethod, function(self, output){
if (self.static) {
output.print("static");
output.space();
}
self._do_print(output, true /* do not print "function" */);
});

@@ -912,2 +1082,13 @@ /* -----[ exits ]----- */

/* -----[ yield ]----- */
DEFPRINT(AST_Yield, function(self, output){
var star = self.is_star ? "*" : "";
output.print("yield" + star);
if (self.expression) {
output.space();
self.expression.print(output);
}
});
/* -----[ loop control ]----- */

@@ -944,4 +1125,4 @@ AST_LoopControl.DEFMETHOD("_do_print", function(output, kind){

return output.force_semicolon();
if (self.body instanceof AST_Do
&& !output.option("screw_ie8")) {
if (self.body instanceof AST_Do) {
// Unconditionally use the if/do-while workaround for all browsers.
// https://github.com/mishoo/UglifyJS/issues/#issue/57 IE

@@ -1079,3 +1260,65 @@ // croaks with "syntax error" on code like this: if (foo)

});
DEFPRINT(AST_Import, function(self, output) {
output.print("import");
output.space();
if (self.imported_name) {
self.imported_name.print(output);
}
if (self.imported_name && self.imported_names) {
output.print(",");
output.space();
}
if (self.imported_names) {
output.print("{");
self.imported_names.forEach(function(name_import, i) {
output.space();
name_import.print(output);
if (i < self.imported_names.length - 1) {
output.print(",");
output.space();
}
});
output.space();
output.print("}");
}
if (self.imported_name || self.imported_names) {
output.space();
output.print("from")
output.space();
}
self.module_name.print(output);
output.semicolon();
});
DEFPRINT(AST_NameImport, function(self, output) {
var definition = self.name.definition();
var names_are_different =
(definition && definition.mangled_name || self.name.name) !==
self.foreign_name.name;
if (names_are_different) {
output.print(self.foreign_name.name);
output.space();
output.print("as");
output.space();
self.name.print(output);
} else {
self.name.print(output);
}
});
DEFPRINT(AST_Export, function(self, output) {
output.print("export");
output.space();
if (self.is_default) {
output.print("default");
output.space();
}
if (self.exported_value) {
self.exported_value.print(output);
} else if (self.exported_definition) {
self.exported_definition.print(output);
}
output.semicolon();
});
function parenthesize_for_noin(node, output, noin) {

@@ -1112,3 +1355,3 @@ if (!noin) node.print(output);

self.expression.print(output);
if (self instanceof AST_New && no_constructor_parens(self, output))
if (self instanceof AST_New && !need_constructor_parens(self, output))
return;

@@ -1154,3 +1397,3 @@ output.with_parens(function(){

if (expr instanceof AST_Number && expr.getValue() >= 0) {
if (!/[xa-f.]/i.test(output.last())) {
if (!/[xa-f.)]/i.test(output.last())) {
output.print(".");

@@ -1281,5 +1524,3 @@ }

});
DEFPRINT(AST_ObjectKeyVal, function(self, output){
var key = self.key;
var quote = self.quote;
AST_ObjectProperty.DEFMETHOD("print_property_name", function(key, quote, output) {
if (output.option("quote_keys")) {

@@ -1293,10 +1534,41 @@ output.print_string(key + "");

} else if (RESERVED_WORDS(key) ? output.option("screw_ie8") : is_identifier_string(key)) {
output.print_name(key);
if (quote && output.option("keep_quoted_props")) {
output.print_string(key, quote);
} else {
output.print_name(key);
}
} else {
output.print_string(key, quote);
}
output.colon();
self.value.print(output);
});
DEFPRINT(AST_ObjectSetter, function(self, output){
DEFPRINT(AST_ObjectKeyVal, function(self, output){
function get_name(self) {
var def = self.value.definition();
return def ? def.mangled_name || def.name : self.value.name;
}
if (output.option("shorthand") &&
self.value instanceof AST_Symbol &&
is_identifier_string(self.key) &&
get_name(self) === self.key
) {
self.print_property_name(self.key, self.quote, output);
} else {
if (!(self.key instanceof AST_Node)) {
self.print_property_name(self.key, self.quote, output);
} else {
output.with_square(function() {
self.key.print(output);
});
}
output.colon();
self.value.print(output);
}
if (self.default) {
output.space();
output.print('=');
output.space();
self.default.print(output);
}
});
AST_ObjectProperty.DEFMETHOD("_print_getter_setter", function(type, self, output) {
if (self.static) {

@@ -1306,8 +1578,20 @@ output.print("static");

}
output.print("set");
output.print(type);
output.space();
self.key.print(output);
if (self.key instanceof AST_SymbolMethod) {
self.print_property_name(self.key.name, self.quote, output);
} else {
output.with_square(function() {
self.key.print(output);
});
}
self.value._do_print(output, true);
});
DEFPRINT(AST_ObjectSetter, function(self, output){
self._print_getter_setter("set", self, output);
});
DEFPRINT(AST_ObjectGetter, function(self, output){
self._print_getter_setter("get", self, output);
});
DEFPRINT(AST_ConciseMethod, function(self, output){
if (self.static) {

@@ -1317,14 +1601,15 @@ output.print("static");

}
output.print("get");
if (self.is_generator) {
output.print("*");
}
output.space();
self.key.print(output);
if (self.key instanceof AST_SymbolMethod) {
self.print_property_name(self.key.name, self.quote, output);
} else {
output.with_square(function() {
self.key.print(output);
});
}
self.value._do_print(output, true);
});
DEFPRINT(AST_ObjectComputedKeyVal, function(self, output) {
output.print("[");
self.key.print(output);
output.print("]:");
output.space();
self.value.print(output);
});
AST_Symbol.DEFMETHOD("_do_print", function(output){

@@ -1346,19 +1631,2 @@ var def = this.definition();

});
DEFPRINT(AST_ObjectSymbol, function(self, output){
var name = self.mangled_key || self.symbol.name;
var def = self.symbol.definition();
if (def && def.mangled_name) {
output.print(name);
output.print(':');
output.space();
output.print(def.mangled_name);
} else if (!(def && def.mangled_name) && self.mangled_key) {
output.print(name);
output.print(':');
output.space();
output.print(def.name);
} else {
output.print(name);
}
});
DEFPRINT(AST_Undefined, function(self, output){

@@ -1384,6 +1652,6 @@ output.print("void 0");

DEFPRINT(AST_String, function(self, output){
output.print_string(self.getValue(), self.quote);
output.print_string(self.getValue(), self.quote, in_directive);
});
DEFPRINT(AST_Number, function(self, output){
if (use_asm && self.start.raw != null) {
if (use_asm && self.start && self.start.raw != null) {
output.print(self.start.raw);

@@ -1485,4 +1753,7 @@ } else {

// self should be AST_New. decide if we want to show parens or not.
function no_constructor_parens(self, output) {
return self.args.length == 0 && !output.option("beautify");
function need_constructor_parens(self, output) {
// Always print parentheses with arguments
if (self.args.length > 0) return true;
return output.option("beautify");
};

@@ -1489,0 +1760,0 @@

@@ -47,6 +47,23 @@ /***********************************************************************

function find_builtins() {
// Compatibility fix for some standard defined globals not defined on every js environment
var new_globals = ["Symbol", "Map", "Promise", "Proxy", "Reflect", "Set", "WeakMap", "WeakSet"];
var objects = {};
new_globals.forEach(function (new_global) {
objects[new_global] = global[new_global] || new Function();
});
var a = [];
[ Object, Array, Function, Number,
String, Boolean, Error, Math,
Date, RegExp
Date, RegExp, objects.Symbol, ArrayBuffer,
DataView, decodeURI, decodeURIComponent,
encodeURI, encodeURIComponent, eval, EvalError,
Float32Array, Float64Array, Int8Array, Int16Array,
Int32Array, isFinite, isNaN, JSON, objects.Map, parseFloat,
parseInt, objects.Promise, objects.Proxy, RangeError, ReferenceError,
objects.Reflect, objects.Set, SyntaxError, TypeError, Uint8Array,
Uint8ClampedArray, Uint16Array, Uint32Array, URIError,
objects.WeakMap, objects.WeakSet
].forEach(function(ctor){

@@ -69,3 +86,5 @@ Object.getOwnPropertyNames(ctor).map(add);

only_cache : false,
regex : null
regex : null,
ignore_quoted : false,
debug : false
});

@@ -86,5 +105,16 @@

var regex = options.regex;
var ignore_quoted = options.ignore_quoted;
// note debug is either false (disabled), or a string of the debug suffix to use (enabled).
// note debug may be enabled as an empty string, which is falsey. Also treat passing 'true'
// the same as passing an empty string.
var debug = (options.debug !== false);
var debug_name_suffix;
if (debug) {
debug_name_suffix = (options.debug === true ? "" : options.debug);
}
var names_to_mangle = [];
var unmangleable = [];
var ignored = {};

@@ -94,7 +124,4 @@ // step 1: find candidates to mangle

if (node instanceof AST_ObjectKeyVal) {
add(node.key);
add(node.key, ignore_quoted && node.quote);
}
else if (node instanceof AST_ObjectSymbol) {
add(node.symbol.name);
}
else if (node instanceof AST_ObjectProperty) {

@@ -105,10 +132,6 @@ // setter or getter, since KeyVal is handled above

else if (node instanceof AST_Dot) {
if (this.parent() instanceof AST_Assign) {
add(node.property);
}
add(node.property);
}
else if (node instanceof AST_Sub) {
if (this.parent() instanceof AST_Assign) {
addStrings(node.property);
}
addStrings(node.property, ignore_quoted);
}

@@ -123,9 +146,5 @@ else if (node instanceof AST_ConciseMethod) {

if (node instanceof AST_ObjectKeyVal) {
node.key = mangle(node.key);
if (!(ignore_quoted && node.quote))
node.key = mangle(node.key);
}
else if (node instanceof AST_ObjectSymbol) {
if (should_mangle(node.symbol.name)) {
node.mangled_key = mangle(node.symbol.name)
}
}
else if (node instanceof AST_ObjectProperty) {

@@ -139,3 +158,4 @@ // setter or getter

else if (node instanceof AST_Sub) {
node.property = mangleStrings(node.property);
if (!ignore_quoted)
node.property = mangleStrings(node.property);
}

@@ -174,2 +194,3 @@ else if (node instanceof AST_ConciseMethod) {

function should_mangle(name) {
if (ignore_quoted && name in ignored) return false;
if (regex && !regex.test(name)) return false;

@@ -181,3 +202,8 @@ if (reserved.indexOf(name) >= 0) return false;

function add(name) {
function add(name, ignore) {
if (ignore) {
ignored[name] = true;
return;
}
if (can_mangle(name))

@@ -198,5 +224,21 @@ push_uniq(names_to_mangle, name);

if (!mangled) {
do {
mangled = base54(++cache.cname);
} while (!can_mangle(mangled));
if (debug) {
// debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
var debug_mangled = "_$" + name + "$" + debug_name_suffix + "_";
if (can_mangle(debug_mangled) && !(ignore_quoted && debug_mangled in ignored)) {
mangled = debug_mangled;
}
}
// either debug mode is off, or it is on and we could not use the mangled name
if (!mangled) {
// note can_mangle() does not check if the name collides with the 'ignored' set
// (filled with quoted properties when ignore_quoted set). Make sure we add this
// check so we don't collide with a quoted name.
do {
mangled = base54(++cache.cname);
} while (!can_mangle(mangled) || (ignore_quoted && mangled in ignored));
}
cache.props.set(name, mangled);

@@ -207,3 +249,3 @@ }

function addStrings(node) {
function addStrings(node, ignore) {
var out = {};

@@ -218,3 +260,3 @@ try {

if (node instanceof AST_String) {
add(node.value);
add(node.value, ignore);
return true;

@@ -221,0 +263,0 @@ }

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

this.global = false;
this.export = false;
this.mangled_name = null;

@@ -58,4 +59,7 @@ this.object_destructuring_arg = false;

this.index = index;
this.id = SymbolDef.next_id++;
};
SymbolDef.next_id = 1;
SymbolDef.prototype = {

@@ -66,2 +70,3 @@ unmangleable: function(options) {

return (this.global && !options.toplevel)
|| this.export
|| this.object_destructuring_arg

@@ -97,3 +102,3 @@ || this.undeclared

options = defaults(options, {
screw_ie8: false,
screw_ie8: true,
cache: null

@@ -107,6 +112,8 @@ });

var defun = null;
var last_var_had_const_pragma = false;
var nesting = 0;
var in_destructuring = null;
var in_export;
var tw = new TreeWalker(function(node, descend){
if (options.screw_ie8 && node instanceof AST_Catch) {
if (node.is_block_scope()) {
var save_scope = scope;

@@ -116,2 +123,7 @@ scope = new AST_Scope(node);

scope.parent_scope = save_scope;
if (!(node instanceof AST_Scope)) {
scope.uses_with = save_scope.uses_with;
scope.uses_eval = save_scope.uses_eval;
scope.directives = save_scope.directives;
}
descend();

@@ -140,2 +152,7 @@ scope = save_scope;

}
if (node instanceof AST_Export) {
in_export = true;
descend();
in_export = false;
}
if (node instanceof AST_LabeledStatement) {

@@ -161,3 +178,3 @@ var l = node.label;

node.object_destructuring_arg = !!in_destructuring;
defun.def_variable(node);
defun.def_variable(node, in_export);
}

@@ -169,3 +186,3 @@ if (node instanceof AST_Label) {

if (node instanceof AST_SymbolLambda) {
defun.def_function(node);
defun.def_function(node, in_export);
}

@@ -178,16 +195,27 @@ else if (node instanceof AST_SymbolDefun) {

// later.
(node.scope = defun.parent_scope).def_function(node);
var parent_lambda = defun.parent_scope;
while (parent_lambda.is_block_scope()) {
parent_lambda = parent_lambda.parent_scope;
}
(node.scope = parent_lambda).def_function(node, in_export);
}
else if (node instanceof AST_SymbolClass) {
defun.def_variable(node);
defun.def_variable(node, in_export);
}
else if (node instanceof AST_SymbolImport) {
scope.def_variable(node, in_export);
}
else if (node instanceof AST_SymbolDefClass) {
// This deals with the name of the class being available
// inside the class.
(node.scope = defun.parent_scope).def_function(node);
(node.scope = defun.parent_scope).def_function(node, in_export);
}
else if (node instanceof AST_Var) {
last_var_had_const_pragma = node.has_const_pragma();
}
else if (node instanceof AST_SymbolVar
|| node instanceof AST_SymbolConst) {
var def = defun.def_variable(node);
def.constant = node instanceof AST_SymbolConst;
|| node instanceof AST_SymbolConst
|| node instanceof AST_SymbolLet) {
var def = ((node instanceof AST_SymbolBlockDeclaration) ? scope : defun).def_variable(node, in_export);
def.constant = node instanceof AST_SymbolConst || last_var_had_const_pragma;
def.destructuring = in_destructuring;

@@ -217,2 +245,13 @@ def.init = tw.parent().value;

var tw = new TreeWalker(function(node, descend){
function isModified(node, level) {
var parent = tw.parent(level);
if (parent instanceof AST_Unary && (parent.operator === "++" || parent.operator === "--")
|| parent instanceof AST_Assign && parent.left === node
|| parent instanceof AST_Call && parent.expression === node) {
return true;
} else if (parent instanceof AST_PropAccess && parent.expression === node) {
return isModified(parent, level + 1);
}
}
if (node instanceof AST_Lambda) {

@@ -238,3 +277,11 @@ var prev_func = func;

var name = node.name;
if (name == "eval" && tw.parent() instanceof AST_Call) {
for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope) {
s.uses_eval = true;
}
}
var sym = node.scope.find_variable(name);
if (node.scope instanceof AST_Lambda && name == "arguments") {
node.scope.uses_arguments = true;
}
if (!sym) {

@@ -250,14 +297,9 @@ var g;

}
node.thedef = g;
if (name == "eval" && tw.parent() instanceof AST_Call) {
for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope)
s.uses_eval = true;
}
if (func && name == "arguments") {
func.uses_arguments = true;
}
} else {
node.thedef = sym;
sym = g;
}
node.reference();
node.thedef = sym;
if (isModified(node, 0)) {
sym.modified = true;
}
node.reference(options);
return true;

@@ -284,8 +326,25 @@ }

AST_Node.DEFMETHOD("is_block_scope", function(){
return false; // Behaviour will be overridden by AST_Block
});
AST_Block.DEFMETHOD("is_block_scope", function(){
return (
!(this instanceof AST_Lambda) &&
!(this instanceof AST_Toplevel) &&
!(this instanceof AST_Class) &&
!(this instanceof AST_SwitchBranch)
);
});
AST_Lambda.DEFMETHOD("init_scope_vars", function(){
AST_Scope.prototype.init_scope_vars.apply(this, arguments);
this.uses_arguments = false;
var symbol = new AST_VarDef({ name: "arguments", start: this.start, end: this.end });
var def = new SymbolDef(this, this.variables.size(), symbol);
this.variables.set(symbol.name, def);
});
AST_SymbolRef.DEFMETHOD("reference", function() {
AST_SymbolRef.DEFMETHOD("reference", function(options) {
var def = this.definition();

@@ -297,2 +356,7 @@ def.references.push(this);

if (s === def.scope) break;
if (options.keep_fnames) {
s.variables.each(function(d) {
push_uniq(def.scope.enclosed, d);
});
}
s = s.parent_scope;

@@ -309,7 +373,7 @@ }

AST_Scope.DEFMETHOD("def_function", function(symbol){
this.functions.set(symbol.name, this.def_variable(symbol));
AST_Scope.DEFMETHOD("def_function", function(symbol, in_export){
this.functions.set(symbol.name, this.def_variable(symbol, in_export));
});
AST_Scope.DEFMETHOD("def_variable", function(symbol){
AST_Scope.DEFMETHOD("def_variable", function(symbol, in_export){
var def;

@@ -320,3 +384,6 @@ if (!this.variables.has(symbol.name)) {

def.object_destructuring_arg = symbol.object_destructuring_arg;
def.global = !this.parent_scope;
if (in_export) {
def.export = true;
}
def.global = !this.parent_scope && !(symbol instanceof AST_SymbolBlockDeclaration);
} else {

@@ -357,5 +424,9 @@ def = this.variables.get(symbol.name);

var tricky_def = def.orig[0] instanceof AST_SymbolFunarg && this.name && this.name.definition();
// the function's mangled_name is null when keep_fnames is true
var tricky_name = tricky_def ? tricky_def.mangled_name || tricky_def.name : null;
while (true) {
var name = AST_Lambda.prototype.next_mangled.call(this, options, def);
if (!(tricky_def && tricky_def.mangled_name == name))
if (!tricky_name || tricky_name != name)
return name;

@@ -365,7 +436,2 @@ }

AST_Scope.DEFMETHOD("references", function(sym){
if (sym instanceof AST_Symbol) sym = sym.definition();
return this.enclosed.indexOf(sym) < 0 ? null : sym;
});
AST_Symbol.DEFMETHOD("unmangleable", function(options){

@@ -411,2 +477,8 @@ var def = this.definition();

AST_Var.DEFMETHOD("has_const_pragma", function() {
var comments_before = this.start && this.start.comments_before;
var lastComment = comments_before && comments_before[comments_before.length - 1];
return lastComment && /@const\b/.test(lastComment.value);
});
AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options){

@@ -416,5 +488,5 @@ return defaults(options, {

eval : false,
sort : false,
sort : false, // Ignored. Flag retained for backwards compatibility.
toplevel : false,
screw_ie8 : false,
screw_ie8 : true,
keep_fnames : false,

@@ -427,2 +499,6 @@ keep_classnames : false

options = this._default_mangler_options(options);
// Never mangle arguments
options.except.push('arguments');
// We only need to mangle declaration nodes. Special logic wired

@@ -458,5 +534,2 @@ // into the code generator will display the mangled name if it's

});
if (options.sort) a.sort(function(a, b){
return b.references.length - a.references.length;
});
to_mangle.push.apply(to_mangle, a);

@@ -471,3 +544,6 @@ return;

}
if (options.screw_ie8 && node instanceof AST_SymbolCatch) {
var mangle_with_block_scope =
(options.screw_ie8 && node instanceof AST_SymbolCatch) ||
node instanceof AST_SymbolBlockDeclaration;
if (mangle_with_block_scope) {
to_mangle.push(node.definition());

@@ -532,7 +608,9 @@ return;

else if (node instanceof AST_ObjectSetter)
base54.consider("set" + node.key);
base54.consider("set" + (typeof node.key === "string" ? node.key : ""));
else if (node instanceof AST_ObjectGetter)
base54.consider("get" + node.key);
else if (node instanceof AST_ObjectKeyVal)
base54.consider("get" + (typeof node.key === "string" ? node.key : ""));
else if (node instanceof AST_ObjectKeyVal && typeof node.key === "string")
base54.consider(node.key);
else if (node instanceof AST_ConciseMethod && typeof node.key === "string")
base54.consider(node.key);
else if (node instanceof AST_New)

@@ -550,2 +628,4 @@ base54.consider("new");

base54.consider("finally");
else if (node instanceof AST_Yield)
base54.consider("yield");
else if (node instanceof AST_Symbol && node.unmangleable(options))

@@ -552,0 +632,0 @@ base54.consider(node.name);

@@ -56,12 +56,17 @@ /***********************************************************************

});
var generator = new MOZ_SourceMap.SourceMapGenerator({
file : options.file,
sourceRoot : options.root
});
var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
var generator;
if (orig_map) {
generator = MOZ_SourceMap.SourceMapGenerator.fromSourceMap(orig_map);
} else {
generator = new MOZ_SourceMap.SourceMapGenerator({
file : options.file,
sourceRoot : options.root
if (orig_map && Array.isArray(options.orig.sources)) {
orig_map._sources.toArray().forEach(function(source) {
var sourceContent = orig_map.sourceContentFor(source, true);
if (sourceContent) {
generator.setSourceContent(source, sourceContent);
}
});
}
function add(source, gen_line, gen_col, orig_line, orig_col, name) {

@@ -87,3 +92,3 @@ if (orig_map) {

});
}
};
return {

@@ -90,0 +95,0 @@ add : add,

@@ -67,3 +67,3 @@ /***********************************************************************

} else {
tw.stack[tw.stack.length - 1] = x = this.clone();
tw.stack[tw.stack.length - 1] = x = this;
descend(x, tw);

@@ -200,2 +200,6 @@ y = tw.after(x, in_list);

_(AST_Yield, function(self, tw){
if (self.expression) self.expression = self.expression.transform(tw);
});
_(AST_Unary, function(self, tw){

@@ -224,10 +228,31 @@ self.expression = self.expression.transform(tw);

_(AST_ObjectSymbol, function(self, tw){
self.symbol = self.symbol.transform(tw);
});
_(AST_ObjectProperty, function(self, tw){
if (self.key instanceof AST_Node) {
self.key = self.key.transform(tw);
}
self.value = self.value.transform(tw);
});
_(AST_Class, function(self, tw){
if (self.name) self.name = self.name.transform(tw);
if (self.extends) self.extends = self.extends.transform(tw);
self.properties = do_list(self.properties, tw);
});
_(AST_Expansion, function(self, tw){
self.expression = self.expression.transform(tw);
});
_(AST_TemplateString, function(self, tw) {
for (var i = 0; i < self.segments.length; i++) {
if (!(self.segments[i] instanceof AST_TemplateSegment)) {
self.segments[i] = self.segments[i].transform(tw);
}
}
});
_(AST_PrefixedTemplateString, function(self, tw) {
self.template_string = self.template_string.transform(tw);
});
})();

@@ -62,6 +62,3 @@ /***********************************************************************

function member(name, array) {
for (var i = array.length; --i >= 0;)
if (array[i] == name)
return true;
return false;
return array.indexOf(name) >= 0;
};

@@ -101,6 +98,6 @@

var ret = args || {};
if (croak) for (var i in ret) if (ret.hasOwnProperty(i) && !defs.hasOwnProperty(i))
if (croak) for (var i in ret) if (HOP(ret, i) && !HOP(defs, i))
DefaultsError.croak("`" + i + "` is not a supported option", defs);
for (var i in defs) if (defs.hasOwnProperty(i)) {
ret[i] = (args && args.hasOwnProperty(i)) ? args[i] : defs[i];
for (var i in defs) if (HOP(defs, i)) {
ret[i] = (args && HOP(args, i)) ? args[i] : defs[i];
}

@@ -112,3 +109,3 @@ return ret;

var count = 0;
for (var i in ext) if (ext.hasOwnProperty(i)) {
for (var i in ext) if (HOP(ext, i)) {
obj[i] = ext[i];

@@ -121,2 +118,4 @@ count++;

function noop() {};
function return_false() { return false; }
function return_true() { return true; }

@@ -157,3 +156,3 @@ var MAP = (function(){

else {
for (i in a) if (a.hasOwnProperty(i)) if (doit()) break;
for (i in a) if (HOP(a, i)) if (doit()) break;
}

@@ -238,6 +237,15 @@ return top.concat(ret);

}
function quote(word) {
return JSON.stringify(word).replace(/[\u2028\u2029]/g, function(s) {
switch (s) {
case "\u2028": return "\\u2028";
case "\u2029": return "\\u2029";
}
return s;
});
}
function compareTo(arr) {
if (arr.length == 1) return f += "return str === " + JSON.stringify(arr[0]) + ";";
if (arr.length == 1) return f += "return str === " + quote(arr[0]) + ";";
f += "switch(str){";
for (var i = 0; i < arr.length; ++i) f += "case " + JSON.stringify(arr[i]) + ":";
for (var i = 0; i < arr.length; ++i) f += "case " + quote(arr[i]) + ":";
f += "return true}return false;";

@@ -317,1 +325,5 @@ }

};
function HOP(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}

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

"license": "BSD-2-Clause",
"version": "2.6.2",
"version": "2.7.5",
"engines": {

@@ -42,3 +42,4 @@ "node": ">=0.8.0"

"esfuzz": "~0.3.1",
"estraverse": "~1.5.1"
"estraverse": "~1.5.1",
"mocha": "~2.3.4"
},

@@ -53,3 +54,4 @@ "browserify": {

"test": "node test/run-tests.js"
}
},
"keywords": ["uglify", "uglify-js", "minify", "minifier"]
}

@@ -65,8 +65,14 @@ UglifyJS 2

sourcesContent property.
--source-map-inline Write base64-encoded source map to the end of js output.
--in-source-map Input source map, useful if you're compressing
JS that was 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).
--screw-ie8 Use this flag if you don't wish to support
Internet Explorer 6/7/8.
By default UglifyJS will not try to be IE-proof.
--support-ie8 Use this flag to support Internet Explorer 6/7/8.
Equivalent to setting `screw_ie8: false` in `minify()`
for `compress`, `mangle` and `output` options.
Note: `--support-ie8` may generate incorrect code
for `try`/`catch` in ES5 compliant browsers.
--expr Parse a single expression, rather than a

@@ -99,4 +105,4 @@ program (for parsing JSON)

- "all" to keep all comments
- a valid JS regexp (needs to start with a
slash) to keep only comments that match.
- a valid JS RegExp like `/foo/` or `/^!/` to
keep only matching comments.
Note that currently not *all* comments can be

@@ -130,3 +136,5 @@ kept when compression is on, because of dead

--bare-returns Allow return outside of functions. Useful when
minifying CommonJS modules.
minifying CommonJS modules and Userscripts that
may be anonymous function wrapped (IIFE) by the
.user.js engine `caller`.
--keep-fnames Do not mangle/drop function names. Useful for

@@ -137,3 +145,12 @@ code relying on Function.prototype.name.

--mangle-props
--mangle-props Mangle property names
--mangle-props Mangle property names (default `0`). Set to
`true` or `1` to mangle all property names. Set
to `unquoted` or `2` to only mangle unquoted
property names. Mode `2` also enables the
`keep_quoted_props` beautifier option to
preserve the quotes around property names and
disables the `properties` compressor option to
prevent rewriting quoted properties with dot
notation. You can override these by setting
them explicitly on the command line.
--mangle-regex Only mangle property names matching the regex

@@ -197,7 +214,2 @@ --name-cache File to hold mangled names mappings

- `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

@@ -284,2 +296,28 @@ default).

#### Mangling unquoted names (`--mangle-props=unquoted` or `--mangle-props=2`)
Using quoted property name (`o["foo"]`) reserves the property name (`foo`)
so that it is not mangled throughout the entire script even when used in an
unquoted style (`o.foo`). Example:
```
$ echo 'var o={"foo":1, bar:3}; o.foo += o.bar; console.log(o.foo);' | uglifyjs --mangle-props=2 -mc
var o={"foo":1,a:3};o.foo+=o.a,console.log(o.foo);
```
#### Debugging property name mangling
You can also pass `--mangle-props-debug` in order to mangle property names
without completely obscuring them. For example the property `o.foo`
would mangle to `o._$foo$_` with this option. This allows property mangling
of a large codebase while still being able to debug the code and identify
where mangling is breaking things.
You can also pass a custom suffix using `--mangle-props-debug=XYZ`. This would then
mangle `o.foo` to `o._$foo$XYZ_`. You can change this each time you compile a
script to identify how a property got mangled. One technique is to pass a
random number on every compile to simulate mangling changing with different
inputs (e.g. as you update the input script with new properties), and to help
identify mistakes like writing mangled keys to storage.
## Compressor options

@@ -292,3 +330,10 @@

- `sequences` -- join consecutive simple statements using the comma operator
- `sequences` (default: true) -- join consecutive simple statements using the
comma operator. May be set to a positive integer to specify the maximum number
of consecutive comma sequences that will be generated. If this option is set to
`true` then the default `sequences` limit is `200`. Set option to `false` or `0`
to disable. The smallest `sequences` length is `2`. A `sequences` value of `1`
is grandfathered to be equivalent to `true` and as such means `200`. On rare
occasions the default sequences limit leads to very slow compress times in which
case a value of `20` or less is recommended.

@@ -304,2 +349,9 @@ - `properties` -- rewrite property access using the dot notation, for

- `unsafe_comps` (default: false) -- Reverse `<` and `<=` to `>` and `>=` to
allow improved compression. This might be unsafe when an at least one of two
operands is an object with computed values due the use of methods like `get`,
or `valueOf`. This could cause change in execution order after operands in the
comparison are switching. Compression only works if both `comparisons` and
`unsafe_comps` are both set to true.
- `conditionals` -- apply optimizations for `if`-s and conditional

@@ -309,4 +361,4 @@ expressions

- `comparisons` -- apply certain optimizations to binary nodes, for example:
`!(a <= b) → a > b` (only when `unsafe`), attempts to negate binary nodes,
e.g. `a = !b && !c && !d && !e → a=!(b||c||d||e)` etc.
`!(a <= b) → a > b` (only when `unsafe_comps`), attempts to negate binary
nodes, e.g. `a = !b && !c && !d && !e → a=!(b||c||d||e)` etc.

@@ -335,2 +387,8 @@ - `evaluate` -- attempt to evaluate constant expressions

- `collapse_vars` -- default `false`. Collapse single-use `var` and `const`
definitions when possible.
- `reduce_vars` -- default `false`. Improve optimization on variables assigned
with and used as constant values.
- `warnings` -- display warnings when dropping unreachable code or unused

@@ -366,5 +424,8 @@ declarations etc.

- `keep_fnames` -- default `false`. Pass `true` to prevent the
compressor from mangling/discarding function names. Useful for code relying on
`Function.prototype.name`.
compressor from discarding function names. Useful for code relying on
`Function.prototype.name`. See also: the `keep_fnames` [mangle option](#mangle).
- `passes` -- default `1`. Number of times to run compress. Use an
integer argument larger than 1 to further reduce code size in some cases.
Note: raising the number of passes will increase uglify compress time.

@@ -409,2 +470,4 @@ ### The `unsafe` option

const PRODUCTION = true;
// Alternative for environments that don't support `const`
/** @const */ var STAGING = false;
// etc.

@@ -419,6 +482,22 @@ ```

will evaluate references to them to the value itself and drop unreachable
code as usual. The possible downside of this approach is that the build
will contain the `const` declarations.
code as usual. The build will contain the `const` declarations if you use
them. If you are targeting < ES6 environments, use `/** @const */ var`.
<a name="codegen-options"></a>
#### Conditional compilation, API
You can also use conditional compilation via the programmatic API. With the difference that the
property name is `global_defs` and is a compressor property:
```js
uglifyJS.minify([ "input.js"], {
compress: {
dead_code: true,
global_defs: {
DEBUG: false
}
}
});
```
## Beautifier options

@@ -440,3 +519,3 @@

- `ascii-only` (default `false`) -- escape Unicode characters in strings and
regexps
regexps (affects directives with non-ascii characters becoming invalid)
- `inline-script` (default `false`) -- escape the slash in occurrences of

@@ -468,2 +547,7 @@ `</script` in strings

- `3` -- always use the original quotes
- `keep_quoted_props` (default `false`) -- when turned on, prevents stripping
quotes from property names in object literals.
- `ecma` (default `5`) -- set output printing mode. This will only change the
output in direct control of the beautifier. Non-compatible features in the
abstract syntax tree will still be outputted as is.

@@ -598,6 +682,23 @@ ### Keeping copyright notices or other comments

To generate a source map with the fromString option, you can also use an object:
```javascript
var result = UglifyJS.minify({"file1.js": "var a = function () {};"}, {
outSourceMap: "out.js.map",
outFileName: "out.js",
fromString: true
});
```
Note that the source map is not saved in a file, it's just returned in
`result.map`. The value passed for `outSourceMap` is only used to set the
`file` attribute in the source map (see [the spec][sm-spec]).
`result.map`. The value passed for `outSourceMap` is only used to set
`//# sourceMappingURL=out.js.map` in `result.code`. The value of
`outFileName` is only used to set `file` attribute in source map file.
The `file` attribute in the source map (see [the spec][sm-spec]) will
use `outFileName` firstly, if it's falsy, then will be deduced from
`outSourceMap` (by removing `'.map'`).
You can set option `sourceMapInline` to be `true` and source map will
be appended to code.
You can also specify sourceRoot property to be included in source map:

@@ -634,2 +735,13 @@ ```javascript

To set the source map url, use the `sourceMapUrl` option.
If you're using the X-SourceMap header instead, you can just set the `sourceMapUrl` option to false.
Defaults to outSourceMap:
```javascript
var result = UglifyJS.minify([ "file1.js" ], {
outSourceMap: "out.js.map",
sourceMapUrl: "localhost/out.js.map"
});
```
Other options:

@@ -642,4 +754,8 @@

- `mangle` — pass `false` to skip mangling names.
- `mangle` (default `true`) — pass `false` to skip mangling names, or pass
an object to specify mangling options (see below).
- `mangleProperties` (default `false`) — pass an object to specify custom
mangle property options.
- `output` (default `null`) — pass an object if you wish to specify

@@ -652,2 +768,45 @@ additional [output options][codegen]. The defaults are optimized

- `parse` (default {}) — pass an object if you wish to specify some
additional [parser options][parser]. (not all options available... see below)
##### mangle
- `except` - pass an array of identifiers that should be excluded from mangling
- `toplevel` — mangle names declared in the toplevel scope (disabled by
default).
- `eval` — mangle names visible in scopes where eval or with are used
(disabled by default).
- `keep_fnames` -- default `false`. Pass `true` to not mangle
function names. Useful for code relying on `Function.prototype.name`.
See also: the `keep_fnames` [compress option](#compressor-options).
Examples:
```javascript
//tst.js
var globalVar;
function funcName(firstLongName, anotherLongName)
{
var myVariable = firstLongName + anotherLongName;
}
UglifyJS.minify("tst.js").code;
// 'function funcName(a,n){}var globalVar;'
UglifyJS.minify("tst.js", { mangle: { except: ['firstLongName'] } }).code;
// 'function funcName(firstLongName,a){}var globalVar;'
UglifyJS.minify("tst.js", { mangle: { toplevel: true } }).code;
// 'function n(n,a){}var a;'
```
##### mangleProperties options
- `regex` — Pass a RegExp to only mangle certain names (maps to the `--mangle-regex` CLI arguments option)
- `ignore_quoted` – Only mangle unquoted property names (maps to the `--mangle-props 2` CLI arguments option)
- `debug` – Mangle names with the original name still present (maps to the `--mangle-props-debug` CLI arguments option). Defaults to `false`. Pass an empty string to enable, or a non-empty string to set the suffix.
We could add more options to `UglifyJS.minify` — if you need additional

@@ -671,2 +830,5 @@ functionality please suggest!

comma in arrays and objects
- `bare_returns` — Allow return outside of functions. (maps to the
`--bare-returns` CLI arguments option and available to `minify` `parse`
other options object)
- `filename` — the name of the file where this code is coming from

@@ -756,4 +918,7 @@ - `toplevel` — a `toplevel` node (as returned by a previous invocation of

In order to keep certain comments in the output you need to pass the
`comments` option. Pass a RegExp or a function. If you pass a RegExp, only
those comments whose body matches the regexp will be kept. Note that body
`comments` option. Pass a RegExp (as string starting and closing with `/`
or pass a RegExp object), a boolean or a function. Stringified options
`all` and `some` can be passed too, where `some` behaves like it's cli
equivalent `--comments` without passing a value. If you pass a RegExp,
only those comments whose body matches the RegExp will be kept. Note that body
means without the initial `//` or `/*`. If you pass a function, it will be

@@ -812,1 +977,2 @@ called for every comment in the tree and will receive two arguments: the

[compressor]: http://lisperator.net/uglifyjs/compress
[parser]: http://lisperator.net/uglifyjs/parser

@@ -17,2 +17,8 @@ exports["Compressor"] = Compressor;

exports["string_template"] = string_template;
exports["tokenizer"] = tokenizer;
exports["is_identifier"] = is_identifier;
exports["SymbolDef"] = SymbolDef;
if (typeof DEBUG !== "undefined" && DEBUG) {
exports["EXPECT_DIRECTIVE"] = EXPECT_DIRECTIVE;
}

@@ -0,1 +1,7 @@

// workaround for tty output truncation upon process.exit()
[process.stdout, process.stderr].forEach(function(stream){
if (stream._handle && stream._handle.setBlocking)
stream._handle.setBlocking(true);
});
var path = require("path");

@@ -22,7 +28,8 @@ var fs = require("fs");

new Function("MOZ_SourceMap", "exports", FILES.map(function(file){
new Function("MOZ_SourceMap", "exports", "DEBUG", FILES.map(function(file){
return fs.readFileSync(file, "utf8");
}).join("\n\n"))(
require("source-map"),
UglifyJS
UglifyJS,
!!global.UGLIFY_DEBUG
);

@@ -36,11 +43,17 @@

options = UglifyJS.defaults(options, {
spidermonkey : false,
outSourceMap : null,
sourceRoot : null,
inSourceMap : null,
fromString : false,
warnings : false,
mangle : {},
output : null,
compress : {}
spidermonkey : false,
outSourceMap : null,
outFileName : null,
sourceRoot : null,
inSourceMap : null,
sourceMapUrl : null,
sourceMapInline : false,
fromString : false,
warnings : false,
mangle : {},
mangleProperties : false,
nameCache : null,
output : null,
compress : {},
parse : {}
});

@@ -56,13 +69,22 @@ UglifyJS.base54.reset();

} else {
if (typeof files == "string")
files = [ files ];
files.forEach(function(file, i){
function addFile(file, fileUrl) {
var code = options.fromString
? file
: fs.readFileSync(file, "utf8");
sourcesContent[file] = code;
sourcesContent[fileUrl] = code;
toplevel = UglifyJS.parse(code, {
filename: options.fromString ? i : file,
toplevel: toplevel
filename: fileUrl,
toplevel: toplevel,
bare_returns: options.parse ? options.parse.bare_returns : undefined
});
}
if (!options.fromString) files = UglifyJS.simple_glob(files);
[].concat(files).forEach(function (files, i) {
if (typeof files === 'string') {
addFile(files, options.fromString ? i : files);
} else {
for (var fileUrl in files) {
addFile(files[fileUrl], fileUrl);
}
}
});

@@ -78,8 +100,15 @@ }

UglifyJS.merge(compress, options.compress);
toplevel.figure_out_scope();
toplevel.figure_out_scope(options.mangle);
var sq = UglifyJS.Compressor(compress);
toplevel = toplevel.transform(sq);
toplevel = sq.compress(toplevel);
}
// 3. mangle
// 3. mangle properties
if (options.mangleProperties || options.nameCache) {
options.mangleProperties.cache = UglifyJS.readNameCache(options.nameCache, "props");
toplevel = UglifyJS.mangle_properties(toplevel, options.mangleProperties);
UglifyJS.writeNameCache(options.nameCache, "props", options.mangleProperties.cache);
}
// 4. mangle
if (options.mangle) {

@@ -91,11 +120,12 @@ toplevel.figure_out_scope(options.mangle);

// 4. output
// 5. output
var inMap = options.inSourceMap;
var output = {};
if (typeof options.inSourceMap == "string") {
inMap = fs.readFileSync(options.inSourceMap, "utf8");
inMap = JSON.parse(fs.readFileSync(options.inSourceMap, "utf8"));
}
if (options.outSourceMap) {
if (options.outSourceMap || options.sourceMapInline) {
output.source_map = UglifyJS.SourceMap({
file: options.outSourceMap,
// prefer outFileName, otherwise use outSourceMap without .map suffix
file: options.outFileName || (typeof options.outSourceMap === 'string' ? options.outSourceMap.replace(/\.map$/i, '') : null),
orig: inMap,

@@ -119,5 +149,2 @@ root: options.sourceRoot

if (options.outSourceMap && "string" === typeof options.outSourceMap) {
stream += "\n//# sourceMappingURL=" + options.outSourceMap;
}

@@ -129,2 +156,9 @@ var source_map = output.source_map;

var mappingUrlPrefix = "\n//# sourceMappingURL=";
if (options.sourceMapInline) {
stream += mappingUrlPrefix + "data:application/json;charset=utf-8;base64," + new Buffer(source_map).toString("base64");
} else if (options.outSourceMap && typeof options.outSourceMap === "string" && options.sourceMapUrl !== false) {
stream += mappingUrlPrefix + (typeof options.sourceMapUrl === "string" ? options.sourceMapUrl : options.outSourceMap);
}
return {

@@ -244,1 +278,45 @@ code : stream + "",

};
// A file glob function that only supports "*" and "?" wildcards in the basename.
// Example: "foo/bar/*baz??.*.js"
// Argument `glob` may be a string or an array of strings.
// Returns an array of strings. Garbage in, garbage out.
exports.simple_glob = function simple_glob(glob) {
var results = [];
if (Array.isArray(glob)) {
glob.forEach(function(elem) {
results = results.concat(simple_glob(elem));
});
return results;
}
if (glob.match(/\*|\?/)) {
var dir = path.dirname(glob);
try {
var entries = fs.readdirSync(dir);
} catch (ex) {}
if (entries) {
var pattern = "^" + (path.basename(glob)
.replace(/\(/g, "\\(")
.replace(/\)/g, "\\)")
.replace(/\{/g, "\\{")
.replace(/\}/g, "\\}")
.replace(/\[/g, "\\[")
.replace(/\]/g, "\\]")
.replace(/\+/g, "\\+")
.replace(/\^/g, "\\^")
.replace(/\$/g, "\\$")
.replace(/\*/g, "[^/\\\\]*")
.replace(/\./g, "\\.")
.replace(/\?/g, ".")) + "$";
var mod = process.platform === "win32" ? "i" : "";
var rx = new RegExp(pattern, mod);
for (var i in entries) {
if (rx.test(entries[i]))
results.push(dir + "/" + entries[i]);
}
}
}
if (results.length === 0)
results = [ glob ];
return results;
};

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

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