Skip to content

Commit 7ecf9c2

Browse files
committed
Refs #942, update uglify to 2.7.5
1 parent fd9de76 commit 7ecf9c2

File tree

8 files changed

+96
-69
lines changed

8 files changed

+96
-69
lines changed

build/jslib/uglifyjs.js

Lines changed: 89 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ function merge(obj, ext) {
116116
};
117117

118118
function noop() {};
119+
function return_false() { return false; }
120+
function return_true() { return true; }
119121

120122
var MAP = (function(){
121123
function MAP(a, f, backwards) {
@@ -3830,6 +3832,20 @@ AST_Toplevel.DEFMETHOD("scope_warnings", function(options){
38303832

38313833
var EXPECT_DIRECTIVE = /^$|[;{][\s\n]*$/;
38323834

3835+
function is_some_comments(comment) {
3836+
var text = comment.value;
3837+
var type = comment.type;
3838+
if (type == "comment2") {
3839+
// multiline comment
3840+
return /@preserve|@license|@cc_on/i.test(text);
3841+
}
3842+
return type == "comment5";
3843+
}
3844+
3845+
function is_comment5(comment) {
3846+
return comment.type == "comment5";
3847+
}
3848+
38333849
function OutputStream(options) {
38343850

38353851
options = defaults(options, {
@@ -3853,50 +3869,34 @@ function OutputStream(options) {
38533869
preamble : null,
38543870
quote_style : 0,
38553871
keep_quoted_props: false,
3856-
wrap_iife : false
3872+
wrap_iife : false,
38573873
}, true);
38583874

38593875
// Convert comment option to RegExp if neccessary and set up comments filter
3860-
if (typeof options.comments === "string" && /^\/.*\/[a-zA-Z]*$/.test(options.comments)) {
3861-
var regex_pos = options.comments.lastIndexOf("/");
3862-
options.comments = new RegExp(
3863-
options.comments.substr(1, regex_pos - 1),
3864-
options.comments.substr(regex_pos + 1)
3865-
);
3866-
}
3867-
if (options.comments instanceof RegExp) {
3868-
options.comments = (function(f) {
3869-
return function(comment) {
3870-
return comment.type == "comment5" || f.test(comment.value);
3871-
}
3872-
})(options.comments);
3873-
}
3874-
else if (typeof options.comments === "function") {
3875-
options.comments = (function(f) {
3876-
return function(comment) {
3877-
return comment.type == "comment5" || f(this, comment);
3878-
}
3879-
})(options.comments);
3880-
}
3881-
else if (options.comments === "some") {
3882-
options.comments = function(comment) {
3883-
var text = comment.value;
3884-
var type = comment.type;
3885-
if (type == "comment2") {
3886-
// multiline comment
3887-
return /@preserve|@license|@cc_on/i.test(text);
3888-
}
3889-
return type == "comment5";
3876+
var comment_filter = options.shebang ? is_comment5 : return_false; // Default case, throw all comments away except shebangs
3877+
if (options.comments) {
3878+
var comments = options.comments;
3879+
if (typeof options.comments === "string" && /^\/.*\/[a-zA-Z]*$/.test(options.comments)) {
3880+
var regex_pos = options.comments.lastIndexOf("/");
3881+
comments = new RegExp(
3882+
options.comments.substr(1, regex_pos - 1),
3883+
options.comments.substr(regex_pos + 1)
3884+
);
38903885
}
3891-
}
3892-
else if (options.comments){ // NOTE includes "all" option
3893-
options.comments = function() {
3894-
return true;
3886+
if (comments instanceof RegExp) {
3887+
comment_filter = function(comment) {
3888+
return comment.type == "comment5" || comments.test(comment.value);
3889+
};
38953890
}
3896-
} else {
3897-
// Falsy case, so reject all comments, except shebangs
3898-
options.comments = function(comment) {
3899-
return comment.type == "comment5";
3891+
else if (typeof comments === "function") {
3892+
comment_filter = function(comment) {
3893+
return comment.type == "comment5" || comments(this, comment);
3894+
};
3895+
}
3896+
else if (comments === "some") {
3897+
comment_filter = is_some_comments;
3898+
} else { // NOTE includes "all" option
3899+
comment_filter = return_true;
39003900
}
39013901
}
39023902

@@ -4206,6 +4206,7 @@ function OutputStream(options) {
42064206
with_square : with_square,
42074207
add_mapping : add_mapping,
42084208
option : function(opt) { return options[opt] },
4209+
comment_filter : comment_filter,
42094210
line : function() { return current_line },
42104211
col : function() { return current_col },
42114212
pos : function() { return current_pos },
@@ -4288,7 +4289,7 @@ function OutputStream(options) {
42884289
}));
42894290
}
42904291

4291-
comments = comments.filter(output.option("comments"), self);
4292+
comments = comments.filter(output.comment_filter, self);
42924293

42934294
// Keep single line comments after nlb, after nlb
42944295
if (!output.option("beautify") && comments.length > 0 &&
@@ -6161,7 +6162,7 @@ merge(Compressor.prototype, {
61616162
(function (def){
61626163
var unary_bool = [ "!", "delete" ];
61636164
var binary_bool = [ "in", "instanceof", "==", "!=", "===", "!==", "<", "<=", ">=", ">" ];
6164-
def(AST_Node, function(){ return false });
6165+
def(AST_Node, return_false);
61656166
def(AST_UnaryPrefix, function(){
61666167
return member(this.operator, unary_bool);
61676168
});
@@ -6179,16 +6180,16 @@ merge(Compressor.prototype, {
61796180
def(AST_Seq, function(){
61806181
return this.cdr.is_boolean();
61816182
});
6182-
def(AST_True, function(){ return true });
6183-
def(AST_False, function(){ return true });
6183+
def(AST_True, return_true);
6184+
def(AST_False, return_true);
61846185
})(function(node, func){
61856186
node.DEFMETHOD("is_boolean", func);
61866187
});
61876188

61886189
// methods to determine if an expression has a string result type
61896190
(function (def){
6190-
def(AST_Node, function(){ return false });
6191-
def(AST_String, function(){ return true });
6191+
def(AST_Node, return_false);
6192+
def(AST_String, return_true);
61926193
def(AST_UnaryPrefix, function(){
61936194
return this.operator == "typeof";
61946195
});
@@ -6442,11 +6443,11 @@ merge(Compressor.prototype, {
64426443

64436444
// determine if expression has side effects
64446445
(function(def){
6445-
def(AST_Node, function(compressor){ return true });
6446+
def(AST_Node, return_true);
64466447

6447-
def(AST_EmptyStatement, function(compressor){ return false });
6448-
def(AST_Constant, function(compressor){ return false });
6449-
def(AST_This, function(compressor){ return false });
6448+
def(AST_EmptyStatement, return_false);
6449+
def(AST_Constant, return_false);
6450+
def(AST_This, return_false);
64506451

64516452
def(AST_Call, function(compressor){
64526453
var pure = compressor.option("pure_funcs");
@@ -6466,13 +6467,13 @@ merge(Compressor.prototype, {
64666467
def(AST_SimpleStatement, function(compressor){
64676468
return this.body.has_side_effects(compressor);
64686469
});
6469-
def(AST_Defun, function(compressor){ return true });
6470-
def(AST_Function, function(compressor){ return false });
6470+
def(AST_Defun, return_true);
6471+
def(AST_Function, return_false);
64716472
def(AST_Binary, function(compressor){
64726473
return this.left.has_side_effects(compressor)
64736474
|| this.right.has_side_effects(compressor);
64746475
});
6475-
def(AST_Assign, function(compressor){ return true });
6476+
def(AST_Assign, return_true);
64766477
def(AST_Conditional, function(compressor){
64776478
return this.condition.has_side_effects(compressor)
64786479
|| this.consequent.has_side_effects(compressor)
@@ -8235,7 +8236,7 @@ function SourceMap(options) {
82358236
var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
82368237

82378238
if (orig_map && Array.isArray(options.orig.sources)) {
8238-
options.orig.sources.forEach(function(source) {
8239+
orig_map._sources.toArray().forEach(function(source) {
82398240
var sourceContent = orig_map.sourceContentFor(source, true);
82408241
if (sourceContent) {
82418242
generator.setSourceContent(source, sourceContent);
@@ -8949,7 +8950,8 @@ function mangle_properties(ast, options) {
89498950
cache : null,
89508951
only_cache : false,
89518952
regex : null,
8952-
ignore_quoted : false
8953+
ignore_quoted : false,
8954+
debug : false
89538955
});
89548956

89558957
var reserved = options.reserved;
@@ -8967,6 +8969,15 @@ function mangle_properties(ast, options) {
89678969
var regex = options.regex;
89688970
var ignore_quoted = options.ignore_quoted;
89698971

8972+
// note debug is either false (disabled), or a string of the debug suffix to use (enabled).
8973+
// note debug may be enabled as an empty string, which is falsey. Also treat passing 'true'
8974+
// the same as passing an empty string.
8975+
var debug = (options.debug !== false);
8976+
var debug_name_suffix;
8977+
if (debug) {
8978+
debug_name_suffix = (options.debug === true ? "" : options.debug);
8979+
}
8980+
89708981
var names_to_mangle = [];
89718982
var unmangleable = [];
89728983
var ignored = {};
@@ -9060,9 +9071,25 @@ function mangle_properties(ast, options) {
90609071

90619072
var mangled = cache.props.get(name);
90629073
if (!mangled) {
9063-
do {
9064-
mangled = base54(++cache.cname);
9065-
} while (!can_mangle(mangled));
9074+
if (debug) {
9075+
// debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
9076+
var debug_mangled = "_$" + name + "$" + debug_name_suffix + "_";
9077+
9078+
if (can_mangle(debug_mangled) && !(ignore_quoted && debug_mangled in ignored)) {
9079+
mangled = debug_mangled;
9080+
}
9081+
}
9082+
9083+
// either debug mode is off, or it is on and we could not use the mangled name
9084+
if (!mangled) {
9085+
// note can_mangle() does not check if the name collides with the 'ignored' set
9086+
// (filled with quoted properties when ignore_quoted set). Make sure we add this
9087+
// check so we don't collide with a quoted name.
9088+
do {
9089+
mangled = base54(++cache.cname);
9090+
} while (!can_mangle(mangled) || (ignore_quoted && mangled in ignored));
9091+
}
9092+
90669093
cache.props.set(name, mangled);
90679094
}
90689095
return mangled;
@@ -9117,6 +9144,7 @@ exports.minify = function(files, options, name) {
91179144
options = defaults(options, {
91189145
spidermonkey : false,
91199146
outSourceMap : null,
9147+
outFileName : null,
91209148
sourceRoot : null,
91219149
inSourceMap : null,
91229150
sourceMapUrl : null,
@@ -9196,7 +9224,8 @@ exports.minify = function(files, options, name) {
91969224
}
91979225
if (options.outSourceMap || options.sourceMapInline) {
91989226
output.source_map = SourceMap({
9199-
file: options.outSourceMap,
9227+
// prefer outFileName, otherwise use outSourceMap without .map suffix
9228+
file: options.outFileName || (typeof options.outSourceMap === 'string' ? options.outSourceMap.replace(/\.map$/i, '') : null),
92009229
orig: inMap,
92019230
root: options.sourceRoot
92029231
});
@@ -9283,7 +9312,7 @@ exports.describe_ast = function() {
92839312
return out + "";
92849313
};
92859314

9286-
exports.readNameCache = function(filename, key) {
9315+
var readNameCache = function(filename, key) {
92879316
var cache = null;
92889317
if (filename) {
92899318
try {
@@ -9300,9 +9329,8 @@ exports.readNameCache = function(filename, key) {
93009329
}
93019330
return cache;
93029331
};
9303-
var readNameCache = exports.readNameCache;
93049332

9305-
exports.writeNameCache = function(filename, key, cache) {
9333+
var writeNameCache = function(filename, key, cache) {
93069334
if (filename) {
93079335
var data;
93089336
try {
@@ -9318,7 +9346,6 @@ exports.writeNameCache = function(filename, key, cache) {
93189346
fs.writeFileSync(filename, JSON.stringify(data, null, 2), "utf8");
93199347
}
93209348
};
9321-
var writeNameCache = exports.writeNameCache;
93229349

93239350

93249351
});

build/jslib/uglifyjs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Sets up uglifyjs for use in the optimizer.
22

3-
Current embedded version: 2.7.4, source-map 0.5.6
3+
Current embedded version: 2.7.5, source-map 0.5.6
44

55
Steps:
66

build/jslib/x.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ var requirejs, require, define, xpcUtil;
419419
} else if (commandOption === 'v') {
420420
console.log('r.js: ' + version +
421421
', RequireJS: ' + this.requirejsVars.require.version +
422-
', UglifyJS: 2.7.4');
422+
', UglifyJS: 2.7.5');
423423
} else if (commandOption === 'convert') {
424424
loadLib();
425425

build/tests/lib/sourcemap/expected-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/tests/lib/sourcemap/onejs/expected.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/tests/lib/sourcemap/twojs/expected.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/tests/lib/sourcemapSingle/expected-main-built.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/tests/lib/sourcemapSingle/main-built.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)