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":
}
}
// 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);
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")) {
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);
|| p instanceof AST_Call && p.expression === this;
});
+ 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 != "-";
+ });
+
PARENS(AST_Seq, function(output){
var p = output.parent();
return p instanceof AST_Call // (foo, bar)() or foo(1, (2, 3), 4)
});
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");
a = 7;
a = false;
- a = NaN;
+ a = 0/0;
a = 0;
a = void 0;
a = null;
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;
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;
console.log(
-0,
0,
- 1 / (-0),
- 1 / (-0)
+ -1/0,
+ -1/0
);
}
expect_stdout: true
console.log(
0,
-0,
- 1 / (0),
- 1 / (0)
+ 1/0,
+ 1/0
);
}
expect_stdout: true
[1, 2, 3, a][0] + 1,
2,
3,
- NaN,
+ 0/0,
"1,21",
5,
(void 0)[1] + 1
}
expect: {
(1/0).toString();
- NaN.toString(); // transformation to 0/0 dropped
+ (0/0).toString();
}
}
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());"
+}