Skip to content

Commit

Permalink
Merge pull request #395 from failwyn/master
Browse files Browse the repository at this point in the history
Fixes issue with default values and javascript destructuring (#394)
  • Loading branch information
trullock committed Jun 11, 2024
2 parents 1ab2b96 + f2e7aa4 commit f0d427e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/NUglify.Tests/JavaScript/Bugs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,5 +389,10 @@ public void Bug391()
TestHelper.Instance.RunTest("-rename:all");
}

[Test]
public void Bug394()
{
TestHelper.Instance.RunTest("-rename:all");
}
}
}
8 changes: 7 additions & 1 deletion src/NUglify.Tests/NUglify.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -575,6 +575,9 @@
<Content Include="TestData\JS\Expected\Bugs\Bug391.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Expected\Bugs\Bug394.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Expected\Bugs\Bug70.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -2965,6 +2968,9 @@
<None Include="TestData\JS\Input\Bugs\Bug306.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="TestData\JS\Input\Bugs\Bug394.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Input\Bugs\Bug57.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
2 changes: 1 addition & 1 deletion src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug201.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const sum=function({t=2,n=3}){return t+n},sum2=({t=2,n=3})=>t+n
const sum=function({foo:t=2,dummy:n=3}){return t+n},sum2=({foo2:t=2,dummy2:n=3})=>t+n
2 changes: 1 addition & 1 deletion src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug345.js

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

1 change: 1 addition & 0 deletions src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug394.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const someFunc=({val:t,op:n="eq"})=>{var i=n+t};var args={val:"va",op:"contains"};someFunc(args)
10 changes: 10 additions & 0 deletions src/NUglify.Tests/TestData/JS/Input/Bugs/Bug394.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const someFunc = ({ val, op = 'eq' }) => {
var useOp = op + val;
};

var args = {
val: 'va',
op: 'contains'
};

someFunc(args);
10 changes: 10 additions & 0 deletions src/NUglify/JavaScript/JSParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4926,10 +4926,20 @@ private ObjectLiteralProperty ParseObjectLiteralProperty(bool isBindingPattern)

// just a name lookup; the property name is implicit
ParsedVersion = ScriptVersion.EcmaScript6;
var fieldContext = m_currentToken.Clone();
var fieldScanner = m_scanner.Clone();
value = ParseObjectPropertyValue(isBindingPattern);

if (isBindingPattern && m_currentToken.Is(JSToken.Assign))
{
// we need to back up to properly parse the field name
if (m_settings.LocalRenaming != LocalRenaming.KeepAll)
{
m_currentToken = fieldContext;
m_scanner = fieldScanner;
field = ParseObjectLiteralFieldName();
}

var assignContext = m_currentToken.Clone();
GetNextToken();
value = new InitializerNode(assignContext.Clone())
Expand Down

0 comments on commit f0d427e

Please sign in to comment.