Skip to content

Commit

Permalink
Merge pull request #240 from trullock/bug_239
Browse files Browse the repository at this point in the history
Bug 239
  • Loading branch information
trullock authored Mar 15, 2021
2 parents 24d3886 + f40bd20 commit a86b02a
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ function foo()
b = a
}
}
(function()
{
try
{
var a = {}
}
catch(ex) {}
})()
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@
b = a
}
}
(function() {
try {
var a = {}
}
catch(ex) {}
})()
8 changes: 7 additions & 1 deletion src/NUglify.Tests/TestData/JS/Input/Switch/PrettyPrint.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ function foo() {
}
}


(function () {
try {
var a = {};
}
catch (ex) {
}
})();
17 changes: 9 additions & 8 deletions src/NUglify/JavaScript/Visitors/OutputVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2591,21 +2591,22 @@ public void Visit(ObjectLiteral node)
if(!(node.Parent is VariableDeclaration))
Indent();

var count = node.Properties.IfNotNull(p => 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);
Expand Down
2 changes: 1 addition & 1 deletion src/NUglify/NUglify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>git://github.com/trullock/NUglify</RepositoryUrl>
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard1.3' ">1.6.0</NetStandardImplicitPackageVersion>
<Version>1.13.6</Version>
<Version>1.13.7</Version>
<PackageLicenseExpression></PackageLicenseExpression>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down

0 comments on commit a86b02a

Please sign in to comment.