1
1
/**
2
- * @license r.js 2.3.2+ Thu, 16 Feb 2017 06:56:59 GMT Copyright jQuery Foundation and other contributors.
2
+ * @license r.js 2.3.2+ Sun, 19 Feb 2017 00:43:50 GMT Copyright jQuery Foundation and other contributors.
3
3
* Released under MIT license, http://github.com/requirejs/r.js/LICENSE
4
4
*/
5
5
@@ -19,7 +19,7 @@ var requirejs, require, define, xpcUtil;
19
19
(function (console, args, readFileFunc) {
20
20
var fileName, env, fs, vm, path, exec, rhinoContext, dir, nodeRequire,
21
21
nodeDefine, exists, reqMain, loadedOptimizedLib, existsForNode, Cc, Ci,
22
- version = '2.3.2+ Thu, 16 Feb 2017 06:56:59 GMT',
22
+ version = '2.3.2+ Sun, 19 Feb 2017 00:43:50 GMT',
23
23
jsSuffixRegExp = /\.js$/,
24
24
commandOption = '',
25
25
useLibLoaded = {},
@@ -14053,6 +14053,8 @@ function merge(obj, ext) {
14053
14053
};
14054
14054
14055
14055
function noop() {};
14056
+ function return_false() { return false; }
14057
+ function return_true() { return true; }
14056
14058
14057
14059
var MAP = (function(){
14058
14060
function MAP(a, f, backwards) {
@@ -17767,6 +17769,20 @@ AST_Toplevel.DEFMETHOD("scope_warnings", function(options){
17767
17769
17768
17770
var EXPECT_DIRECTIVE = /^$|[;{][\s\n]*$/;
17769
17771
17772
+ function is_some_comments(comment) {
17773
+ var text = comment.value;
17774
+ var type = comment.type;
17775
+ if (type == "comment2") {
17776
+ // multiline comment
17777
+ return /@preserve|@license|@cc_on/i.test(text);
17778
+ }
17779
+ return type == "comment5";
17780
+ }
17781
+
17782
+ function is_comment5(comment) {
17783
+ return comment.type == "comment5";
17784
+ }
17785
+
17770
17786
function OutputStream(options) {
17771
17787
17772
17788
options = defaults(options, {
@@ -17790,50 +17806,34 @@ function OutputStream(options) {
17790
17806
preamble : null,
17791
17807
quote_style : 0,
17792
17808
keep_quoted_props: false,
17793
- wrap_iife : false
17809
+ wrap_iife : false,
17794
17810
}, true);
17795
17811
17796
17812
// Convert comment option to RegExp if neccessary and set up comments filter
17797
- if (typeof options.comments === "string" && /^\/.*\/[a-zA-Z]*$/.test(options.comments)) {
17798
- var regex_pos = options.comments.lastIndexOf("/");
17799
- options.comments = new RegExp(
17800
- options.comments.substr(1, regex_pos - 1),
17801
- options.comments.substr(regex_pos + 1)
17802
- );
17803
- }
17804
- if (options.comments instanceof RegExp) {
17805
- options.comments = (function(f) {
17806
- return function(comment) {
17807
- return comment.type == "comment5" || f.test(comment.value);
17808
- }
17809
- })(options.comments);
17810
- }
17811
- else if (typeof options.comments === "function") {
17812
- options.comments = (function(f) {
17813
- return function(comment) {
17814
- return comment.type == "comment5" || f(this, comment);
17815
- }
17816
- })(options.comments);
17817
- }
17818
- else if (options.comments === "some") {
17819
- options.comments = function(comment) {
17820
- var text = comment.value;
17821
- var type = comment.type;
17822
- if (type == "comment2") {
17823
- // multiline comment
17824
- return /@preserve|@license|@cc_on/i.test(text);
17825
- }
17826
- return type == "comment5";
17813
+ var comment_filter = options.shebang ? is_comment5 : return_false; // Default case, throw all comments away except shebangs
17814
+ if (options.comments) {
17815
+ var comments = options.comments;
17816
+ if (typeof options.comments === "string" && /^\/.*\/[a-zA-Z]*$/.test(options.comments)) {
17817
+ var regex_pos = options.comments.lastIndexOf("/");
17818
+ comments = new RegExp(
17819
+ options.comments.substr(1, regex_pos - 1),
17820
+ options.comments.substr(regex_pos + 1)
17821
+ );
17827
17822
}
17828
- }
17829
- else if (options.comments){ // NOTE includes "all" option
17830
- options.comments = function() {
17831
- return true ;
17823
+ if (comments instanceof RegExp) {
17824
+ comment_filter = function(comment) {
17825
+ return comment.type == "comment5" || comments.test(comment.value);
17826
+ } ;
17832
17827
}
17833
- } else {
17834
- // Falsy case, so reject all comments, except shebangs
17835
- options.comments = function(comment) {
17836
- return comment.type == "comment5";
17828
+ else if (typeof comments === "function") {
17829
+ comment_filter = function(comment) {
17830
+ return comment.type == "comment5" || comments(this, comment);
17831
+ };
17832
+ }
17833
+ else if (comments === "some") {
17834
+ comment_filter = is_some_comments;
17835
+ } else { // NOTE includes "all" option
17836
+ comment_filter = return_true;
17837
17837
}
17838
17838
}
17839
17839
@@ -18143,6 +18143,7 @@ function OutputStream(options) {
18143
18143
with_square : with_square,
18144
18144
add_mapping : add_mapping,
18145
18145
option : function(opt) { return options[opt] },
18146
+ comment_filter : comment_filter,
18146
18147
line : function() { return current_line },
18147
18148
col : function() { return current_col },
18148
18149
pos : function() { return current_pos },
@@ -18225,7 +18226,7 @@ function OutputStream(options) {
18225
18226
}));
18226
18227
}
18227
18228
18228
- comments = comments.filter(output.option("comments") , self);
18229
+ comments = comments.filter(output.comment_filter , self);
18229
18230
18230
18231
// Keep single line comments after nlb, after nlb
18231
18232
if (!output.option("beautify") && comments.length > 0 &&
@@ -20098,7 +20099,7 @@ merge(Compressor.prototype, {
20098
20099
(function (def){
20099
20100
var unary_bool = [ "!", "delete" ];
20100
20101
var binary_bool = [ "in", "instanceof", "==", "!=", "===", "!==", "<", "<=", ">=", ">" ];
20101
- def(AST_Node, function(){ return false } );
20102
+ def(AST_Node, return_false );
20102
20103
def(AST_UnaryPrefix, function(){
20103
20104
return member(this.operator, unary_bool);
20104
20105
});
@@ -20116,16 +20117,16 @@ merge(Compressor.prototype, {
20116
20117
def(AST_Seq, function(){
20117
20118
return this.cdr.is_boolean();
20118
20119
});
20119
- def(AST_True, function(){ return true } );
20120
- def(AST_False, function(){ return true } );
20120
+ def(AST_True, return_true );
20121
+ def(AST_False, return_true );
20121
20122
})(function(node, func){
20122
20123
node.DEFMETHOD("is_boolean", func);
20123
20124
});
20124
20125
20125
20126
// methods to determine if an expression has a string result type
20126
20127
(function (def){
20127
- def(AST_Node, function(){ return false } );
20128
- def(AST_String, function(){ return true } );
20128
+ def(AST_Node, return_false );
20129
+ def(AST_String, return_true );
20129
20130
def(AST_UnaryPrefix, function(){
20130
20131
return this.operator == "typeof";
20131
20132
});
@@ -20379,11 +20380,11 @@ merge(Compressor.prototype, {
20379
20380
20380
20381
// determine if expression has side effects
20381
20382
(function(def){
20382
- def(AST_Node, function(compressor){ return true } );
20383
+ def(AST_Node, return_true );
20383
20384
20384
- def(AST_EmptyStatement, function(compressor){ return false } );
20385
- def(AST_Constant, function(compressor){ return false } );
20386
- def(AST_This, function(compressor){ return false } );
20385
+ def(AST_EmptyStatement, return_false );
20386
+ def(AST_Constant, return_false );
20387
+ def(AST_This, return_false );
20387
20388
20388
20389
def(AST_Call, function(compressor){
20389
20390
var pure = compressor.option("pure_funcs");
@@ -20403,13 +20404,13 @@ merge(Compressor.prototype, {
20403
20404
def(AST_SimpleStatement, function(compressor){
20404
20405
return this.body.has_side_effects(compressor);
20405
20406
});
20406
- def(AST_Defun, function(compressor){ return true } );
20407
- def(AST_Function, function(compressor){ return false } );
20407
+ def(AST_Defun, return_true );
20408
+ def(AST_Function, return_false );
20408
20409
def(AST_Binary, function(compressor){
20409
20410
return this.left.has_side_effects(compressor)
20410
20411
|| this.right.has_side_effects(compressor);
20411
20412
});
20412
- def(AST_Assign, function(compressor){ return true } );
20413
+ def(AST_Assign, return_true );
20413
20414
def(AST_Conditional, function(compressor){
20414
20415
return this.condition.has_side_effects(compressor)
20415
20416
|| this.consequent.has_side_effects(compressor)
@@ -22172,7 +22173,7 @@ function SourceMap(options) {
22172
22173
var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
22173
22174
22174
22175
if (orig_map && Array.isArray(options.orig.sources)) {
22175
- options.orig.sources .forEach(function(source) {
22176
+ orig_map._sources.toArray() .forEach(function(source) {
22176
22177
var sourceContent = orig_map.sourceContentFor(source, true);
22177
22178
if (sourceContent) {
22178
22179
generator.setSourceContent(source, sourceContent);
@@ -22886,7 +22887,8 @@ function mangle_properties(ast, options) {
22886
22887
cache : null,
22887
22888
only_cache : false,
22888
22889
regex : null,
22889
- ignore_quoted : false
22890
+ ignore_quoted : false,
22891
+ debug : false
22890
22892
});
22891
22893
22892
22894
var reserved = options.reserved;
@@ -22904,6 +22906,15 @@ function mangle_properties(ast, options) {
22904
22906
var regex = options.regex;
22905
22907
var ignore_quoted = options.ignore_quoted;
22906
22908
22909
+ // note debug is either false (disabled), or a string of the debug suffix to use (enabled).
22910
+ // note debug may be enabled as an empty string, which is falsey. Also treat passing 'true'
22911
+ // the same as passing an empty string.
22912
+ var debug = (options.debug !== false);
22913
+ var debug_name_suffix;
22914
+ if (debug) {
22915
+ debug_name_suffix = (options.debug === true ? "" : options.debug);
22916
+ }
22917
+
22907
22918
var names_to_mangle = [];
22908
22919
var unmangleable = [];
22909
22920
var ignored = {};
@@ -22997,9 +23008,25 @@ function mangle_properties(ast, options) {
22997
23008
22998
23009
var mangled = cache.props.get(name);
22999
23010
if (!mangled) {
23000
- do {
23001
- mangled = base54(++cache.cname);
23002
- } while (!can_mangle(mangled));
23011
+ if (debug) {
23012
+ // debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
23013
+ var debug_mangled = "_$" + name + "$" + debug_name_suffix + "_";
23014
+
23015
+ if (can_mangle(debug_mangled) && !(ignore_quoted && debug_mangled in ignored)) {
23016
+ mangled = debug_mangled;
23017
+ }
23018
+ }
23019
+
23020
+ // either debug mode is off, or it is on and we could not use the mangled name
23021
+ if (!mangled) {
23022
+ // note can_mangle() does not check if the name collides with the 'ignored' set
23023
+ // (filled with quoted properties when ignore_quoted set). Make sure we add this
23024
+ // check so we don't collide with a quoted name.
23025
+ do {
23026
+ mangled = base54(++cache.cname);
23027
+ } while (!can_mangle(mangled) || (ignore_quoted && mangled in ignored));
23028
+ }
23029
+
23003
23030
cache.props.set(name, mangled);
23004
23031
}
23005
23032
return mangled;
@@ -23054,6 +23081,7 @@ exports.minify = function(files, options, name) {
23054
23081
options = defaults(options, {
23055
23082
spidermonkey : false,
23056
23083
outSourceMap : null,
23084
+ outFileName : null,
23057
23085
sourceRoot : null,
23058
23086
inSourceMap : null,
23059
23087
sourceMapUrl : null,
@@ -23133,7 +23161,8 @@ exports.minify = function(files, options, name) {
23133
23161
}
23134
23162
if (options.outSourceMap || options.sourceMapInline) {
23135
23163
output.source_map = SourceMap({
23136
- file: options.outSourceMap,
23164
+ // prefer outFileName, otherwise use outSourceMap without .map suffix
23165
+ file: options.outFileName || (typeof options.outSourceMap === 'string' ? options.outSourceMap.replace(/\.map$/i, '') : null),
23137
23166
orig: inMap,
23138
23167
root: options.sourceRoot
23139
23168
});
@@ -23220,7 +23249,7 @@ exports.describe_ast = function() {
23220
23249
return out + "";
23221
23250
};
23222
23251
23223
- exports. readNameCache = function(filename, key) {
23252
+ var readNameCache = function(filename, key) {
23224
23253
var cache = null;
23225
23254
if (filename) {
23226
23255
try {
@@ -23237,9 +23266,8 @@ exports.readNameCache = function(filename, key) {
23237
23266
}
23238
23267
return cache;
23239
23268
};
23240
- var readNameCache = exports.readNameCache;
23241
23269
23242
- exports. writeNameCache = function(filename, key, cache) {
23270
+ var writeNameCache = function(filename, key, cache) {
23243
23271
if (filename) {
23244
23272
var data;
23245
23273
try {
@@ -23255,7 +23283,6 @@ exports.writeNameCache = function(filename, key, cache) {
23255
23283
fs.writeFileSync(filename, JSON.stringify(data, null, 2), "utf8");
23256
23284
}
23257
23285
};
23258
- var writeNameCache = exports.writeNameCache;
23259
23286
23260
23287
23261
23288
});
@@ -28679,7 +28706,7 @@ function (args, quit, logger, build) {
28679
28706
} else if (commandOption === 'v') {
28680
28707
console.log('r.js: ' + version +
28681
28708
', RequireJS: ' + this.requirejsVars.require.version +
28682
- ', UglifyJS: 2.7.4 ');
28709
+ ', UglifyJS: 2.7.5 ');
28683
28710
} else if (commandOption === 'convert') {
28684
28711
loadLib();
28685
28712
0 commit comments