Skip to content

Commit

Permalink
Merge pull request trullock#347 from zhangyiatmicrosoft/issue345
Browse files Browse the repository at this point in the history
Fix issue 345
  • Loading branch information
trullock authored Jan 26, 2023
2 parents a0de178 + 7683284 commit 1576542
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/NUglify.Tests/JavaScript/Bugs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,11 @@ public void Bug306()
{
TestHelper.Instance.RunTest("-js:json");
}

[Test]
public void Bug345()
{
TestHelper.Instance.RunTest("-rename:all");
}
}
}
6 changes: 6 additions & 0 deletions src/NUglify.Tests/NUglify.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@
<Content Include="TestData\JS\Expected\Bugs\Bug264.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Expected\Bugs\Bug345.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Expected\ES2015\ConciseMethods.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -2986,6 +2989,9 @@
<Content Include="TestData\JS\Input\Bugs\Bug264.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Input\Bugs\Bug345.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="TestData\JS\Input\CommandLine\Expression.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
1 change: 1 addition & 0 deletions src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug345.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"use strict";function test1({n=1,t=2}={}){console.log(n+t)}function test2(n=1,t=2){console.log(n+t)}
13 changes: 13 additions & 0 deletions src/NUglify.Tests/TestData/JS/Input/Bugs/Bug345.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

function test1(
{
verylongname_x = 1,
verylongname_y = 2
} = {}) {
console.log(verylongname_x + verylongname_y);
}

function test2(verylongname_x = 1, verylongname_y = 2) {
console.log(verylongname_x + verylongname_y);
}
24 changes: 15 additions & 9 deletions src/NUglify/JavaScript/Visitors/AnalyzeNodeVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3366,18 +3366,24 @@ public override void Visit(ObjectLiteral node)
string keyName = property.Name?.Name;

if (keyName == null)
keyName = functionObject?.Binding?.Name;
keyName = functionObject?.Binding?.Name;

if (keyName == null)
{
if (property.Value is UnaryExpression ue && ue.OperatorToken == JSToken.RestSpread)
{
keyName = property.Value.Context.ToString();
}
else
{
keyName = property.Value?.ToString();
}
if (property.Value is UnaryExpression ue && ue.OperatorToken == JSToken.RestSpread)
{
keyName = property.Value.Context.ToString();
}
else if (property.Value is InitializerNode inode
&& inode.Binding is BindingIdentifier bi
&& !bi.Name.IsNullOrWhiteSpace())
{
keyName = bi.Name;
}
else
{
keyName = property.Value?.ToString();
}
}

keyName += propertyType;
Expand Down

0 comments on commit 1576542

Please sign in to comment.