From 21968285e8fad1cfe775b389c6bcd16e14b62c6c Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Tue, 18 Sep 2012 10:53:46 +0300 Subject: [PATCH] added AST_NaN (output as 0/0) --- lib/ast.js | 5 +++++ lib/compress.js | 9 ++++++--- lib/output.js | 3 +++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/ast.js b/lib/ast.js index 55e95033..39a62b16 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -661,6 +661,11 @@ var AST_Null = DEFNODE("Null", null, { value: null }, AST_Atom); +var AST_NaN = DEFNODE("NaN", null, { + $documentation: "The impossible value", + value: 0/0 +}, AST_Atom); + var AST_Undefined = DEFNODE("Undefined", null, { $documentation: "The `undefined` value", value: (function(){}()) diff --git a/lib/compress.js b/lib/compress.js index ca7bfe51..aedd78fd 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -526,9 +526,9 @@ function Compressor(options, false_by_default) { }); break; case "number": - ast = make_node(AST_Number, this, { + ast = make_node(isNaN(val) ? AST_NaN : AST_Number, this, { value: val - }); + }).optimize(compressor); break; case "boolean": ast = make_node(val ? AST_True : AST_False, this); @@ -1501,8 +1501,11 @@ function Compressor(options, false_by_default) { }); AST_SymbolRef.DEFMETHOD("optimize", function(compressor){ - if (this.name == "undefined" && this.undeclared()) { + if (this.undeclared()) switch (this.name) { + case "undefined": return make_node(AST_Undefined, this).optimize(compressor); + case "NaN": + return make_node(AST_NaN, this).optimize(compressor); } return this; }); diff --git a/lib/output.js b/lib/output.js index 96221599..ee11aebc 100644 --- a/lib/output.js +++ b/lib/output.js @@ -894,6 +894,9 @@ function OutputStream(options) { output.print("void 0"); //output.print("[][0]"); }); + DEFPRINT(AST_NaN, function(self, output){ + output.print("0/0"); + }); DEFPRINT(AST_This, function(self, output){ output.print("this"); }); -- 2.34.1