Skip to content

Commit 1f463aa

Browse files
committed
snapshot
1 parent 4b3f5c5 commit 1f463aa

File tree

1 file changed

+147
-42
lines changed

1 file changed

+147
-42
lines changed

dist/r.js

Lines changed: 147 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
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.
33
* Released under MIT license, http://github.com/requirejs/r.js/LICENSE
44
*/
55

@@ -19,7 +19,7 @@ var requirejs, require, define, xpcUtil;
1919
(function (console, args, readFileFunc) {
2020
var fileName, env, fs, vm, path, exec, rhinoContext, dir, nodeRequire,
2121
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',
2323
jsSuffixRegExp = /\.js$/,
2424
commandOption = '',
2525
useLibLoaded = {},
@@ -16616,12 +16616,16 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
1661616616
}
1661716617
if (node instanceof AST_SymbolRef) {
1661816618
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) {
1662016621
for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope) {
1662116622
s.uses_eval = true;
1662216623
}
1662316624
}
1662416625
var sym = node.scope.find_variable(name);
16626+
if (node.scope instanceof AST_Lambda && name == "arguments") {
16627+
node.scope.uses_arguments = true;
16628+
}
1662516629
if (!sym) {
1662616630
var g;
1662716631
if (globals.has(name)) {
@@ -16632,12 +16636,12 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
1663216636
g.global = true;
1663316637
globals.set(name, g);
1663416638
}
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;
1664116645
}
1664216646
node.reference();
1664316647
return true;
@@ -17127,9 +17131,54 @@ function OutputStream(options) {
1712717131
screw_ie8 : true,
1712817132
preamble : null,
1712917133
quote_style : 0,
17130-
keep_quoted_props: false
17134+
keep_quoted_props: false,
17135+
wrap_iife : false
1713117136
}, true);
1713217137

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+
1713317182
var indentation = 0;
1713417183
var current_col = 0;
1713517184
var current_line = 1;
@@ -17495,7 +17544,7 @@ function OutputStream(options) {
1749517544

1749617545
AST_Node.DEFMETHOD("add_comments", function(output){
1749717546
if (output._readonly) return;
17498-
var c = output.option("comments"), self = this;
17547+
var self = this;
1749917548
var start = self.start;
1750017549
if (start && !start._comments_dumped) {
1750117550
start._comments_dumped = true;
@@ -17518,19 +17567,7 @@ function OutputStream(options) {
1751817567
}));
1751917568
}
1752017569

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);
1753417571

1753517572
// Keep single line comments after nlb, after nlb
1753617573
if (!output.option("beautify") && comments.length > 0 &&
@@ -17581,7 +17618,16 @@ function OutputStream(options) {
1758117618
// a function expression needs parens around it when it's provably
1758217619
// the first token to appear in a statement.
1758317620
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;
1758517631
});
1758617632

1758717633
// same goes for an object literal, because otherwise it would be
@@ -18545,6 +18591,7 @@ function Compressor(options, false_by_default) {
1854518591
if_return : !false_by_default,
1854618592
join_vars : !false_by_default,
1854718593
collapse_vars : false,
18594+
reduce_vars : false,
1854818595
cascade : !false_by_default,
1854918596
side_effects : !false_by_default,
1855018597
pure_getters : false,
@@ -19585,7 +19632,7 @@ merge(Compressor.prototype, {
1958519632
this._evaluating = true;
1958619633
try {
1958719634
var d = this.definition();
19588-
if (d && d.constant && d.init) {
19635+
if (d && (d.constant || compressor.option("reduce_vars") && !d.modified) && d.init) {
1958919636
return ev(d.init, compressor);
1959019637
}
1959119638
} finally {
@@ -20791,6 +20838,12 @@ merge(Compressor.prototype, {
2079120838
// typeof always returns a non-empty string, thus it's
2079220839
// always true in booleans
2079320840
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+
}
2079420847
return make_node(AST_True, self);
2079520848
}
2079620849
if (e instanceof AST_Binary && self.operator == "!") {
@@ -20977,8 +21030,8 @@ merge(Compressor.prototype, {
2097721030
case "+":
2097821031
var ll = self.left.evaluate(compressor);
2097921032
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))) {
2098221035
compressor.warn("+ in boolean context always true [{file}:{line},{col}]", self.start);
2098321036
return make_node(AST_True, self);
2098421037
}
@@ -21133,16 +21186,26 @@ merge(Compressor.prototype, {
2113321186
});
2113421187

2113521188
var ASSIGN_OPS = [ '+', '-', '/', '*', '%', '>>', '<<', '>>>', '|', '^', '&' ];
21189+
var ASSIGN_OPS_COMMUTATIVE = [ '*', '|', '^', '&' ];
2113621190
OPT(AST_Assign, function(self, compressor){
2113721191
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+
}
2114621209
}
2114721210
return self;
2114821211
});
@@ -22336,6 +22399,7 @@ exports.minify = function(files, options, name) {
2233622399
sourceRoot : null,
2233722400
inSourceMap : null,
2233822401
sourceMapUrl : null,
22402+
sourceMapInline : false,
2233922403
fromString : false,
2234022404
warnings : false,
2234122405
mangle : {},
@@ -22409,7 +22473,7 @@ exports.minify = function(files, options, name) {
2240922473
if (typeof options.inSourceMap == "string") {
2241022474
inMap = JSON.parse(rjsFile.readFile(options.inSourceMap, "utf8"));
2241122475
}
22412-
if (options.outSourceMap) {
22476+
if (options.outSourceMap || options.sourceMapInline) {
2241322477
output.source_map = SourceMap({
2241422478
file: options.outSourceMap,
2241522479
orig: inMap,
@@ -22430,16 +22494,19 @@ exports.minify = function(files, options, name) {
2243022494
var stream = OutputStream(output);
2243122495
toplevel.print(stream);
2243222496

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-
}
2243722497

2243822498
var source_map = output.source_map;
2243922499
if (source_map) {
2244022500
source_map = source_map + "";
2244122501
}
2244222502

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+
2244322510
return {
2244422511
code : stream + "",
2244522512
map : source_map
@@ -22495,6 +22562,44 @@ exports.describe_ast = function() {
2249522562
return out + "";
2249622563
};
2249722564

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+
2249822603
});
2249922604
/*jslint plusplus: true */
2250022605
/*global define: false */
@@ -27917,7 +28022,7 @@ function (args, quit, logger, build) {
2791728022
} else if (commandOption === 'v') {
2791828023
console.log('r.js: ' + version +
2791928024
', RequireJS: ' + this.requirejsVars.require.version +
27920-
', UglifyJS: 2.7.3');
28025+
', UglifyJS: 2.7.4');
2792128026
} else if (commandOption === 'convert') {
2792228027
loadLib();
2792328028

0 commit comments

Comments
 (0)