Socket
Socket
Sign inDemoInstall

uglify-js

Package Overview
Dependencies
Maintainers
3
Versions
288
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uglify-js - npm Package Compare versions

Comparing version 2.4.24 to 2.5.0

tools/exports.js

13

lib/ast.js

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

};
exports["AST_" + type] = ctor;
return ctor;

@@ -333,8 +334,7 @@ };

}
var wrapped_tl = "(function(exports, global){ global['" + name + "'] = exports; '$ORIG'; '$EXPORTS'; }({}, (function(){return this}())))";
var wrapped_tl = "(function(exports, global){ '$ORIG'; '$EXPORTS'; global['" + name + "'] = exports; }({}, (function(){return this}())))";
wrapped_tl = parse(wrapped_tl);
wrapped_tl = wrapped_tl.transform(new TreeTransformer(function before(node){
if (node instanceof AST_SimpleStatement) {
node = node.body;
if (node instanceof AST_String) switch (node.getValue()) {
if (node instanceof AST_Directive) {
switch (node.value) {
case "$ORIG":

@@ -869,6 +869,7 @@ return MAP.splice(self.body);

var AST_Number = DEFNODE("Number", "value", {
var AST_Number = DEFNODE("Number", "value literal", {
$documentation: "A number literal",
$propdoc: {
value: "[number] the numeric value"
value: "[number] the numeric value",
literal: "[string] numeric value as string (optional)"
}

@@ -875,0 +876,0 @@ }, AST_Constant);

@@ -402,3 +402,3 @@ /***********************************************************************

var moz_to_me = "function From_Moz_" + moztype + "(M){\n";
moz_to_me += "return new " + mytype.name + "({\n" +
moz_to_me += "return new U2." + mytype.name + "({\n" +
"start: my_start_token(M),\n" +

@@ -446,4 +446,4 @@ "end: my_end_token(M)";

moz_to_me = new Function("my_start_token", "my_end_token", "from_moz", "return(" + moz_to_me + ")")(
my_start_token, my_end_token, from_moz
moz_to_me = new Function("U2", "my_start_token", "my_end_token", "from_moz", "return(" + moz_to_me + ")")(
exports, my_start_token, my_end_token, from_moz
);

@@ -450,0 +450,0 @@ me_to_moz = new Function("to_moz", "to_moz_block", "return(" + me_to_moz + ")")(

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

comments : false,
shebang : true,
preserve_line : false,

@@ -165,2 +166,4 @@ screw_ie8 : false,

if (might_need_semicolon) {
might_need_semicolon = false;
if ((!ch || ";}".indexOf(ch) < 0) && !/[;]$/.test(last)) {

@@ -176,7 +179,13 @@ if (options.semicolons || requireSemicolonChars(ch)) {

current_col = 0;
if (/^\s+$/.test(str)) {
// reset the semicolon flag, since we didn't print one
// now and might still have to later
might_need_semicolon = true;
}
}
if (!options.beautify)
might_need_space = false;
}
might_need_semicolon = false;
}

@@ -401,59 +410,65 @@

var c = output.option("comments"), self = this;
if (c) {
var start = self.start;
if (start && !start._comments_dumped) {
start._comments_dumped = true;
var comments = start.comments_before || [];
var start = self.start;
if (start && !start._comments_dumped) {
start._comments_dumped = true;
var comments = start.comments_before || [];
// XXX: ugly fix for https://github.com/mishoo/UglifyJS2/issues/112
// and https://github.com/mishoo/UglifyJS2/issues/372
if (self instanceof AST_Exit && self.value) {
self.value.walk(new TreeWalker(function(node){
if (node.start && node.start.comments_before) {
comments = comments.concat(node.start.comments_before);
node.start.comments_before = [];
}
if (node instanceof AST_Function ||
node instanceof AST_Array ||
node instanceof AST_Object)
{
return true; // don't go inside.
}
}));
}
// XXX: ugly fix for https://github.com/mishoo/UglifyJS2/issues/112
// and https://github.com/mishoo/UglifyJS2/issues/372
if (self instanceof AST_Exit && self.value) {
self.value.walk(new TreeWalker(function(node){
if (node.start && node.start.comments_before) {
comments = comments.concat(node.start.comments_before);
node.start.comments_before = [];
}
if (node instanceof AST_Function ||
node instanceof AST_Array ||
node instanceof AST_Object)
{
return true; // don't go inside.
}
}));
}
if (c.test) {
comments = comments.filter(function(comment){
return c.test(comment.value);
});
} else if (typeof c == "function") {
comments = comments.filter(function(comment){
return c(self, comment);
});
}
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";
});
}
// Keep single line comments after nlb, after nlb
if (!output.option("beautify") && comments.length > 0 &&
/comment[134]/.test(comments[0].type) &&
output.col() !== 0 && comments[0].nlb)
{
output.print("\n");
// Keep single line comments after nlb, after nlb
if (!output.option("beautify") && comments.length > 0 &&
/comment[134]/.test(comments[0].type) &&
output.col() !== 0 && comments[0].nlb)
{
output.print("\n");
}
comments.forEach(function(c){
if (/comment[134]/.test(c.type)) {
output.print("//" + c.value + "\n");
output.indent();
}
comments.forEach(function(c){
if (/comment[134]/.test(c.type)) {
output.print("//" + c.value + "\n");
else if (c.type == "comment2") {
output.print("/*" + c.value + "*/");
if (start.nlb) {
output.print("\n");
output.indent();
} else {
output.space();
}
else if (c.type == "comment2") {
output.print("/*" + c.value + "*/");
if (start.nlb) {
output.print("\n");
output.indent();
} else {
output.space();
}
}
});
}
}
else if (output.pos() === 0 && c.type == "comment5" && output.option("shebang")) {
output.print("#!" + c.value + "\n");
output.indent();
}
});
}

@@ -1150,3 +1165,9 @@ });

