1
1
/**
2
- * @license r.js 2.3.2+ Sat, 01 Oct 2016 23:40:33 GMT Copyright jQuery Foundation and other contributors.
2
+ * @license r.js 2.3.2+ Sat, 29 Oct 2016 21:28:02 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+ Sat, 01 Oct 2016 23:40:33 GMT',
22
+ version = '2.3.2+ Sat, 29 Oct 2016 21:28:02 GMT',
23
23
jsSuffixRegExp = /\.js$/,
24
24
commandOption = '',
25
25
useLibLoaded = {},
@@ -16616,12 +16616,16 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
16616
16616
}
16617
16617
if (node instanceof AST_SymbolRef) {
16618
16618
var name = node.name;
16619
- if (name == "eval" && tw.parent() instanceof AST_Call) {
16619
+ var parent = tw.parent();
16620
+ if (name == "eval" && parent instanceof AST_Call) {
16620
16621
for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope) {
16621
16622
s.uses_eval = true;
16622
16623
}
16623
16624
}
16624
16625
var sym = node.scope.find_variable(name);
16626
+ if (node.scope instanceof AST_Lambda && name == "arguments") {
16627
+ node.scope.uses_arguments = true;
16628
+ }
16625
16629
if (!sym) {
16626
16630
var g;
16627
16631
if (globals.has(name)) {
@@ -16632,12 +16636,12 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
16632
16636
g.global = true;
16633
16637
globals.set(name, g);
16634
16638
}
16635
- node.thedef = g;
16636
- if (func && name == "arguments") {
16637
- func.uses_arguments = true ;
16638
- }
16639
- } else {
16640
- node.thedef = sym ;
16639
+ sym = g;
16640
+ }
16641
+ node.thedef = sym ;
16642
+ if (parent instanceof AST_Unary && (parent.operator === '++' || parent.operator === '--')
16643
+ || parent instanceof AST_Assign && parent.left === node) {
16644
+ sym.modified = true ;
16641
16645
}
16642
16646
node.reference();
16643
16647
return true;
@@ -17127,9 +17131,54 @@ function OutputStream(options) {
17127
17131
screw_ie8 : true,
17128
17132
preamble : null,
17129
17133
quote_style : 0,
17130
- keep_quoted_props: false
17134
+ keep_quoted_props: false,
17135
+ wrap_iife : false
17131
17136
}, true);
17132
17137
17138
+ // Convert comment option to RegExp if neccessary and set up comments filter
17139
+ if (typeof options.comments === "string" && /^\/.*\/[a-zA-Z]*$/.test(options.comments)) {
17140
+ var regex_pos = options.comments.lastIndexOf("/");
17141
+ options.comments = new RegExp(
17142
+ options.comments.substr(1, regex_pos - 1),
17143
+ options.comments.substr(regex_pos + 1)
17144
+ );
17145
+ }
17146
+ if (options.comments instanceof RegExp) {
17147
+ options.comments = (function(f) {
17148
+ return function(comment) {
17149
+ return comment.type == "comment5" || f.test(comment.value);
17150
+ }
17151
+ })(options.comments);
17152
+ }
17153
+ else if (typeof options.comments === "function") {
17154
+ options.comments = (function(f) {
17155
+ return function(comment) {
17156
+ return comment.type == "comment5" || f(this, comment);
17157
+ }
17158
+ })(options.comments);
17159
+ }
17160
+ else if (options.comments === "some") {
17161
+ options.comments = function(comment) {
17162
+ var text = comment.value;
17163
+ var type = comment.type;
17164
+ if (type == "comment2") {
17165
+ // multiline comment
17166
+ return /@preserve|@license|@cc_on/i.test(text);
17167
+ }
17168
+ return type == "comment5";
17169
+ }
17170
+ }
17171
+ else if (options.comments){ // NOTE includes "all" option
17172
+ options.comments = function() {
17173
+ return true;
17174
+ }
17175
+ } else {
17176
+ // Falsy case, so reject all comments, except shebangs
17177
+ options.comments = function(comment) {
17178
+ return comment.type == "comment5";
17179
+ }
17180
+ }
17181
+
17133
17182
var indentation = 0;
17134
17183
var current_col = 0;
17135
17184
var current_line = 1;
@@ -17495,7 +17544,7 @@ function OutputStream(options) {
17495
17544
17496
17545
AST_Node.DEFMETHOD("add_comments", function(output){
17497
17546
if (output._readonly) return;
17498
- var c = output.option("comments"), self = this;
17547
+ var self = this;
17499
17548
var start = self.start;
17500
17549
if (start && !start._comments_dumped) {
17501
17550
start._comments_dumped = true;
@@ -17518,19 +17567,7 @@ function OutputStream(options) {
17518
17567
}));
17519
17568
}
17520
17569
17521
- if (!c) {
17522
- comments = comments.filter(function(comment) {
17523
- return comment.type == "comment5";
17524
- });
17525
- } else if (c.test) {
17526
- comments = comments.filter(function(comment){
17527
- return comment.type == "comment5" || c.test(comment.value);
17528
- });
17529
- } else if (typeof c == "function") {
17530
- comments = comments.filter(function(comment){
17531
- return comment.type == "comment5" || c(self, comment);
17532
- });
17533
- }
17570
+ comments = comments.filter(output.option("comments"), self);
17534
17571
17535
17572
// Keep single line comments after nlb, after nlb
17536
17573
if (!output.option("beautify") && comments.length > 0 &&
@@ -17581,7 +17618,16 @@ function OutputStream(options) {
17581
17618
// a function expression needs parens around it when it's provably
17582
17619
// the first token to appear in a statement.
17583
17620
PARENS(AST_Function, function(output){
17584
- return first_in_statement(output);
17621
+ if (first_in_statement(output)) {
17622
+ return true;
17623
+ }
17624
+
17625
+ if (output.option('wrap_iife')) {
17626
+ var p = output.parent();
17627
+ return p instanceof AST_Call && p.expression === this;
17628
+ }
17629
+
17630
+ return false;
17585
17631
});
17586
17632
17587
17633
// same goes for an object literal, because otherwise it would be
@@ -18545,6 +18591,7 @@ function Compressor(options, false_by_default) {
18545
18591
if_return : !false_by_default,
18546
18592
join_vars : !false_by_default,
18547
18593
collapse_vars : false,
18594
+ reduce_vars : false,
18548
18595
cascade : !false_by_default,
18549
18596
side_effects : !false_by_default,
18550
18597
pure_getters : false,
@@ -19585,7 +19632,7 @@ merge(Compressor.prototype, {
19585
19632
this._evaluating = true;
19586
19633
try {
19587
19634
var d = this.definition();
19588
- if (d && d.constant && d.init) {
19635
+ if (d && ( d.constant || compressor.option("reduce_vars") && !d.modified) && d.init) {
19589
19636
return ev(d.init, compressor);
19590
19637
}
19591
19638
} finally {
@@ -20791,6 +20838,12 @@ merge(Compressor.prototype, {
20791
20838
// typeof always returns a non-empty string, thus it's
20792
20839
// always true in booleans
20793
20840
compressor.warn("Boolean expression always true [{file}:{line},{col}]", self.start);
20841
+ if (self.expression.has_side_effects(compressor)) {
20842
+ return make_node(AST_Seq, self, {
20843
+ car: self.expression,
20844
+ cdr: make_node(AST_True, self)
20845
+ });
20846
+ }
20794
20847
return make_node(AST_True, self);
20795
20848
}
20796
20849
if (e instanceof AST_Binary && self.operator == "!") {
@@ -20977,8 +21030,8 @@ merge(Compressor.prototype, {
20977
21030
case "+":
20978
21031
var ll = self.left.evaluate(compressor);
20979
21032
var rr = self.right.evaluate(compressor);
20980
- if ((ll.length > 1 && ll[0] instanceof AST_String && ll[1]) ||
20981
- (rr.length > 1 && rr[0] instanceof AST_String && rr[1])) {
21033
+ if ((ll.length > 1 && ll[0] instanceof AST_String && ll[1] && !self.right.has_side_effects(compressor) ) ||
21034
+ (rr.length > 1 && rr[0] instanceof AST_String && rr[1] && !self.left.has_side_effects(compressor) )) {
20982
21035
compressor.warn("+ in boolean context always true [{file}:{line},{col}]", self.start);
20983
21036
return make_node(AST_True, self);
20984
21037
}
@@ -21133,16 +21186,26 @@ merge(Compressor.prototype, {
21133
21186
});
21134
21187
21135
21188
var ASSIGN_OPS = [ '+', '-', '/', '*', '%', '>>', '<<', '>>>', '|', '^', '&' ];
21189
+ var ASSIGN_OPS_COMMUTATIVE = [ '*', '|', '^', '&' ];
21136
21190
OPT(AST_Assign, function(self, compressor){
21137
21191
self = self.lift_sequences(compressor);
21138
- if (self.operator == "="
21139
- && self.left instanceof AST_SymbolRef
21140
- && self.right instanceof AST_Binary
21141
- && self.right.left instanceof AST_SymbolRef
21142
- && self.right.left.name == self.left.name
21143
- && member(self.right.operator, ASSIGN_OPS)) {
21144
- self.operator = self.right.operator + "=";
21145
- self.right = self.right.right;
21192
+ if (self.operator == "=" && self.left instanceof AST_SymbolRef && self.right instanceof AST_Binary) {
21193
+ // x = expr1 OP expr2
21194
+ if (self.right.left instanceof AST_SymbolRef
21195
+ && self.right.left.name == self.left.name
21196
+ && member(self.right.operator, ASSIGN_OPS)) {
21197
+ // x = x - 2 ---> x -= 2
21198
+ self.operator = self.right.operator + "=";
21199
+ self.right = self.right.right;
21200
+ }
21201
+ else if (self.right.right instanceof AST_SymbolRef
21202
+ && self.right.right.name == self.left.name
21203
+ && member(self.right.operator, ASSIGN_OPS_COMMUTATIVE)
21204
+ && !self.right.left.has_side_effects(compressor)) {
21205
+ // x = 2 & x ---> x &= 2
21206
+ self.operator = self.right.operator + "=";
21207
+ self.right = self.right.left;
21208
+ }
21146
21209
}
21147
21210
return self;
21148
21211
});
@@ -22336,6 +22399,7 @@ exports.minify = function(files, options, name) {
22336
22399
sourceRoot : null,
22337
22400
inSourceMap : null,
22338
22401
sourceMapUrl : null,
22402
+ sourceMapInline : false,
22339
22403
fromString : false,
22340
22404
warnings : false,
22341
22405
mangle : {},
@@ -22409,7 +22473,7 @@ exports.minify = function(files, options, name) {
22409
22473
if (typeof options.inSourceMap == "string") {
22410
22474
inMap = JSON.parse(rjsFile.readFile(options.inSourceMap, "utf8"));
22411
22475
}
22412
- if (options.outSourceMap) {
22476
+ if (options.outSourceMap || options.sourceMapInline ) {
22413
22477
output.source_map = SourceMap({
22414
22478
file: options.outSourceMap,
22415
22479
orig: inMap,
@@ -22430,16 +22494,19 @@ exports.minify = function(files, options, name) {
22430
22494
var stream = OutputStream(output);
22431
22495
toplevel.print(stream);
22432
22496
22433
- var mappingUrlPrefix = "\n//# sourceMappingURL=";
22434
- if (options.outSourceMap && typeof options.outSourceMap === "string" && options.sourceMapUrl !== false) {
22435
- stream += mappingUrlPrefix + (typeof options.sourceMapUrl === "string" ? options.sourceMapUrl : options.outSourceMap);
22436
- }
22437
22497
22438
22498
var source_map = output.source_map;
22439
22499
if (source_map) {
22440
22500
source_map = source_map + "";
22441
22501
}
22442
22502
22503
+ var mappingUrlPrefix = "\n//# sourceMappingURL=";
22504
+ if (options.sourceMapInline) {
22505
+ stream += mappingUrlPrefix + "data:application/json;charset=utf-8;base64," + new Buffer(source_map).toString("base64");
22506
+ } else if (options.outSourceMap && typeof options.outSourceMap === "string" && options.sourceMapUrl !== false) {
22507
+ stream += mappingUrlPrefix + (typeof options.sourceMapUrl === "string" ? options.sourceMapUrl : options.outSourceMap);
22508
+ }
22509
+
22443
22510
return {
22444
22511
code : stream + "",
22445
22512
map : source_map
@@ -22495,6 +22562,44 @@ exports.describe_ast = function() {
22495
22562
return out + "";
22496
22563
};
22497
22564
22565
+ exports.readNameCache = function(filename, key) {
22566
+ var cache = null;
22567
+ if (filename) {
22568
+ try {
22569
+ var cache = rjsFile.readFile(filename, "utf8");
22570
+ cache = JSON.parse(cache)[key];
22571
+ if (!cache) throw "init";
22572
+ cache.props = Dictionary.fromObject(cache.props);
22573
+ } catch(ex) {
22574
+ cache = {
22575
+ cname: -1,
22576
+ props: new Dictionary()
22577
+ };
22578
+ }
22579
+ }
22580
+ return cache;
22581
+ };
22582
+ var readNameCache = exports.readNameCache;
22583
+
22584
+ exports.writeNameCache = function(filename, key, cache) {
22585
+ if (filename) {
22586
+ var data;
22587
+ try {
22588
+ data = rjsFile.readFile(filename, "utf8");
22589
+ data = JSON.parse(data);
22590
+ } catch(ex) {
22591
+ data = {};
22592
+ }
22593
+ data[key] = {
22594
+ cname: cache.cname,
22595
+ props: cache.props.toObject()
22596
+ };
22597
+ fs.writeFileSync(filename, JSON.stringify(data, null, 2), "utf8");
22598
+ }
22599
+ };
22600
+ var writeNameCache = exports.writeNameCache;
22601
+
22602
+
22498
22603
});
22499
22604
/*jslint plusplus: true */
22500
22605
/*global define: false */
@@ -27917,7 +28022,7 @@ function (args, quit, logger, build) {
27917
28022
} else if (commandOption === 'v') {
27918
28023
console.log('r.js: ' + version +
27919
28024
', RequireJS: ' + this.requirejsVars.require.version +
27920
- ', UglifyJS: 2.7.3 ');
28025
+ ', UglifyJS: 2.7.4 ');
27921
28026
} else if (commandOption === 'convert') {
27922
28027
loadLib();
27923
28028
0 commit comments