continue loop;
case stat instanceof AST_If:
if (stat.body instanceof AST_Return) {
+ var value = stat.body.value;
//---
// pretty silly case, but:
// if (foo()) return; return; ==> foo(); return;
- if (((in_lambda && ret.length == 0)
- || (ret[0] instanceof AST_Return && !ret[0].value))
- && !stat.body.value && !stat.alternative) {
+ if ((in_lambda && ret.length == 0 || ret[0] instanceof AST_Return && !ret[0].value)
+ && !value && !stat.alternative) {
CHANGED = true;
var cond = make_node(AST_SimpleStatement, stat.condition, {
body: stat.condition
}
//---
// if (foo()) return x; return y; ==> return foo() ? x : y;
- if (ret[0] instanceof AST_Return && stat.body.value && ret[0].value && !stat.alternative) {
+ if (ret[0] instanceof AST_Return && value && ret[0].value && !stat.alternative) {
CHANGED = true;
stat = stat.clone();
stat.alternative = ret[0];
//---
// if (foo()) return x; [ return ; ] ==> return foo() ? x : undefined;
if (multiple_if_returns && (ret.length == 0 || ret[0] instanceof AST_Return)
- && stat.body.value && !stat.alternative && in_lambda) {
+ && value && !stat.alternative && in_lambda) {
CHANGED = true;
stat = stat.clone();
stat.alternative = ret[0] || make_node(AST_Return, stat, {
continue loop;
}
//---
- // if (foo()) return; [ else x... ]; y... ==> if (!foo()) { x...; y... }
- if (!stat.body.value && in_lambda) {
+ // if (foo()) return [ void bar() ]; [ else x...; ] y... ==> if (!foo()) { x...; y... } else bar();
+ if (in_lambda && (!value || value instanceof AST_UnaryPrefix && value.operator == "void")) {
CHANGED = true;
stat = stat.clone();
stat.condition = stat.condition.negate(compressor);
stat.body = make_node(AST_BlockStatement, stat, {
body: body
});
- stat.alternative = null;
+ stat.alternative = value ? make_node(AST_SimpleStatement, value, {
+ body: value.expression
+ }) : null;
ret = funs.concat([ stat.transform(compressor) ]);
continue loop;
}
-
//---
// if (a) return b; if (c) return d; e; ==> return a ? b : c ? d : void e;
//
eval(stdout);
assert.strictEqual(typeof WrappedUglifyJS, 'object');
- assert.strictEqual(WrappedUglifyJS.minify("foo([true,,2+3]);").code, "foo([!0,,5]);");
+ var result = WrappedUglifyJS.minify("foo([true,,2+3]);");
+ assert.strictEqual(result.error, undefined);
+ assert.strictEqual(result.code, "foo([!0,,5]);");
done();
});
eval(stdout);
assert.strictEqual(typeof SpiderUglify, "object");
- assert.strictEqual(SpiderUglify.minify("foo([true,,2+3]);").code, "foo([!0,,5]);");
+ var result = SpiderUglify.minify("foo([true,,2+3]);");
+ assert.strictEqual(result.error, undefined);
+ assert.strictEqual(result.code, "foo([!0,,5]);");
done();
});