From 09f77c7d4d37350102c36b270b553f45e706d0c8 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 29 Mar 2017 18:31:55 +0800 Subject: output optimal representations of NaN & Infinity (#1723) - move these optimisations out from `Compressor` to `OutputStream` - fixes behaviour inconsistency when running uglified code from global or module levels due to redefinition --- test/compress/issue-597.js | 86 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) (limited to 'test/compress/issue-597.js') diff --git a/test/compress/issue-597.js b/test/compress/issue-597.js index f243223a..3a501532 100644 --- a/test/compress/issue-597.js +++ b/test/compress/issue-597.js @@ -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,87 @@ 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());" +} -- cgit v1.2.3