Merge branch 'master' into harmony
This commit is contained in:
@@ -197,11 +197,10 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
|
||||
AST_Node.DEFMETHOD("equivalent_to", function(node){
|
||||
// XXX: this is a rather expensive way to test two node's equivalence:
|
||||
return this.print_to_string() == node.print_to_string();
|
||||
return this.TYPE == node.TYPE && this.print_to_string() == node.print_to_string();
|
||||
});
|
||||
|
||||
AST_Node.DEFMETHOD("process_expression", function(insert) {
|
||||
AST_Node.DEFMETHOD("process_expression", function(insert, compressor) {
|
||||
var self = this;
|
||||
var tt = new TreeTransformer(function(node) {
|
||||
if (insert && node instanceof AST_SimpleStatement) {
|
||||
@@ -210,6 +209,12 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
}
|
||||
if (!insert && node instanceof AST_Return) {
|
||||
if (compressor) {
|
||||
var value = node.value && node.value.drop_side_effect_free(compressor, true);
|
||||
return value ? make_node(AST_SimpleStatement, node, {
|
||||
body: value
|
||||
}) : make_node(AST_EmptyStatement, node);
|
||||
}
|
||||
return make_node(AST_SimpleStatement, node, {
|
||||
body: node.value || make_node(AST_Undefined, node)
|
||||
});
|
||||
@@ -418,18 +423,17 @@ merge(Compressor.prototype, {
|
||||
value: val
|
||||
});
|
||||
case "number":
|
||||
if (isNaN(val)) {
|
||||
return make_node(AST_NaN, orig);
|
||||
}
|
||||
|
||||
if ((1 / val) < 0) {
|
||||
return make_node(AST_UnaryPrefix, orig, {
|
||||
if (isNaN(val)) return make_node(AST_NaN, orig);
|
||||
if (isFinite(val)) {
|
||||
return 1 / val < 0 ? make_node(AST_UnaryPrefix, orig, {
|
||||
operator: "-",
|
||||
expression: make_node(AST_Number, orig, { value: -val })
|
||||
});
|
||||
}) : make_node(AST_Number, orig, { value: val });
|
||||
}
|
||||
|
||||
return make_node(AST_Number, orig, { value: val });
|
||||
return val < 0 ? make_node(AST_UnaryPrefix, orig, {
|
||||
operator: "-",
|
||||
expression: make_node(AST_Infinity, orig)
|
||||
}) : make_node(AST_Infinity, orig);
|
||||
case "boolean":
|
||||
return make_node(val ? AST_True : AST_False, orig);
|
||||
case "undefined":
|
||||
@@ -2006,8 +2010,7 @@ merge(Compressor.prototype, {
|
||||
var sym = def.name.definition();
|
||||
if (sym.id in in_use_ids) return true;
|
||||
if (!drop_vars && sym.global) return true;
|
||||
if (sym.orig[0] instanceof AST_SymbolCatch
|
||||
&& sym.scope.parent_scope.find_variable(def.name).orig[0] === def.name) {
|
||||
if (sym.orig[0] instanceof AST_SymbolCatch) {
|
||||
def.value = def.value && def.value.drop_side_effect_free(compressor);
|
||||
return true;
|
||||
}
|
||||
@@ -2278,7 +2281,7 @@ merge(Compressor.prototype, {
|
||||
if (this.expression instanceof AST_Function
|
||||
&& (!this.expression.name || !this.expression.name.definition().references.length)) {
|
||||
var node = this.clone();
|
||||
node.expression = node.expression.process_expression(false);
|
||||
node.expression = node.expression.process_expression(false, compressor);
|
||||
return node;
|
||||
}
|
||||
return this;
|
||||
@@ -2642,7 +2645,6 @@ merge(Compressor.prototype, {
|
||||
self.expression = best_of_expression(expression, self.expression);
|
||||
}
|
||||
if (!compressor.option("dead_code")) return self;
|
||||
var prev_block;
|
||||
var decl = [];
|
||||
var body = [];
|
||||
var default_branch;
|
||||
@@ -2671,14 +2673,16 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
}
|
||||
if (aborts(branch)) {
|
||||
var block = make_node(AST_BlockStatement, branch, branch).print_to_string();
|
||||
if (!fallthrough && prev_block === block) body[body.length - 1].body = [];
|
||||
if (body.length > 0 && !fallthrough) {
|
||||
var prev = body[body.length - 1];
|
||||
if (prev.body.length == branch.body.length
|
||||
&& make_node(AST_BlockStatement, prev, prev).equivalent_to(make_node(AST_BlockStatement, branch, branch)))
|
||||
prev.body = [];
|
||||
}
|
||||
body.push(branch);
|
||||
prev_block = block;
|
||||
fallthrough = false;
|
||||
} else {
|
||||
body.push(branch);
|
||||
prev_block = null;
|
||||
fallthrough = true;
|
||||
}
|
||||
}
|
||||
@@ -2724,6 +2728,15 @@ merge(Compressor.prototype, {
|
||||
|
||||
OPT(AST_Try, function(self, compressor){
|
||||
self.body = tighten_body(self.body, compressor);
|
||||
if (self.bcatch && self.bfinally && all(self.bfinally.body, is_empty)) self.bfinally = null;
|
||||
if (all(self.body, is_empty)) {
|
||||
var body = [];
|
||||
if (self.bcatch) extract_declarations_from_unreachable_code(compressor, self.bcatch, body);
|
||||
if (self.bfinally) body = body.concat(self.bfinally.body);
|
||||
return body.length > 0 ? make_node(AST_BlockStatement, self, {
|
||||
body: body
|
||||
}).optimize(compressor) : make_node(AST_EmptyStatement, self);
|
||||
}
|
||||
return self;
|
||||
});
|
||||
|
||||
@@ -3009,11 +3022,9 @@ merge(Compressor.prototype, {
|
||||
return AST_Seq.from_array(args).transform(compressor);
|
||||
}
|
||||
}
|
||||
if (compressor.option("side_effects")) {
|
||||
if (!AST_Block.prototype.has_side_effects.call(exp, compressor)) {
|
||||
var args = self.args.concat(make_node(AST_Undefined, self));
|
||||
return AST_Seq.from_array(args).transform(compressor);
|
||||
}
|
||||
if (compressor.option("side_effects") && all(exp.body, is_empty)) {
|
||||
var args = self.args.concat(make_node(AST_Undefined, self));
|
||||
return AST_Seq.from_array(args).transform(compressor);
|
||||
}
|
||||
}
|
||||
if (compressor.option("drop_console")) {
|
||||
@@ -3164,8 +3175,17 @@ merge(Compressor.prototype, {
|
||||
})).optimize(compressor);
|
||||
}
|
||||
}
|
||||
if (e instanceof AST_Binary
|
||||
&& (self.operator == "+" || self.operator == "-")
|
||||
&& (e.operator == "*" || e.operator == "/" || e.operator == "%")) {
|
||||
self.expression = e.left;
|
||||
e.left = self;
|
||||
return e.optimize(compressor);
|
||||
}
|
||||
// avoids infinite recursion of numerals
|
||||
if (self.operator != "-" || !(self.expression instanceof AST_Number)) {
|
||||
if (self.operator != "-"
|
||||
|| !(self.expression instanceof AST_Number
|
||||
|| self.expression instanceof AST_Infinity)) {
|
||||
var ev = self.evaluate(compressor);
|
||||
if (ev !== self) {
|
||||
ev = make_node_from_constant(ev, self).optimize(compressor);
|
||||
@@ -3597,9 +3617,9 @@ merge(Compressor.prototype, {
|
||||
case "undefined":
|
||||
return make_node(AST_Undefined, self).optimize(compressor);
|
||||
case "NaN":
|
||||
return make_node(AST_NaN, self).optimize(compressor);
|
||||
return make_node(AST_NaN, self);
|
||||
case "Infinity":
|
||||
return make_node(AST_Infinity, self).optimize(compressor);
|
||||
return make_node(AST_Infinity, self);
|
||||
}
|
||||
}
|
||||
if (compressor.option("evaluate") && compressor.option("reduce_vars")) {
|
||||
@@ -3627,14 +3647,6 @@ merge(Compressor.prototype, {
|
||||
return self;
|
||||
});
|
||||
|
||||
OPT(AST_Infinity, function (self, compressor) {
|
||||
return make_node(AST_Binary, self, {
|
||||
operator : '/',
|
||||
left : make_node(AST_Number, self, {value: 1}),
|
||||
right : make_node(AST_Number, self, {value: 0})
|
||||
});
|
||||
});
|
||||
|
||||
OPT(AST_Undefined, function(self, compressor){
|
||||
if (compressor.option("unsafe")) {
|
||||
var scope = compressor.find_parent(AST_Scope);
|
||||
|
||||
@@ -652,6 +652,15 @@ function OutputStream(options) {
|
||||
&& this.operator !== "--";
|
||||
});
|
||||
|
||||
PARENS([ AST_Infinity, AST_NaN ], function(output){
|
||||
var p = output.parent();
|
||||
return p instanceof AST_PropAccess && p.expression === this
|
||||
|| p instanceof AST_Call && p.expression === this
|
||||
|| p instanceof AST_Unary && p.operator != "+" && p.operator != "-"
|
||||
|| p instanceof AST_Binary && p.right === this
|
||||
&& (p.operator == "/" || p.operator == "%");
|
||||
});
|
||||
|
||||
PARENS(AST_Seq, function(output){
|
||||
var p = output.parent();
|
||||
return p instanceof AST_Call // (foo, bar)() or foo(1, (2, 3), 4)
|
||||
@@ -1139,24 +1148,24 @@ function OutputStream(options) {
|
||||
self.expression.print(output);
|
||||
});
|
||||
output.space();
|
||||
if (self.body.length > 0) output.with_block(function(){
|
||||
self.body.forEach(function(stmt, i){
|
||||
if (i) output.newline();
|
||||
var last = self.body.length - 1;
|
||||
if (last < 0) output.print("{}");
|
||||
else output.with_block(function(){
|
||||
self.body.forEach(function(branch, i){
|
||||
output.indent(true);
|
||||
stmt.print(output);
|
||||
branch.print(output);
|
||||
if (i < last && branch.body.length > 0)
|
||||
output.newline();
|
||||
});
|
||||
});
|
||||
else output.print("{}");
|
||||
});
|
||||
AST_SwitchBranch.DEFMETHOD("_do_print_body", function(output){
|
||||
if (this.body.length > 0) {
|
||||
output.newline();
|
||||
this.body.forEach(function(stmt){
|
||||
output.indent();
|
||||
stmt.print(output);
|
||||
output.newline();
|
||||
this.body.forEach(function(stmt){
|
||||
output.indent();
|
||||
stmt.print(output);
|
||||
output.newline();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
DEFPRINT(AST_Default, function(self, output){
|
||||
output.print("default:");
|
||||
@@ -1617,10 +1626,18 @@ function OutputStream(options) {
|
||||
});
|
||||
DEFPRINT(AST_Hole, noop);
|
||||
DEFPRINT(AST_Infinity, function(self, output){
|
||||
output.print("Infinity");
|
||||
output.print("1");
|
||||
output.space();
|
||||
output.print("/");
|
||||
output.space();
|
||||
output.print("0");
|
||||
});
|
||||
DEFPRINT(AST_NaN, function(self, output){
|
||||
output.print("NaN");
|
||||
output.print("0");
|
||||
output.space();
|
||||
output.print("/");
|
||||
output.space();
|
||||
output.print("0");
|
||||
});
|
||||
DEFPRINT(AST_This, function(self, output){
|
||||
output.print("this");
|
||||
|
||||
@@ -87,9 +87,7 @@ SymbolDef.prototype = {
|
||||
if (!options.screw_ie8 && sym instanceof AST_SymbolLambda)
|
||||
s = s.parent_scope;
|
||||
var def;
|
||||
if (options.screw_ie8
|
||||
&& sym instanceof AST_SymbolCatch
|
||||
&& (def = s.parent_scope.find_variable(sym))) {
|
||||
if (this.defun && (def = this.defun.variables.get(this.name))) {
|
||||
this.mangled_name = def.mangled_name || def.name;
|
||||
} else
|
||||
this.mangled_name = s.next_mangled(options, this);
|
||||
@@ -229,7 +227,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
||||
}
|
||||
}
|
||||
else if (node instanceof AST_SymbolCatch) {
|
||||
scope.def_variable(node, in_export, in_block);
|
||||
scope.def_variable(node, in_export, in_block).defun = defun;
|
||||
}
|
||||
else if (node instanceof AST_LabelRef) {
|
||||
var sym = labels.get(node.name);
|
||||
@@ -293,7 +291,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
||||
if (node instanceof AST_SymbolCatch) {
|
||||
var name = node.name;
|
||||
var refs = node.thedef.references;
|
||||
var scope = node.thedef.scope.parent_scope.parent_scope;
|
||||
var scope = node.thedef.defun;
|
||||
var def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
|
||||
refs.forEach(function(ref) {
|
||||
ref.thedef = def;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"homepage": "http://lisperator.net/uglifyjs",
|
||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||
"license": "BSD-2-Clause",
|
||||
"version": "2.8.17",
|
||||
"version": "2.8.19",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
|
||||
@@ -840,8 +840,8 @@ equality_conditionals_false: {
|
||||
f(0, true, 0),
|
||||
f(1, 2, 3),
|
||||
f(1, null, 3),
|
||||
f(NaN),
|
||||
f(NaN, "foo");
|
||||
f(0/0),
|
||||
f(0/0, "foo");
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
@@ -888,8 +888,8 @@ equality_conditionals_true: {
|
||||
f(0, true, 0),
|
||||
f(1, 2, 3),
|
||||
f(1, null, 3),
|
||||
f(NaN),
|
||||
f(NaN, "foo");
|
||||
f(0/0),
|
||||
f(0/0, "foo");
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -236,3 +236,45 @@ dead_code_const_annotation_complex_scope: {
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
try_catch_finally: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
dead_code: true,
|
||||
evaluate: true,
|
||||
}
|
||||
input: {
|
||||
var a = 1;
|
||||
!function() {
|
||||
try {
|
||||
if (false) throw x;
|
||||
} catch (a) {
|
||||
var a = 2;
|
||||
console.log("FAIL");
|
||||
} finally {
|
||||
a = 3;
|
||||
console.log("PASS");
|
||||
}
|
||||
}();
|
||||
try {
|
||||
console.log(a);
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var a = 1;
|
||||
!function() {
|
||||
var a;
|
||||
a = 3;
|
||||
console.log("PASS");
|
||||
}();
|
||||
try {
|
||||
console.log(a);
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"1",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -934,7 +934,9 @@ issue_1715_1: {
|
||||
var a = 1;
|
||||
function f() {
|
||||
a++;
|
||||
try {} catch (a) {
|
||||
try {
|
||||
x();
|
||||
} catch (a) {
|
||||
var a;
|
||||
}
|
||||
}
|
||||
@@ -945,7 +947,9 @@ issue_1715_1: {
|
||||
var a = 1;
|
||||
function f() {
|
||||
a++;
|
||||
try {} catch (a) {
|
||||
try {
|
||||
x();
|
||||
} catch (a) {
|
||||
var a;
|
||||
}
|
||||
}
|
||||
@@ -963,7 +967,9 @@ issue_1715_2: {
|
||||
var a = 1;
|
||||
function f() {
|
||||
a++;
|
||||
try {} catch (a) {
|
||||
try {
|
||||
x();
|
||||
} catch (a) {
|
||||
var a = 2;
|
||||
}
|
||||
}
|
||||
@@ -974,7 +980,9 @@ issue_1715_2: {
|
||||
var a = 1;
|
||||
function f() {
|
||||
a++;
|
||||
try {} catch (a) {
|
||||
try {
|
||||
x();
|
||||
} catch (a) {
|
||||
var a;
|
||||
}
|
||||
}
|
||||
@@ -992,7 +1000,9 @@ issue_1715_3: {
|
||||
var a = 1;
|
||||
function f() {
|
||||
a++;
|
||||
try {} catch (a) {
|
||||
try {
|
||||
console;
|
||||
} catch (a) {
|
||||
var a = 2 + x();
|
||||
}
|
||||
}
|
||||
@@ -1003,7 +1013,9 @@ issue_1715_3: {
|
||||
var a = 1;
|
||||
function f() {
|
||||
a++;
|
||||
try {} catch (a) {
|
||||
try {
|
||||
console;
|
||||
} catch (a) {
|
||||
var a = x();
|
||||
}
|
||||
}
|
||||
@@ -1012,3 +1024,34 @@ issue_1715_3: {
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
issue_1715_4: {
|
||||
options = {
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = 1;
|
||||
!function a() {
|
||||
a++;
|
||||
try {
|
||||
x();
|
||||
} catch (a) {
|
||||
var a;
|
||||
}
|
||||
}();
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = 1;
|
||||
!function() {
|
||||
a++;
|
||||
try {
|
||||
x();
|
||||
} catch (a) {
|
||||
var a;
|
||||
}
|
||||
}();
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ and: {
|
||||
a = 7;
|
||||
|
||||
a = false;
|
||||
a = NaN;
|
||||
a = 0/0;
|
||||
a = 0;
|
||||
a = void 0;
|
||||
a = null;
|
||||
@@ -67,7 +67,7 @@ and: {
|
||||
a = 6 << condition && -4.5;
|
||||
|
||||
a = condition && false;
|
||||
a = console.log("b") && NaN;
|
||||
a = console.log("b") && 0/0;
|
||||
a = console.log("c") && 0;
|
||||
a = 2 * condition && void 0;
|
||||
a = condition + 3 && null;
|
||||
@@ -149,7 +149,7 @@ or: {
|
||||
a = 6 << condition || -4.5;
|
||||
|
||||
a = condition || false;
|
||||
a = console.log("b") || NaN;
|
||||
a = console.log("b") || 0/0;
|
||||
a = console.log("c") || 0;
|
||||
a = 2 * condition || void 0;
|
||||
a = condition + 3 || null;
|
||||
@@ -196,8 +196,8 @@ negative_zero: {
|
||||
console.log(
|
||||
-0,
|
||||
0,
|
||||
1 / (-0),
|
||||
1 / (-0)
|
||||
-1/0,
|
||||
-1/0
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
@@ -217,8 +217,8 @@ positive_zero: {
|
||||
console.log(
|
||||
0,
|
||||
-0,
|
||||
1 / (0),
|
||||
1 / (0)
|
||||
1/0,
|
||||
1/0
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
@@ -302,15 +302,15 @@ pow_with_number_constants: {
|
||||
var m = 3 ** -10; // Result will be 0.000016935087808430286, which is too long
|
||||
}
|
||||
expect: {
|
||||
var a = NaN;
|
||||
var a = 0/0;
|
||||
var b = 1;
|
||||
var c = 1;
|
||||
var d = NaN;
|
||||
var e = Infinity;
|
||||
var d = 0/0;
|
||||
var e = 1/0;
|
||||
var f = 0;
|
||||
var g = NaN;
|
||||
var h = Infinity;
|
||||
var i = -Infinity;
|
||||
var g = 0/0;
|
||||
var h = 1/0;
|
||||
var i = -1/0;
|
||||
var j = .125;
|
||||
var k = .125;
|
||||
var l = .25;
|
||||
@@ -627,7 +627,7 @@ unsafe_array: {
|
||||
[1, 2, 3, a][0] + 1,
|
||||
2,
|
||||
3,
|
||||
NaN,
|
||||
0/0,
|
||||
"1,21",
|
||||
5,
|
||||
(void 0)[1] + 1
|
||||
|
||||
@@ -21,12 +21,13 @@ pow_with_number_constants: {
|
||||
var f = 2 ** -Infinity;
|
||||
}
|
||||
expect: {
|
||||
var a = 5 ** NaN;
|
||||
// TODO: may need parentheses
|
||||
var a = 5 ** 0/0;
|
||||
var b = 42 ** +0;
|
||||
var c = 42 ** -0;
|
||||
var d = NaN ** 1;
|
||||
var e = 2 ** (1/0);
|
||||
var f = 2 ** -(1/0);
|
||||
var d = 0/0 ** 1;
|
||||
var e = 2 ** 1/0;
|
||||
var f = 2 ** -1/0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -195,11 +195,12 @@ assorted_Infinity_NaN_undefined_in_with_scope: {
|
||||
sequences: false,
|
||||
}
|
||||
input: {
|
||||
var f = console.log;
|
||||
var o = {
|
||||
undefined : 3,
|
||||
NaN : 4,
|
||||
Infinity : 5,
|
||||
}
|
||||
};
|
||||
if (o) {
|
||||
f(undefined, void 0);
|
||||
f(NaN, 0/0);
|
||||
@@ -216,25 +217,25 @@ assorted_Infinity_NaN_undefined_in_with_scope: {
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
var f = console.log, o = {
|
||||
undefined : 3,
|
||||
NaN : 4,
|
||||
Infinity : 5
|
||||
}
|
||||
};
|
||||
if (o) {
|
||||
f(void 0, void 0);
|
||||
f(NaN, NaN);
|
||||
f(0/0, 0/0);
|
||||
f(1/0, 1/0);
|
||||
f(-(1/0), -(1/0));
|
||||
f(NaN, NaN);
|
||||
f(-1/0, -1/0);
|
||||
f(0/0, 0/0);
|
||||
}
|
||||
with (o) {
|
||||
f(undefined, void 0);
|
||||
f(NaN, 0/0);
|
||||
f(Infinity, 1/0);
|
||||
f(-Infinity, -(1/0));
|
||||
f(-Infinity, -1/0);
|
||||
f(9 + undefined, 9 + void 0);
|
||||
}
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ side_effects_finally: {
|
||||
function f() {
|
||||
function g() {
|
||||
try {
|
||||
x();
|
||||
} catch (e) {
|
||||
} finally {
|
||||
console.log("PASS");
|
||||
@@ -83,6 +84,7 @@ side_effects_finally: {
|
||||
function f() {
|
||||
(function() {
|
||||
try {
|
||||
x();
|
||||
} catch (e) {
|
||||
} finally {
|
||||
console.log("PASS");
|
||||
|
||||
97
test/compress/issue-1733.js
Normal file
97
test/compress/issue-1733.js
Normal file
@@ -0,0 +1,97 @@
|
||||
function_iife_catch: {
|
||||
mangle = {
|
||||
screw_ie8: true,
|
||||
}
|
||||
input: {
|
||||
function f(n) {
|
||||
!function() {
|
||||
try {
|
||||
throw 0;
|
||||
} catch (n) {
|
||||
var a = 1;
|
||||
console.log(n, a);
|
||||
}
|
||||
}();
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect_exact: "function f(o){!function(){try{throw 0}catch(c){var o=1;console.log(c,o)}}()}f();"
|
||||
expect_stdout: "0 1"
|
||||
}
|
||||
|
||||
function_iife_catch_ie8: {
|
||||
mangle = {
|
||||
screw_ie8: false,
|
||||
}
|
||||
input: {
|
||||
function f(n) {
|
||||
!function() {
|
||||
try {
|
||||
throw 0;
|
||||
} catch (n) {
|
||||
var a = 1;
|
||||
console.log(n, a);
|
||||
}
|
||||
}();
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect_exact: "function f(o){!function(){try{throw 0}catch(o){var c=1;console.log(o,c)}}()}f();"
|
||||
expect_stdout: "0 1"
|
||||
}
|
||||
|
||||
function_catch_catch: {
|
||||
mangle = {
|
||||
screw_ie8: true,
|
||||
}
|
||||
input: {
|
||||
var o = 0;
|
||||
function f() {
|
||||
try {
|
||||
throw 1;
|
||||
} catch (c) {
|
||||
try {
|
||||
throw 2;
|
||||
} catch (o) {
|
||||
var o = 3;
|
||||
console.log(o);
|
||||
}
|
||||
}
|
||||
console.log(o);
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect_exact: "var o=0;function f(){try{throw 1}catch(c){try{throw 2}catch(o){var o=3;console.log(o)}}console.log(o)}f();"
|
||||
expect_stdout: [
|
||||
"3",
|
||||
"undefined",
|
||||
]
|
||||
}
|
||||
|
||||
function_catch_catch_ie8: {
|
||||
mangle = {
|
||||
screw_ie8: false,
|
||||
}
|
||||
input: {
|
||||
var o = 0;
|
||||
function f() {
|
||||
try {
|
||||
throw 1;
|
||||
} catch (c) {
|
||||
try {
|
||||
throw 2;
|
||||
} catch (o) {
|
||||
var o = 3;
|
||||
console.log(o);
|
||||
}
|
||||
}
|
||||
console.log(o);
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect_exact: "var o=0;function f(){try{throw 1}catch(c){try{throw 2}catch(o){var o=3;console.log(o)}}console.log(o)}f();"
|
||||
expect_stdout: [
|
||||
"3",
|
||||
"undefined",
|
||||
]
|
||||
}
|
||||
@@ -6,7 +6,7 @@ NaN_and_Infinity_must_have_parens: {
|
||||
}
|
||||
expect: {
|
||||
(1/0).toString();
|
||||
NaN.toString(); // transformation to 0/0 dropped
|
||||
(0/0).toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,3 +23,105 @@ NaN_and_Infinity_should_not_be_replaced_when_they_are_redefined: {
|
||||
NaN.toString();
|
||||
}
|
||||
}
|
||||
|
||||
beautify_off_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
}
|
||||
beautify = {
|
||||
beautify: false,
|
||||
}
|
||||
input: {
|
||||
var NaN;
|
||||
console.log(
|
||||
null,
|
||||
undefined,
|
||||
Infinity,
|
||||
NaN,
|
||||
Infinity * undefined,
|
||||
Infinity.toString(),
|
||||
NaN.toString(),
|
||||
(Infinity * undefined).toString()
|
||||
);
|
||||
}
|
||||
expect_exact: "var NaN;console.log(null,void 0,1/0,NaN,0/0,(1/0).toString(),NaN.toString(),(0/0).toString());"
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
beautify_off_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
}
|
||||
beautify = {
|
||||
beautify: false,
|
||||
}
|
||||
input: {
|
||||
console.log(
|
||||
null.toString(),
|
||||
undefined.toString()
|
||||
);
|
||||
}
|
||||
expect_exact: "console.log(null.toString(),(void 0).toString());"
|
||||
}
|
||||
|
||||
beautify_on_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
}
|
||||
beautify = {
|
||||
beautify: true,
|
||||
}
|
||||
input: {
|
||||
var NaN;
|
||||
console.log(
|
||||
null,
|
||||
undefined,
|
||||
Infinity,
|
||||
NaN,
|
||||
Infinity * undefined,
|
||||
Infinity.toString(),
|
||||
NaN.toString(),
|
||||
(Infinity * undefined).toString()
|
||||
);
|
||||
}
|
||||
expect_exact: [
|
||||
"var NaN;",
|
||||
"",
|
||||
"console.log(null, void 0, 1 / 0, NaN, 0 / 0, (1 / 0).toString(), NaN.toString(), (0 / 0).toString());",
|
||||
]
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
beautify_on_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
}
|
||||
beautify = {
|
||||
beautify: true,
|
||||
}
|
||||
input: {
|
||||
console.log(
|
||||
null.toString(),
|
||||
undefined.toString()
|
||||
);
|
||||
}
|
||||
expect_exact: "console.log(null.toString(), (void 0).toString());"
|
||||
}
|
||||
|
||||
issue_1724: {
|
||||
input: {
|
||||
var a = 0;
|
||||
++a % Infinity | Infinity ? a++ : 0;
|
||||
console.log(a);
|
||||
}
|
||||
expect_exact: "var a=0;++a%(1/0)|1/0?a++:0;console.log(a);"
|
||||
expect_stdout: "2"
|
||||
}
|
||||
|
||||
issue_1725: {
|
||||
input: {
|
||||
([].length === 0) % Infinity ? console.log("PASS") : console.log("FAIL");
|
||||
}
|
||||
expect_exact: '(0===[].length)%(1/0)?console.log("PASS"):console.log("FAIL");'
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -168,3 +168,37 @@ issue_1710: {
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unary_binary_parenthesis: {
|
||||
input: {
|
||||
var v = [ 0, 1, NaN, Infinity, null, undefined, true, false, "", "foo", /foo/ ];
|
||||
v.forEach(function(x) {
|
||||
v.forEach(function(y) {
|
||||
console.log(
|
||||
+(x*y),
|
||||
+(x/y),
|
||||
+(x%y),
|
||||
-(x*y),
|
||||
-(x/y),
|
||||
-(x%y)
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
var v = [ 0, 1, 0/0, 1/0, null, void 0, true, false, "", "foo", /foo/ ];
|
||||
v.forEach(function(x) {
|
||||
v.forEach(function(y) {
|
||||
console.log(
|
||||
+x*y,
|
||||
+x/y,
|
||||
+x%y,
|
||||
-x*y,
|
||||
-x/y,
|
||||
-x%y
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ sub_properties: {
|
||||
a[3.14] = 3;
|
||||
a.if = 4;
|
||||
a["foo bar"] = 5;
|
||||
a[NaN] = 6;
|
||||
a[0/0] = 6;
|
||||
a[null] = 7;
|
||||
a[void 0] = 8;
|
||||
}
|
||||
|
||||
@@ -204,13 +204,13 @@ issue_1586_1: {
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
x();
|
||||
} catch (err) {
|
||||
console.log(err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
expect_exact: "function f(){try{}catch(c){console.log(c.message)}}"
|
||||
expect_stdout: true
|
||||
expect_exact: "function f(){try{x()}catch(c){console.log(c.message)}}"
|
||||
}
|
||||
|
||||
issue_1586_2: {
|
||||
@@ -223,11 +223,11 @@ issue_1586_2: {
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
x();
|
||||
} catch (err) {
|
||||
console.log(err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
expect_exact: "function f(){try{}catch(c){console.log(c.message)}}"
|
||||
expect_stdout: true
|
||||
expect_exact: "function f(){try{x()}catch(c){console.log(c.message)}}"
|
||||
}
|
||||
|
||||
@@ -680,3 +680,44 @@ issue_1705_3: {
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
beautify: {
|
||||
beautify = {
|
||||
beautify: true,
|
||||
}
|
||||
input: {
|
||||
switch (a) {
|
||||
case 0:
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
}
|
||||
switch (b) {
|
||||
case 3:
|
||||
foo();
|
||||
bar();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
expect_exact: [
|
||||
"switch (a) {",
|
||||
" case 0:",
|
||||
" case 1:",
|
||||
" break;",
|
||||
"",
|
||||
" case 2:",
|
||||
" default:",
|
||||
"}",
|
||||
"",
|
||||
"switch (b) {",
|
||||
" case 3:",
|
||||
" foo();",
|
||||
" bar();",
|
||||
"",
|
||||
" default:",
|
||||
" break;",
|
||||
"}",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ describe("Directives", function() {
|
||||
});
|
||||
|
||||
it("Should test EXPECT_DIRECTIVE RegExp", function() {
|
||||
var tests = [
|
||||
[
|
||||
["", true],
|
||||
["'test';", true],
|
||||
["'test';;", true],
|
||||
@@ -195,11 +195,12 @@ describe("Directives", function() {
|
||||
["'tests'; \n\t", true],
|
||||
["'tests';\n\n", true],
|
||||
["\n\n\"use strict\";\n\n", true]
|
||||
];
|
||||
|
||||
for (var i = 0; i < tests.length; i++) {
|
||||
assert.strictEqual(uglify.EXPECT_DIRECTIVE.test(tests[i][0]), tests[i][1], tests[i][0]);
|
||||
}
|
||||
].forEach(function(test) {
|
||||
var out = uglify.OutputStream();
|
||||
out.print(test[0]);
|
||||
out.print_string("", null, true);
|
||||
assert.strictEqual(out.get() === test[0] + ';""', test[1], test[0]);
|
||||
});
|
||||
});
|
||||
|
||||
it("Should only print 2 semicolons spread over 2 lines in beautify mode", function() {
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
var uglify = require('../../');
|
||||
var assert = require("assert");
|
||||
|
||||
describe("For statement", function() {
|
||||
it("For variable should list enclosing scope in its references (issue #17022)", function() {
|
||||
var ast = uglify.parse("function f() { for (var a = 0; a < 10; a++) {} }");
|
||||
ast.figure_out_scope();
|
||||
|
||||
var checkWalker = new uglify.TreeWalker(function(node, descend) {
|
||||
if (node instanceof uglify.AST_VarDef) {
|
||||
console.log("AST_VarDef");
|
||||
// one reference should be in the AST_Defun scope - search for it
|
||||
|
||||
var walkNode = function (r) {
|
||||
console.log(r.CTOR.name);
|
||||
var walker = new uglify.TreeWalker(function(node, descend){
|
||||
// do not walk into any other scope, it should be listed if needed
|
||||
console.log(" " + node.CTOR.name);
|
||||
if (node instanceof uglify.AST_Scope && node != r.scope) return true;
|
||||
if (node instanceof uglify.AST_For) {
|
||||
console.log("Great - we found the for statement referencing the variable")
|
||||
}
|
||||
return false;
|
||||
});
|
||||
r.scope.walk(walker);
|
||||
r.walk(walker);
|
||||
};
|
||||
|
||||
node.name.thedef.orig.forEach(walkNode);
|
||||
node.name.thedef.references.forEach(walkNode);
|
||||
}
|
||||
});
|
||||
ast.walk(checkWalker);
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,5 @@
|
||||
#! /usr/bin/env node
|
||||
|
||||
global.UGLIFY_DEBUG = true;
|
||||
|
||||
var U = require("../tools/node");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
|
||||
@@ -17,7 +17,3 @@ exports["string_template"] = string_template;
|
||||
exports["tokenizer"] = tokenizer;
|
||||
exports["is_identifier"] = is_identifier;
|
||||
exports["SymbolDef"] = SymbolDef;
|
||||
|
||||
if (global.UGLIFY_DEBUG) {
|
||||
exports["EXPECT_DIRECTIVE"] = EXPECT_DIRECTIVE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user