uglify-js
Advanced tools
Comparing version 2.4.1 to 2.4.2
@@ -374,3 +374,3 @@ /*********************************************************************** | ||
var AST_Accessor = DEFNODE("Accessor", null, { | ||
$documentation: "A setter/getter function" | ||
$documentation: "A setter/getter function. The `name` property is always null." | ||
}, AST_Lambda); | ||
@@ -760,3 +760,3 @@ | ||
$propdoc: { | ||
key: "[string] the property name; it's always a plain string in our AST, no matter if it was a string, number or identifier in original code", | ||
key: "[string] the property name converted to a string for ObjectKeyVal. For setters and getters this is an arbitrary AST_Node.", | ||
value: "[AST_Node] property value. For setters and getters this is an AST_Function." | ||
@@ -763,0 +763,0 @@ }, |
@@ -64,2 +64,3 @@ /*********************************************************************** | ||
screw_ie8 : false, | ||
preamble : null, | ||
}, true); | ||
@@ -303,2 +304,6 @@ | ||
if (options.preamble) { | ||
print(options.preamble.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g, "\n")); | ||
} | ||
var stack = []; | ||
@@ -383,3 +388,3 @@ return { | ||
start._comments_dumped = true; | ||
var comments = start.comments_before; | ||
var comments = start.comments_before || []; | ||
@@ -389,5 +394,6 @@ // XXX: ugly fix for https://github.com/mishoo/UglifyJS2/issues/112 | ||
// the returned or thrown value. | ||
if (self instanceof AST_Exit && | ||
self.value && self.value.start.comments_before.length > 0) { | ||
comments = (comments || []).concat(self.value.start.comments_before); | ||
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 = []; | ||
@@ -482,7 +488,3 @@ } | ||
|| (pp == sp | ||
&& this === p.right | ||
&& !(so == po && | ||
(so == "*" || | ||
so == "&&" || | ||
so == "||")))) { | ||
&& this === p.right)) { | ||
return true; | ||
@@ -514,4 +516,13 @@ } | ||
PARENS(AST_Call, function(output){ | ||
var p = output.parent(); | ||
return p instanceof AST_New && p.expression === this; | ||
var p = output.parent(), p1; | ||
if (p instanceof AST_New && p.expression === this) | ||
return true; | ||
// workaround for Safari bug. | ||
// https://bugs.webkit.org/show_bug.cgi?id=123506 | ||
return this.expression instanceof AST_Function | ||
&& p instanceof AST_PropAccess | ||
&& p.expression === this | ||
&& (p1 = output.parent(1)) instanceof AST_Assign | ||
&& p1.left === p; | ||
}); | ||
@@ -1073,2 +1084,4 @@ | ||
output.print("set"); | ||
output.space(); | ||
self.key.print(output); | ||
self.value._do_print(output, true); | ||
@@ -1078,2 +1091,4 @@ }); | ||
output.print("get"); | ||
output.space(); | ||
self.key.print(output); | ||
self.value._do_print(output, true); | ||
@@ -1080,0 +1095,0 @@ }); |
@@ -582,6 +582,6 @@ /*********************************************************************** | ||
var PRECEDENCE = (function(a, ret){ | ||
for (var i = 0, n = 1; i < a.length; ++i, ++n) { | ||
for (var i = 0; i < a.length; ++i) { | ||
var b = a[i]; | ||
for (var j = 0; j < b.length; ++j) { | ||
ret[b[j]] = n; | ||
ret[b[j]] = i + 1; | ||
} | ||
@@ -793,3 +793,3 @@ } | ||
case "function": | ||
return function_(true); | ||
return function_(AST_Defun); | ||
@@ -938,15 +938,8 @@ case "if": | ||
var function_ = function(in_statement, ctor) { | ||
var is_accessor = ctor === AST_Accessor; | ||
var name = (is("name") ? as_symbol(in_statement | ||
? AST_SymbolDefun | ||
: is_accessor | ||
? AST_SymbolAccessor | ||
: AST_SymbolLambda) | ||
: is_accessor && (is("string") || is("num")) ? as_atom_node() | ||
: null); | ||
var function_ = function(ctor) { | ||
var in_statement = ctor === AST_Defun; | ||
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null; | ||
if (in_statement && !name) | ||
unexpected(); | ||
expect("("); | ||
if (!ctor) ctor = in_statement ? AST_Defun : AST_Function; | ||
return new ctor({ | ||
@@ -1122,3 +1115,5 @@ name: name, | ||
case "name": | ||
return as_symbol(AST_SymbolRef); | ||
case "keyword": | ||
ret = _make_symbol(AST_SymbolRef); | ||
break; | ||
case "num": | ||
@@ -1174,3 +1169,3 @@ ret = new AST_Number({ start: tok, end: tok, value: tok.value }); | ||
next(); | ||
var func = function_(false); | ||
var func = function_(AST_Function); | ||
func.start = start; | ||
@@ -1223,4 +1218,4 @@ func.end = prev(); | ||
start : start, | ||
key : name, | ||
value : function_(false, AST_Accessor), | ||
key : as_atom_node(), | ||
value : function_(AST_Accessor), | ||
end : prev() | ||
@@ -1233,4 +1228,4 @@ })); | ||
start : start, | ||
key : name, | ||
value : function_(false, AST_Accessor), | ||
key : as_atom_node(), | ||
value : function_(AST_Accessor), | ||
end : prev() | ||
@@ -1283,2 +1278,11 @@ })); | ||
function _make_symbol(type) { | ||
var name = S.token.value; | ||
return new (name == "this" ? AST_This : type)({ | ||
name : String(name), | ||
start : S.token, | ||
end : S.token | ||
}); | ||
}; | ||
function as_symbol(type, noerror) { | ||
@@ -1289,8 +1293,3 @@ if (!is("name")) { | ||
} | ||
var name = S.token.value; | ||
var sym = new (name == "this" ? AST_This : type)({ | ||
name : String(S.token.value), | ||
start : S.token, | ||
end : S.token | ||
}); | ||
var sym = _make_symbol(type); | ||
next(); | ||
@@ -1297,0 +1296,0 @@ return sym; |
@@ -67,5 +67,5 @@ /*********************************************************************** | ||
var s = this.scope; | ||
if (this.orig[0] instanceof AST_SymbolLambda && !options.screw_ie8) | ||
if (!options.screw_ie8 && this.orig[0] instanceof AST_SymbolLambda) | ||
s = s.parent_scope; | ||
this.mangled_name = s.next_mangled(options); | ||
this.mangled_name = s.next_mangled(options, this); | ||
} | ||
@@ -260,2 +260,15 @@ } | ||
AST_Function.DEFMETHOD("next_mangled", function(options, def){ | ||
// #179, #326 | ||
// in Safari strict mode, something like (function x(x){...}) is a syntax error; | ||
// a function expression's argument cannot shadow the function expression's name | ||
var tricky_def = def.orig[0] instanceof AST_SymbolFunarg && this.name && this.name.definition(); | ||
while (true) { | ||
var name = AST_Lambda.prototype.next_mangled.call(this, options, def); | ||
if (!(tricky_def && tricky_def.mangled_name == name)) | ||
return name; | ||
} | ||
}); | ||
AST_Scope.DEFMETHOD("references", function(sym){ | ||
@@ -262,0 +275,0 @@ if (sym instanceof AST_Symbol) sym = sym.definition(); |
@@ -6,3 +6,3 @@ { | ||
"main": "tools/node.js", | ||
"version": "2.4.1", | ||
"version": "2.4.2", | ||
"engines": { "node" : ">=0.4.0" }, | ||
@@ -9,0 +9,0 @@ "maintainers": [{ |
@@ -90,2 +90,6 @@ UglifyJS 2 | ||
cascading statements into sequences. [string] | ||
--preamble Preamble to prepend to the output. You can use this to | ||
insert a comment, for example for licensing information. | ||
This will not be parsed, but the source map will adjust | ||
for its presence. | ||
--stats Display operations run time on STDERR. [boolean] | ||
@@ -261,3 +265,3 @@ --acorn Use Acorn for parsing. [boolean] | ||
- `typeof foo == "undefined"` → `foo === void 0` | ||
- `void 0` → `"undefined"` (if there is a variable named "undefined" in | ||
- `void 0` → `undefined` (if there is a variable named "undefined" in | ||
scope; we do it because the variable name will be mangled, typically | ||
@@ -333,2 +337,6 @@ reduced to a single character). | ||
gzip could be smaller; size after gzip insignificantly larger). | ||
- `preamble` (default `null`) -- when passed it must be a string and | ||
it will be prepended to the output literally. The source map will | ||
adjust for this text. Can be used to insert a comment containing | ||
licensing information, for example. | ||
@@ -335,0 +343,0 @@ ### Keeping copyright notices or other comments |
@@ -13,2 +13,3 @@ concatenate_rhs_strings: { | ||
foo("Hello" + bar() + 123 + "World"); | ||
foo(bar() + 'Foo' + (10 + parseInt('10'))); | ||
} | ||
@@ -22,3 +23,4 @@ expect: { | ||
foo("Hello" + bar() + "123World"); | ||
foo(bar() + 'Foo' + (10 + parseInt('10'))); | ||
} | ||
} |
@@ -10,4 +10,11 @@ #! /usr/bin/env node | ||
var tests_dir = path.dirname(module.filename); | ||
var failures = 0; | ||
var failed_files = {}; | ||
run_compress_tests(); | ||
if (failures) { | ||
sys.error("\n!!! Failed " + failures + " test cases."); | ||
sys.error("!!! " + Object.keys(failed_files).join(", ")); | ||
process.exit(1); | ||
} | ||
@@ -87,2 +94,4 @@ /* -----[ utils ]----- */ | ||
}); | ||
failures++; | ||
failed_files[file] = 1; | ||
} | ||
@@ -89,0 +98,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
360739
40
8665
634