vendor/uglifyjs/lib/process.js in uglifier-0.1.1 vs vendor/uglifyjs/lib/process.js in uglifier-0.2.0
- old
+ new
@@ -359,18 +359,14 @@
var w = ast_walker(), walk = w.walk;
var having_eval = [];
function with_new_scope(cont) {
current_scope = new Scope(current_scope);
- try {
- var ret = current_scope.body = cont();
- ret.scope = current_scope;
- return ret;
- }
- finally {
- current_scope = current_scope.parent;
- }
+ var ret = current_scope.body = cont();
+ ret.scope = current_scope;
+ current_scope = current_scope.parent;
+ return ret;
};
function define(name) {
return current_scope.define(name);
};
@@ -985,21 +981,14 @@
];
},
"unary-prefix": function(op, cond) {
if (op == "!")
return best_of(this, negate(cond));
- },
- "call": function(expr, args) {
- if (expr[0] == "dot" && expr[2] == "toString" && args.length == 0) {
- // foo.toString() ==> foo+""
- return [ "binary", "+", expr[1], [ "string", "" ]];
- }
}
}, function() {
return walk(ast);
});
-
};
/* -----[ re-generate code from the AST ]----- */
var DOT_CALL_NO_PARENS = jsp.array_to_hash([
@@ -1089,11 +1078,11 @@
// "stat", but it could also be a "seq" and
// we're the first in this "seq" and the
// parent is "stat", and so on. Messy stuff,
// but it worths the trouble.
var a = slice($stack), self = a.pop(), p = a.pop();
- while (true) {
+ while (p) {
if (p[0] == "stat") return true;
if ((p[0] == "seq" && p[1] === self) ||
(p[0] == "call" && p[1] === self) ||
(p[0] == "binary" && p[2] === self)) {
self = p;
@@ -1113,11 +1102,11 @@
"0" + num.toString(8)); // same.
if ((m = /^(.*?)(0+)$/.exec(num))) {
a.push(m[1] + "e" + m[2].length);
}
} else if ((m = /^0?\.(0+)(.*)$/.exec(num))) {
- a.push(m[2] + "e-" + (m[1].length + 1),
+ a.push(m[2] + "e-" + (m[1].length + m[2].length),
str.substr(str.indexOf(".")));
}
return best_of(a);
};
@@ -1327,10 +1316,17 @@
// IF having an ELSE clause where the THEN clause ends in an
// IF *without* an ELSE block (then the outer ELSE would refer
// to the inner IF). This function checks for this case and
// adds the block brackets if needed.
function make_then(th) {
+ if (th[0] == "do") {
+ // https://github.com/mishoo/UglifyJS/issues/#issue/57
+ // IE croaks with "syntax error" on code like this:
+ // if (foo) do ... while(cond); else ...
+ // we need block brackets around do/while
+ return make([ "block", [ th ]]);
+ }
var b = th;
while (true) {
var type = b[0];
if (type == "if") {
if (!b[3])
@@ -1480,5 +1476,6 @@
exports.ast_walker = ast_walker;
exports.ast_mangle = ast_mangle;
exports.ast_squeeze = ast_squeeze;
exports.gen_code = gen_code;
exports.ast_add_scope = ast_add_scope;
+exports.ast_squeeze_more = require("./squeeze-more").ast_squeeze_more;