From f4e1bec5fdfedfdeebfae617c17033b68b0ccef8 Mon Sep 17 00:00:00 2001 From: Andrew Bullock Date: Mon, 15 Mar 2021 07:32:44 +0000 Subject: [PATCH 1/2] fixes #239 --- .../TestData/JS/Expected/Switch/PrettyPrint.js | 2 +- .../JS/Expected/Switch/PrettyPrint_P.js | 8 ++++++++ .../JS/Expected/Switch/PrettyPrint_same.js | 6 ++++++ .../TestData/JS/Input/Switch/PrettyPrint.js | 8 +++++++- .../JavaScript/Visitors/OutputVisitor.cs | 17 +++++++++-------- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/NUglify.Tests/TestData/JS/Expected/Switch/PrettyPrint.js b/src/NUglify.Tests/TestData/JS/Expected/Switch/PrettyPrint.js index 55ba1170..b186ec8e 100644 --- a/src/NUglify.Tests/TestData/JS/Expected/Switch/PrettyPrint.js +++ b/src/NUglify.Tests/TestData/JS/Expected/Switch/PrettyPrint.js @@ -1 +1 @@ -function foo(){var a=1,b=2,c="three",d,f;try{for(d=a*b;d>0;){switch(c){case"three":c=10;break;case 0:c=-1;break;default:c=c*2}c?(d=d*c,a*=d):c=1}}catch(e){for(f=0;f0;){switch(c){case"three":c=10;break;case 0:c=-1;break;default:c=c*2}c?(d=d*c,a*=d):c=1}}catch(e){for(f=0;f p.Count); - if (count > 1) + var propertyCount = node.Properties.IfNotNull(p => p.Count); + if (propertyCount > 1) NewLine(); - else if(settings.OutputMode == OutputMode.MultipleLines) + else if(propertyCount == 1 && settings.OutputMode == OutputMode.MultipleLines) Output(' '); // output each key/value pair node.Properties?.Accept(this); - - Unindent(); - if (count > 1) + if (propertyCount > 0) + Unindent(); + + if (propertyCount > 1) NewLine(); - else if (settings.OutputMode == OutputMode.MultipleLines) - Output(' '); + else if (propertyCount == 1 && settings.OutputMode == OutputMode.MultipleLines) + Output(' '); Output('}'); MarkSegment(node, null, node.Context); From f40bd208e78a1912a35934d87dcdf67b9b2db408 Mon Sep 17 00:00:00 2001 From: Andrew Bullock Date: Mon, 15 Mar 2021 07:33:26 +0000 Subject: [PATCH 2/2] bumped version --- changelog.md | 3 +++ src/NUglify/NUglify.csproj | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 2ef25f56..6f76d2f3 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,9 @@ ## vNext (unpublished) +## v1.13.7 (15 Mar 2021) +- Fixes bug with javascript pretty-print formatting and empty object initializers {} + ## v1.13.6 (9 Mar 2021) - Fixes bug with json script elements in HTML e.g. application/ld+json diff --git a/src/NUglify/NUglify.csproj b/src/NUglify/NUglify.csproj index 5a1292a2..36295ec7 100644 --- a/src/NUglify/NUglify.csproj +++ b/src/NUglify/NUglify.csproj @@ -17,7 +17,7 @@ git git://github.com/trullock/NUglify 1.6.0 - 1.13.6 + 1.13.7 latest