bin/r.js in requirejs-rails-0.9.2 vs bin/r.js in requirejs-rails-0.9.3
- old
+ new
@@ -1,7 +1,7 @@
/**
- * @license r.js 2.1.10 Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
+ * @license r.js 2.1.11 Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/requirejs for details
*/
/*
@@ -18,11 +18,11 @@
var requirejs, require, define, xpcUtil;
(function (console, args, readFileFunc) {
var fileName, env, fs, vm, path, exec, rhinoContext, dir, nodeRequire,
nodeDefine, exists, reqMain, loadedOptimizedLib, existsForNode, Cc, Ci,
- version = '2.1.10',
+ version = '2.1.11',
jsSuffixRegExp = /\.js$/,
commandOption = '',
useLibLoaded = {},
//Used by jslib/rhino/args.js
rhinoArgs = args,
@@ -236,11 +236,11 @@
};
}
}
/** vim: et:ts=4:sw=4:sts=4
- * @license RequireJS 2.1.10 Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
+ * @license RequireJS 2.1.11 Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/requirejs for details
*/
//Not using strict: uneven strict support in browsers, #392, and causes
//problems with requirejs.exec()/transpiler plugins that may not be strict.
@@ -249,11 +249,11 @@
(function (global) {
var req, s, head, baseElement, dataMain, src,
interactiveScript, currentlyAddingScript, mainScript, subPath,
- version = '2.1.10',
+ version = '2.1.11',
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
jsSuffixRegExp = /\.js$/,
currDirRegExp = /^\.\//,
op = Object.prototype,
@@ -378,11 +378,11 @@
function defaultOnError(err) {
throw err;
}
- //Allow getting a global that expressed in
+ //Allow getting a global that is expressed in
//dot notation, like 'a.b.c'.
function getGlobal(value) {
if (!value) {
return value;
}
@@ -804,11 +804,11 @@
},
'exports': function (mod) {
mod.usingExports = true;
if (mod.map.isDefine) {
if (mod.exports) {
- return mod.exports;
+ return (defined[mod.map.id] = mod.exports);
} else {
return (mod.exports = defined[mod.map.id] = {});
}
}
},
@@ -820,11 +820,11 @@
id: mod.map.id,
uri: mod.map.url,
config: function () {
return getOwn(config.config, mod.map.id) || {};
},
- exports: handlers.exports(mod)
+ exports: mod.exports || (mod.exports = {})
});
}
}
};
@@ -1739,11 +1739,11 @@
},
/**
* Called to enable a module if it is still in the registry
* awaiting enablement. A second arg, parent, the parent module,
- * is passed in for context, when this method is overriden by
+ * is passed in for context, when this method is overridden by
* the optimizer. Not shown here to keep code compact.
*/
enable: function (depMap) {
var mod = getOwn(registry, depMap.id);
if (mod) {
@@ -9681,11 +9681,11 @@
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS†AND ANY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
@@ -11132,11 +11132,11 @@
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS†AND ANY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
@@ -13837,10 +13837,11 @@
this.__originalMappings.push(mapping);
}
}
}
+ this.__generatedMappings.sort(util.compareByGeneratedPositions);
this.__originalMappings.sort(util.compareByOriginalPositions);
};
/**
* Find the mapping that best matches the hypothetical "needle" mapping that
@@ -14307,11 +14308,11 @@
}
else {
throw new Error('Invalid mapping: ' + JSON.stringify({
generated: aGenerated,
source: aSource,
- orginal: aOriginal,
+ original: aOriginal,
name: aName
}));
}
};
@@ -15050,11 +15051,11 @@
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS†AND ANY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
@@ -15353,11 +15354,11 @@
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS†AND ANY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
@@ -15712,15 +15713,15 @@
}, AST_Lambda);
/* -----[ JUMPS ]----- */
var AST_Jump = DEFNODE("Jump", null, {
- $documentation: "Base class for “jumps†(for now that's `return`, `throw`, `break` and `continue`)"
+ $documentation: "Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)"
}, AST_Statement);
var AST_Exit = DEFNODE("Exit", "value", {
- $documentation: "Base class for “exits†(`return` and `throw`)",
+ $documentation: "Base class for “exits” (`return` and `throw`)",
$propdoc: {
value: "[AST_Node?] the value returned or thrown by this statement; could be null for AST_Return"
},
_walk: function(visitor) {
return visitor._visit(this, this.value && function(){
@@ -15777,11 +15778,11 @@
/* -----[ SWITCH ]----- */
var AST_Switch = DEFNODE("Switch", "expression", {
$documentation: "A `switch` statement",
$propdoc: {
- expression: "[AST_Node] the `switch` “discriminantâ€"
+ expression: "[AST_Node] the `switch` “discriminant”"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.expression._walk(visitor);
walk_body(this, visitor);
@@ -15964,11 +15965,11 @@
});
var AST_PropAccess = DEFNODE("PropAccess", "expression property", {
$documentation: "Base class for property access expressions, i.e. `a.foo` or `a[\"foo\"]`",
$propdoc: {
- expression: "[AST_Node] the “container†expression",
+ expression: "[AST_Node] the “container” expression",
property: "[AST_Node|string] the property to access. For AST_Dot this is always a plain string, while for AST_Sub it's an arbitrary AST_Node"
}
});
var AST_Dot = DEFNODE("Dot", null, {
@@ -16041,11 +16042,11 @@
});
}
});
var AST_Assign = DEFNODE("Assign", null, {
- $documentation: "An assignment expression — `a = b + 5`",
+ $documentation: "An assignment expression — `a = b + 5`",
}, AST_Binary);
/* -----[ LITERALS ]----- */
var AST_Array = DEFNODE("Array", "elements", {
@@ -16339,11 +16340,11 @@
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS†AND ANY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
@@ -16358,11 +16359,11 @@
"use strict";
var KEYWORDS = 'break case catch const continue debugger default delete do else finally for function if in instanceof new return switch throw try typeof var void while with';
var KEYWORDS_ATOM = 'false null true';
-var RESERVED_WORDS = 'abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized this throws transient volatile'
+var RESERVED_WORDS = 'abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized this throws transient volatile yield'
+ " " + KEYWORDS_ATOM + " " + KEYWORDS;
var KEYWORDS_BEFORE_EXPRESSION = 'return new delete throw else case';
KEYWORDS = makePredicate(KEYWORDS);
RESERVED_WORDS = makePredicate(RESERVED_WORDS);
@@ -16993,11 +16994,11 @@
function expect_token(type, val) {
if (is(type, val)) {
return next();
}
- token_error(S.token, "Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»");
+ token_error(S.token, "Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»");
};
function expect(punc) { return expect_token("punc", punc); };
function can_insert_semicolon() {
@@ -17693,11 +17694,11 @@
return new AST_Conditional({
start : start,
condition : expr,
consequent : yes,
alternative : expression(false, no_in),
- end : peek()
+ end : prev()
});
}
return expr;
};
@@ -17796,11 +17797,11 @@
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS†AND ANY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
@@ -18015,11 +18016,11 @@
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS†AND ANY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
@@ -18579,11 +18580,11 @@
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS†AND ANY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
@@ -18599,26 +18600,27 @@
"use strict";
function OutputStream(options) {
options = defaults(options, {
- indent_start : 0,
- indent_level : 4,
- quote_keys : false,
- space_colon : true,
- ascii_only : false,
- inline_script : false,
- width : 80,
- max_line_len : 32000,
- beautify : false,
- source_map : null,
- bracketize : false,
- semicolons : true,
- comments : false,
- preserve_line : false,
- screw_ie8 : false,
- preamble : null,
+ indent_start : 0,
+ indent_level : 4,
+ quote_keys : false,
+ space_colon : true,
+ ascii_only : false,
+ unescape_regexps : false,
+ inline_script : false,
+ width : 80,
+ max_line_len : 32000,
+ beautify : false,
+ source_map : null,
+ bracketize : false,
+ semicolons : true,
+ comments : false,
+ preserve_line : false,
+ screw_ie8 : false,
+ preamble : null,
}, true);
var indentation = 0;
var current_col = 0;
var current_line = 1;
@@ -18838,11 +18840,11 @@
current_line, current_col,
token.line, token.col,
(!name && token.type == "name") ? token.value : name
);
} catch(ex) {
- AST_Node.warn("Couldn't figure out mapping for {file}:{line},{col} → {cline},{ccol} [{name}]", {
+ AST_Node.warn("Couldn't figure out mapping for {file}:{line},{col} → {cline},{ccol} [{name}]", {
file: token.file,
line: token.line,
col: token.col,
cline: current_line,
ccol: current_col,
@@ -18939,17 +18941,24 @@
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
- // if this node is `return` or `throw`, we cannot allow comments before
- // the returned or thrown value.
- if (self instanceof AST_Exit && self.value
- && self.value.start.comments_before
- && self.value.start.comments_before.length > 0) {
- comments = comments.concat(self.value.start.comments_before);
- self.value.start.comments_before = [];
+ // 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);
@@ -19009,11 +19018,11 @@
var p = output.parent();
return p instanceof AST_Call // (foo, bar)() or foo(1, (2, 3), 4)
|| p instanceof AST_Unary // !(foo, bar, baz)
|| p instanceof AST_Binary // 1 + (2, 3) + 4 ==> 8
|| p instanceof AST_VarDef // var a = (1, 2), b = a + a; ==> b == 4
- || p instanceof AST_Dot // (1, {foo:2}).foo ==> 2
+ || p instanceof AST_PropAccess // (1, {foo:2}).foo or (1, {foo:2})["foo"] ==> 2
|| p instanceof AST_Array // [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ]
|| p instanceof AST_ObjectProperty // { foo: (1, 2) }.foo ==> 2
|| p instanceof AST_Conditional /* (false, true) ? (a = 10, b = 20) : (c = 30)
* ==> 20 (side effect, set a := 10 and b := 20) */
;
@@ -19096,23 +19105,23 @@
return true;
});
function assign_and_conditional_paren_rules(output) {
var p = output.parent();
- // !(a = false) → true
+ // !(a = false) → true
if (p instanceof AST_Unary)
return true;
- // 1 + (a = 2) + 3 → 6, side effect setting a = 2
+ // 1 + (a = 2) + 3 → 6, side effect setting a = 2
if (p instanceof AST_Binary && !(p instanceof AST_Assign))
return true;
- // (a = func)() —or— new (a = Object)()
+ // (a = func)() —or— new (a = Object)()
if (p instanceof AST_Call && p.expression === this)
return true;
// (a = foo) ? bar : baz
if (p instanceof AST_Conditional && p.condition === this)
return true;
- // (a = foo)["prop"] —or— (a = foo).prop
+ // (a = foo)["prop"] —or— (a = foo).prop
if (p instanceof AST_PropAccess && p.expression === this)
return true;
};
PARENS(AST_Assign, assign_and_conditional_paren_rules);
@@ -19664,14 +19673,51 @@
output.print_string(self.getValue());
});
DEFPRINT(AST_Number, function(self, output){
output.print(make_num(self.getValue()));
});
+
+ function regexp_safe_literal(code) {
+ return [
+ 0x5c , // \
+ 0x2f , // /
+ 0x2e , // .
+ 0x2b , // +
+ 0x2a , // *
+ 0x3f , // ?
+ 0x28 , // (
+ 0x29 , // )
+ 0x5b , // [
+ 0x5d , // ]
+ 0x7b , // {
+ 0x7d , // }
+ 0x24 , // $
+ 0x5e , // ^
+ 0x3a , // :
+ 0x7c , // |
+ 0x21 , // !
+ 0x0a , // \n
+ 0x0d , // \r
+ 0x00 , // \0
+ 0xfeff , // Unicode BOM
+ 0x2028 , // unicode "line separator"
+ 0x2029 , // unicode "paragraph separator"
+ ].indexOf(code) < 0;
+ };
+
DEFPRINT(AST_RegExp, function(self, output){
var str = self.getValue().toString();
- if (output.option("ascii_only"))
+ if (output.option("ascii_only")) {
str = output.to_ascii(str);
+ } else if (output.option("unescape_regexps")) {
+ str = str.split("\\\\").map(function(str){
+ return str.replace(/\\u[0-9a-fA-F]{4}|\\x[0-9a-fA-F]{2}/g, function(s){
+ var code = parseInt(s.substr(2), 16);
+ return regexp_safe_literal(code) ? String.fromCharCode(code) : s;
+ });
+ }).join("\\\\");
+ }
output.print(str);
var p = output.parent();
if (p instanceof AST_Binary && /^in/.test(p.operator) && p.left === self)
output.print(" ");
});
@@ -19835,11 +19881,11 @@
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS†AND ANY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
@@ -19880,10 +19926,11 @@
pure_getters : false,
pure_funcs : null,
negate_iife : !false_by_default,
screw_ie8 : false,
drop_console : false,
+ angular : false,
warnings : true,
global_defs : {}
}, true);
};
@@ -20007,10 +20054,13 @@
function tighten_body(statements, compressor) {
var CHANGED;
do {
CHANGED = false;
+ if (compressor.option("angular")) {
+ statements = process_for_angular(statements);
+ }
statements = eliminate_spurious_blocks(statements);
if (compressor.option("dead_code")) {
statements = eliminate_dead_code(statements, compressor);
}
if (compressor.option("if_return")) {
@@ -20028,10 +20078,54 @@
negate_iifes(statements, compressor);
}
return statements;
+ function process_for_angular(statements) {
+ function make_injector(func, name) {
+ return make_node(AST_SimpleStatement, func, {
+ body: make_node(AST_Assign, func, {
+ operator: "=",
+ left: make_node(AST_Dot, name, {
+ expression: make_node(AST_SymbolRef, name, name),
+ property: "$inject"
+ }),
+ right: make_node(AST_Array, func, {
+ elements: func.argnames.map(function(sym){
+ return make_node(AST_String, sym, { value: sym.name });
+ })
+ })
+ })
+ });
+ }
+ return statements.reduce(function(a, stat){
+ a.push(stat);
+ var token = stat.start;
+ var comments = token.comments_before;
+ if (comments && comments.length > 0) {
+ var last = comments.pop();
+ if (/@ngInject/.test(last.value)) {
+ // case 1: defun
+ if (stat instanceof AST_Defun) {
+ a.push(make_injector(stat, stat.name));
+ }
+ else if (stat instanceof AST_Definitions) {
+ stat.definitions.forEach(function(def){
+ if (def.value && def.value instanceof AST_Lambda) {
+ a.push(make_injector(def.value, def.name));
+ }
+ });
+ }
+ else {
+ compressor.warn("Unknown statement marked with @ngInject [{file}:{line},{col}]", token);
+ }
+ }
+ }
+ return a;
+ }, []);
+ }
+
function eliminate_spurious_blocks(statements) {
var seen_dirs = [];
return statements.reduce(function(a, stat){
if (stat instanceof AST_BlockStatement) {
CHANGED = true;
@@ -21162,11 +21256,11 @@
OPT(AST_If, function(self, compressor){
if (!compressor.option("conditionals")) return self;
// if condition can be statically determined, warn and drop
// one of the blocks. note, statically determined implies
- // “has no side effectsâ€; also it doesn't work for cases like
+ // “has no side effects”; also it doesn't work for cases like
// `x && true`, though it probably should.
var cond = self.condition.evaluate(compressor);
self.condition = cond[0];
if (cond.length > 1) {
if (cond[1]) {
@@ -21645,10 +21739,22 @@
&& !self.cdr.has_side_effects(compressor)
&& self.car.equivalent_to(self.cdr)) {
return self.car;
}
}
+ if (self.cdr instanceof AST_UnaryPrefix
+ && self.cdr.operator == "void"
+ && !self.cdr.expression.has_side_effects(compressor)) {
+ self.cdr.operator = self.car;
+ return self.cdr;
+ }
+ if (self.cdr instanceof AST_Undefined) {
+ return make_node(AST_UnaryPrefix, self, {
+ operator : "void",
+ expression : self.car
+ });
+ }
return self;
});
AST_Unary.DEFMETHOD("lift_sequences", function(compressor){
if (compressor.option("sequences")) {
@@ -22016,20 +22122,39 @@
* Stuff like this:
* if (foo) exp = something; else exp = something_else;
* ==>
* exp = foo ? something : something_else;
*/
- self = make_node(AST_Assign, self, {
+ return make_node(AST_Assign, self, {
operator: consequent.operator,
left: consequent.left,
right: make_node(AST_Conditional, self, {
condition: self.condition,
consequent: consequent.right,
alternative: alternative.right
})
});
}
+ if (consequent instanceof AST_Call
+ && alternative.TYPE === consequent.TYPE
+ && consequent.args.length == alternative.args.length
+ && consequent.expression.equivalent_to(alternative.expression)) {
+ if (consequent.args.length == 0) {
+ return make_node(AST_Seq, self, {
+ car: self.condition,
+ cdr: consequent
+ });
+ }
+ if (consequent.args.length == 1) {
+ consequent.args[0] = make_node(AST_Conditional, self, {
+ condition: self.condition,
+ consequent: consequent.args[0],
+ alternative: alternative.args[0]
+ });
+ return consequent;
+ }
+ }
return self;
});
OPT(AST_Boolean, function(self, compressor){
if (compressor.option("booleans")) {
@@ -22065,10 +22190,16 @@
return make_node(AST_Dot, self, {
expression : self.expression,
property : prop
});
}
+ var v = parseFloat(prop);
+ if (!isNaN(v) && v.toString() == prop) {
+ self.property = make_node(AST_Number, self.property, {
+ value: v
+ });
+ }
}
return self;
});
function literals_in_boolean_context(self, compressor) {
@@ -22109,11 +22240,11 @@
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS†AND ANY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
@@ -22194,11 +22325,11 @@
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS†AND ANY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
@@ -22437,35 +22568,40 @@
})();
AST_Node.warn_function = function(txt) { logger.error("uglifyjs2 WARN: " + txt); };
exports.minify = function(files, options, name) {
options = defaults(options, {
+ spidermonkey : false,
outSourceMap : null,
sourceRoot : null,
inSourceMap : null,
fromString : false,
warnings : false,
mangle : {},
output : null,
compress : {}
});
- if (typeof files == "string")
- files = [ files ];
-
base54.reset();
// 1. parse
var toplevel = null;
- files.forEach(function(file){
- var code = options.fromString
- ? file
- : rjsFile.readFile(file, "utf8");
- toplevel = parse(code, {
- filename: options.fromString ? name : file,
- toplevel: toplevel
+
+ if (options.spidermonkey) {
+ toplevel = AST_Node.from_mozilla_ast(files);
+ } else {
+ if (typeof files == "string")
+ files = [ files ];
+ files.forEach(function(file){
+ var code = options.fromString
+ ? file
+ : rjsFile.readFile(file, "utf8");
+ toplevel = parse(code, {
+ filename: options.fromString ? name : file,
+ toplevel: toplevel
+ });
});
- });
+ }
// 2. compress
if (options.compress) {
var compress = { warnings: options.warnings };
merge(compress, options.compress);
@@ -22622,11 +22758,11 @@
}
for (key in object) {
if (object.hasOwnProperty(key)) {
child = object[key];
if (typeof child === 'object' && child !== null) {
- traverse(child, visitor);
+ traverseBroad(child, visitor);
}
}
}
}
@@ -23513,11 +23649,20 @@
var astRoot, contentLines, modLine,
foundAnon,
scanCount = 0,
scanReset = false,
- defineInfos = [];
+ defineInfos = [],
+ applySourceUrl = function (contents) {
+ if (options.useSourceUrl) {
+ contents = 'eval("' + lang.jsEscape(contents) +
+ '\\n//# sourceURL=' + (path.indexOf('/') === 0 ? '' : '/') +
+ path +
+ '");\n';
+ }
+ return contents;
+ };
try {
astRoot = esprima.parse(contents, {
loc: true
});
@@ -23526,11 +23671,11 @@
e.toString());
return contents;
}
//Find the define calls and their position in the files.
- parse.traverseBroad(astRoot, function (node) {
+ parse.traverse(astRoot, function (node) {
var args, firstArg, firstArgLoc, factoryNode,
needsId, depAction, foundId, init,
sourceUrlData, range,
namespaceExists = false;
@@ -23679,12 +23824,13 @@
}
}
}
});
+
if (!defineInfos.length) {
- return contents;
+ return applySourceUrl(contents);
}
//Reverse the matches, need to start from the bottom of
//the file to modify it, so that the ranges are still true
//further up.
@@ -23752,18 +23898,11 @@
}
});
contents = contentLines.join('\n');
- if (options.useSourceUrl) {
- contents = 'eval("' + lang.jsEscape(contents) +
- '\\n//# sourceURL=' + (path.indexOf('/') === 0 ? '' : '/') +
- path +
- '");\n';
- }
-
- return contents;
+ return applySourceUrl(contents);
},
/**
* Modify the contents of a require.config/requirejs.config call. This
* call will LOSE any existing comments that are in the config string.
@@ -25020,22 +25159,49 @@
//Override the shim exports function generator to just
//spit out strings that can be used in the stringified
//build output.
context.makeShimExports = function (value) {
- function fn() {
- return '(function (global) {\n' +
- ' return function () {\n' +
- ' var ret, fn;\n' +
- (value.init ?
- (' fn = ' + value.init.toString() + ';\n' +
- ' ret = fn.apply(global, arguments);\n') : '') +
- (value.exports ?
- ' return ret || global.' + value.exports + ';\n' :
- ' return ret;\n') +
- ' };\n' +
- '}(this))';
+ var fn;
+ if (context.config.wrapShim) {
+ fn = function () {
+ var str = 'return ';
+ // If specifies an export that is just a global
+ // name, no dot for a `this.` and such, then also
+ // attach to the global, for `var a = {}` files
+ // where the function closure would hide that from
+ // the global object.
+ if (value.exports && value.exports.indexOf('.') === -1) {
+ str += 'root.' + value.exports + ' = ';
+ }
+
+ if (value.init) {
+ str += '(' + value.init.toString() + '.apply(this, arguments))';
+ }
+ if (value.init && value.exports) {
+ str += ' || ';
+ }
+ if (value.exports) {
+ str += value.exports;
+ }
+ str += ';';
+ return str;
+ };
+ } else {
+ fn = function () {
+ return '(function (global) {\n' +
+ ' return function () {\n' +
+ ' var ret, fn;\n' +
+ (value.init ?
+ (' fn = ' + value.init.toString() + ';\n' +
+ ' ret = fn.apply(global, arguments);\n') : '') +
+ (value.exports ?
+ ' return ret || global.' + value.exports + ';\n' :
+ ' return ret;\n') +
+ ' };\n' +
+ '}(this))';
+ };
}
return fn;
};
@@ -26609,10 +26775,13 @@
});
//Set final output dir
if (hasProp(config, "baseUrl")) {
if (config.appDir) {
+ if (!config.originalBaseUrl) {
+ throw new Error('Please set a baseUrl in the build config');
+ }
config.dirBaseUrl = build.makeAbsPath(config.originalBaseUrl, config.dir);
} else {
config.dirBaseUrl = config.dir || config.baseUrl;
}
//Make sure dirBaseUrl ends in a slash, since it is
@@ -26664,19 +26833,24 @@
if (config.dir) {
// Make sure the output dir is not set to a parent of the
// source dir or the same dir, as it will result in source
// code deletion.
- if (config.dir === config.baseUrl ||
+ if (!config.allowSourceOverwrites && (config.dir === config.baseUrl ||
config.dir === config.appDir ||
(config.baseUrl && build.makeRelativeFilePath(config.dir,
config.baseUrl).indexOf('..') !== 0) ||
(config.appDir &&
- build.makeRelativeFilePath(config.dir, config.appDir).indexOf('..') !== 0)) {
+ build.makeRelativeFilePath(config.dir, config.appDir).indexOf('..') !== 0))) {
throw new Error('"dir" is set to a parent or same directory as' +
' "appDir" or "baseUrl". This can result in' +
- ' the deletion of source code. Stopping.');
+ ' the deletion of source code. Stopping. If' +
+ ' you want to allow possible overwriting of' +
+ ' source code, set "allowSourceOverwrites"' +
+ ' to true in the build config, but do so at' +
+ ' your own risk. In that case, you may want' +
+ ' to also set "keepBuildDir" to true.');
}
}
if (config.insertRequire && !lang.isArray(config.insertRequire)) {
throw new Error('insertRequire should be a list of module IDs' +
@@ -27253,11 +27427,11 @@
currContents = config.onBuildWrite(moduleName, path, currContents);
}
//Semicolon is for files that are not well formed when
//concatenated with other content.
- singleContents += "\n" + addSemiColon(currContents, config);
+ singleContents += addSemiColon(currContents, config);
});
}
}).then(function () {
var refPath, pluginId, resourcePath,
sourceMapPath, sourceMapLineNumber,
@@ -27271,20 +27445,40 @@
//after the module is processed.
//If we have a name, but no defined module, then add in the placeholder.
if (moduleName && falseProp(layer.modulesWithNames, moduleName) && !config.skipModuleInsertion) {
shim = config.shim && (getOwn(config.shim, moduleName) || (packageMain && getOwn(config.shim, moduleName) || getOwn(config.shim, packageName)));
if (shim) {
- singleContents += '\n' + namespaceWithDot + 'define("' + moduleName + '", ' +
- (shim.deps && shim.deps.length ?
- build.makeJsArrayString(shim.deps) + ', ' : '') +
- (shim.exportsFn ? shim.exportsFn() : 'function(){}') +
- ');\n';
+ if (config.wrapShim) {
+ singleContents = '(function(root) {' +
+ '\n' + namespaceWithDot + 'define("' + moduleName + '", ' +
+ (shim.deps && shim.deps.length ?
+ build.makeJsArrayString(shim.deps) + ', ' : '[], ') +
+ 'function() {\n' +
+ ' return (function() {\n' +
+ singleContents +
+ (shim.exportsFn ? shim.exportsFn() : '') +
+ ' }).apply(root, arguments);\n' +
+ ' });\n' +
+ '}(this));\n';
+ } else {
+ singleContents += '\n' + namespaceWithDot + 'define("' + moduleName + '", ' +
+ (shim.deps && shim.deps.length ?
+ build.makeJsArrayString(shim.deps) + ', ' : '') +
+ (shim.exportsFn ? shim.exportsFn() : 'function(){}') +
+ ');\n';
+ }
} else {
singleContents += '\n' + namespaceWithDot + 'define("' + moduleName + '", function(){});\n';
}
}
+ //Add line break at end of file, instead of at beginning,
+ //so source map line numbers stay correct, but still allow
+ //for some space separation between files in case ASI issues
+ //for concatenation would cause an error otherwise.
+ singleContents += '\n';
+
//Add to the source map
if (sourceMapGenerator) {
refPath = config.out ? config.baseUrl : module._buildPath;
parts = path.split('!');
if (parts.length === 1) {
@@ -27573,11 +27767,11 @@
} else if (commandOption === 'v') {
console.log('r.js: ' + version +
', RequireJS: ' + this.requirejsVars.require.version +
- ', UglifyJS2: 2.4.8, UglifyJS: 1.3.4');
+ ', UglifyJS2: 2.4.12, UglifyJS: 1.3.4');
} else if (commandOption === 'convert') {
loadLib();
this.requirejsVars.require(['env!env/args', 'commonJs', 'env!env/print'],
function (args, commonJs, print) {
@@ -27612,6 +27806,6 @@
}((typeof console !== 'undefined' ? console : undefined),
(typeof Packages !== 'undefined' || (typeof window === 'undefined' &&
typeof Components !== 'undefined' && Components.interfaces) ?
Array.prototype.slice.call(arguments, 0) : []),
- (typeof readFile !== 'undefined' ? readFile : undefined)));
\ No newline at end of file
+ (typeof readFile !== 'undefined' ? readFile : undefined)));