Skip to content

Commit

Permalink
Merge pull request #157 from trullock/bug_156
Browse files Browse the repository at this point in the history
fixes #156 optional chaining
  • Loading branch information
trullock authored Oct 1, 2020
2 parents ce8c85c + 3770ec5 commit a5c2c1e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 22 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 @@ -128,5 +128,11 @@ public void Bug139_A()
Assert.AreEqual("var testString=`\n\r`+`} async init(){ }`", uglifyResult.Code);

}

[Test]
public void Bug156()
{
TestHelper.Instance.RunTest();
}
}
}
6 changes: 6 additions & 0 deletions src/NUglify.Tests/NUglify.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@
<Content Include="TestData\JS\Expected\Bugs\Bug138.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Expected\Bugs\Bug156.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Expected\Bugs\Bug70.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -2745,6 +2748,9 @@
<Content Include="TestData\JS\Input\Bugs\Bug139.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Input\Bugs\Bug156.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Input\Bugs\Bug94.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
34 changes: 17 additions & 17 deletions src/NUglify.Tests/NUglify.Tests.nuget.props
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.lock.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\alexr.GTSRO\.nuget\packages\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">ProjectJson</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">5.3.1</NuGetToolVersion>
</PropertyGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgNUnit3TestAdapter Condition=" '$(PkgNUnit3TestAdapter)' == '' ">C:\Users\alexr.GTSRO\.nuget\packages\nunit3testadapter\3.5.0</PkgNUnit3TestAdapter>
</PropertyGroup>
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.lock.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\trull\.nuget\packages\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">ProjectJson</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">5.6.0</NuGetToolVersion>
</PropertyGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgNUnit3TestAdapter Condition=" '$(PkgNUnit3TestAdapter)' == '' ">C:\Users\trull\.nuget\packages\nunit3testadapter\3.5.0</PkgNUnit3TestAdapter>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions src/NUglify.Tests/TestData/JS/Expected/Bugs/Bug156.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a?.b;let x=a?.b
Original file line number Diff line number Diff line change
@@ -1 +1 @@
let x=foo.?bar,y=foo.?(),z=foo.?().?[],p=foo?.3:0;return x+y+z
let x=foo?.bar,y=foo?.(),z=foo?.()?.[a],p=foo?.3:0;return x+y+z
2 changes: 2 additions & 0 deletions src/NUglify.Tests/TestData/JS/Input/Bugs/Bug156.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a?.b;
let x = a?.b;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let x = foo?.bar;
let y = foo?.();
let z = foo?.()?.[];
let z = foo?.()?.[a];

// should be treated as a conditional expression
let p = foo?.3 : 0;
Expand Down
6 changes: 3 additions & 3 deletions src/NUglify/JavaScript/Visitors/OutputVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,8 @@ public void Visit(CallExpression node)
{
if (node.OptionalChaining)
{
OutputPossibleLineBreak('.');
OutputPossibleLineBreak('?');
OutputPossibleLineBreak('.');
}

OutputPossibleLineBreak(node.InBrackets ? '[' : '(');
Expand Down Expand Up @@ -2499,9 +2499,9 @@ public void Visit(MemberExpression node)
SetContextOutputPosition(node.Context);
}

OutputPossibleLineBreak('.');
if(node.OptionalChaining)
if (node.OptionalChaining)
OutputPossibleLineBreak('?');
OutputPossibleLineBreak('.');

MarkSegment(node, node.Name, node.NameContext);
Output(node.Name);
Expand Down

0 comments on commit a5c2c1e

Please sign in to comment.