DEFPRINT(AST_Number, function(self, output){
output.print(make_num(self.getValue()));
if (self.literal !== undefined
&& +self.literal === self.value /* paranoid check */
&& self.scope && self.scope.has_directive('use asm')) {
output.print(self.literal);
} else {
output.print(make_num(self.getValue()));
}
});

@@ -1153,0 +1174,0 @@

@@ -213,3 +213,3 @@ /***********************************************************************

function tokenizer($TEXT, filename, html5_comments) {
function tokenizer($TEXT, filename, html5_comments, shebang) {

@@ -339,3 +339,7 @@ var S = {

if (!isNaN(valid)) {
return token("num", valid);
var tok = token("num", valid);
if (num.indexOf('.') >= 0) {
tok.literal = num;
}
return tok;
} else {

@@ -485,3 +489,7 @@ parse_error("Invalid syntax: " + num);

var mods = read_name();
return token("regexp", new RegExp(regexp, mods));
try {
return token("regexp", new RegExp(regexp, mods));
} catch(e) {
parse_error(e.message);
}
});

@@ -570,2 +578,9 @@

if (code == 92 || is_identifier_start(code)) return read_word();
if (shebang) {
if (S.pos == 0 && looking_at("#!")) {
forward(2);
return skip_line_comment("comment5");
}
}
parse_error("Unexpected character '" + ch + "'");

@@ -640,2 +655,3 @@ };

bare_returns : false,
shebang : true,
});

@@ -646,3 +662,3 @@

? tokenizer($TEXT, options.filename,
options.html5_comments)
options.html5_comments, options.shebang)
: $TEXT),

@@ -1119,3 +1135,3 @@ token : null,

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

@@ -1135,3 +1151,3 @@ expect_token("operator", "new");

end : prev()
}), true);
}), allow_calls);
};

@@ -1147,3 +1163,3 @@

case "num":
ret = new AST_Number({ start: tok, end: tok, value: tok.value });
ret = new AST_Number({ start: tok, end: tok, value: tok.value, literal: tok.literal });
break;

@@ -1181,3 +1197,3 @@ case "string":

if (is("operator", "new")) {
return new_();
return new_(allow_calls);
}

@@ -1184,0 +1200,0 @@ var start = S.token;

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

var names_to_mangle = [];
var unmangleable = [];

@@ -112,16 +113,10 @@ // step 1: find candidates to mangle

if (node instanceof AST_ObjectKeyVal) {
if (should_mangle(node.key)) {
node.key = mangle(node.key);
}
node.key = mangle(node.key);
}
else if (node instanceof AST_ObjectProperty) {
// setter or getter
if (should_mangle(node.key.name)) {
node.key.name = mangle(node.key.name);
}
node.key.name = mangle(node.key.name);
}
else if (node instanceof AST_Dot) {
if (should_mangle(node.property)) {
node.property = mangle(node.property);
}
node.property = mangle(node.property);
}

@@ -148,2 +143,3 @@ else if (node instanceof AST_Sub) {

function can_mangle(name) {
if (unmangleable.indexOf(name) >= 0) return false;
if (reserved.indexOf(name) >= 0) return false;

@@ -167,5 +163,13 @@ if (options.only_cache) {

push_uniq(names_to_mangle, name);
if (!should_mangle(name)) {
push_uniq(unmangleable, name);
}
}
function mangle(name) {
if (!should_mangle(name)) {
return name;
}
var mangled = cache.props.get(name);

@@ -213,5 +217,3 @@ if (!mangled) {

else if (node instanceof AST_String) {
if (should_mangle(node.value)) {
node.value = mangle(node.value);
}
node.value = mangle(node.value);
}

@@ -218,0 +220,0 @@ else if (node instanceof AST_Conditional) {

@@ -122,2 +122,6 @@ /***********************************************************************

}
if (node instanceof AST_Number) {
node.scope = scope;
return true;
}
if (node instanceof AST_With) {

@@ -124,0 +128,0 @@ for (var s = scope; s; s = s.parent_scope)

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

"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
"license": "BSD",
"version": "2.4.24",
"license": "BSD-2-Clause",
"version": "2.5.0",
"engines": {
"node": ">=0.4.0"
"node": ">=0.8.0"
},

@@ -34,3 +34,3 @@ "maintainers": [

"async": "~0.2.6",
"source-map": "0.1.34",
"source-map": "~0.5.1",
"uglify-to-browserify": "~1.0.0",

@@ -51,4 +51,5 @@ "yargs": "~3.5.4"

"scripts": {
"shrinkwrap": "rm ./npm-shrinkwrap.json; rm -rf ./node_modules; npm i && npm shrinkwrap && npm outdated",
"test": "node test/run-tests.js"
}
}

@@ -353,2 +353,7 @@ UglifyJS 2

- `keep_fnames` -- default `false`. Pass `true` to prevent the
compressor from mangling/discarding function names. Useful for code relying on
`Function.prototype.name`.
### The `unsafe` option

@@ -355,0 +360,0 @@

var path = require("path");
var fs = require("fs");
var vm = require("vm");
var UglifyJS = vm.createContext({
console : console,
process : process,
Buffer : Buffer,
MOZ_SourceMap : require("source-map")
});
function load_global(file) {
file = path.resolve(path.dirname(module.filename), file);
try {
var code = fs.readFileSync(file, "utf8");
return vm.runInContext(code, UglifyJS, file);
} catch(ex) {
// XXX: in case of a syntax error, the message is kinda
// useless. (no location information).
console.log("ERROR in file: " + file + " / " + ex);
process.exit(1);
}
};
var FILES = exports.FILES = [

@@ -35,3 +14,4 @@ "../lib/utils.js",

"../lib/mozilla-ast.js",
"../lib/propmangle.js"
"../lib/propmangle.js",
"./exports.js",
].map(function(file){

@@ -41,4 +21,11 @@ return fs.realpathSync(path.join(path.dirname(__filename), file));

FILES.forEach(load_global);
var UglifyJS = exports;
new Function("MOZ_SourceMap", "exports", FILES.map(function(file){
return fs.readFileSync(file, "utf8");
}).join("\n\n"))(
require("source-map"),
UglifyJS
);
UglifyJS.AST_Node.warn_function = function(txt) {

@@ -48,9 +35,2 @@ console.error("WARN: %s", txt);

// XXX: perhaps we shouldn't export everything but heck, I'm lazy.
for (var i in UglifyJS) {
if (UglifyJS.hasOwnProperty(i)) {
exports[i] = UglifyJS[i];
}
}
exports.minify = function(files, options) {

@@ -71,2 +51,3 @@ options = UglifyJS.defaults(options, {

// 1. parse
var haveScope = false;
var toplevel = null,

@@ -80,3 +61,3 @@ sourcesContent = {};

files = [ files ];
files.forEach(function(file){
files.forEach(function(file, i){
var code = options.fromString

@@ -87,3 +68,3 @@ ? file

toplevel = UglifyJS.parse(code, {
filename: options.fromString ? "?" : file,
filename: options.fromString ? i : file,
toplevel: toplevel

@@ -93,2 +74,5 @@ });

}
if (options.wrap) {
toplevel = toplevel.wrap_commonjs(options.wrap, options.exportAll);
}

@@ -100,2 +84,3 @@ // 2. compress

toplevel.figure_out_scope();
haveScope = true;
var sq = UglifyJS.Compressor(compress);

@@ -108,2 +93,3 @@ toplevel = toplevel.transform(sq);

toplevel.figure_out_scope(options.mangle);
haveScope = true;
toplevel.compute_char_frequency(options.mangle);

@@ -113,3 +99,8 @@ toplevel.mangle_names(options.mangle);

// 4. output
// 4. scope (if needed)
if (!haveScope) {
toplevel.figure_out_scope();
}
// 5. output
var inMap = options.inSourceMap;

@@ -141,3 +132,3 @@ var output = {};

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

@@ -144,0 +135,0 @@ }

Sorry, the diff of this file is not supported yet

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc