Skip to content

Commit

Permalink
Merge pull request #109 from LorettaDevs/normalizer-fix
Browse files Browse the repository at this point in the history
Fix NormalizeWhitespace not inserting spaces between expression list arguments.
  • Loading branch information
TheGreatSageEqualToHeaven authored Nov 15, 2022
2 parents d6c8100 + 950eeef commit 327f21e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Fixed
- Fixed `ContainedScopes` not being populated.
- Fixed NormalizeWhitespace not inserting spaces between expression list arguments.

## v0.2.10
### Added
Expand Down
11 changes: 11 additions & 0 deletions src/Compilers/Lua/Portable/Syntax/SyntaxNormalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,17 @@ private TReturn WithTempState<TArg, TReturn>(Func<TArg, TReturn> func, TArg arg)
return base.VisitMethodCallExpression(node);
}

// expression_list_function_argument
// : '(' (expression (',' expression)*)? ')'
// ;
public override SyntaxNode? VisitExpressionListFunctionArgument(ExpressionListFunctionArgumentSyntax node)
{
foreach (var expressionSeparator in node.Expressions.GetSeparators())
AddSpaceAfterToken(expressionSeparator);

return base.VisitExpressionListFunctionArgument(node);
}

// Visiting ParenthesizedExpressionSyntax is not necessary as it has no spacing.
// Visiting ElementAccessExpressionSyntax is not necessary as it has no spacing.
// Visiting MemberAccessExpressionSyntax is not necessary as it has no spacing.
Expand Down
12 changes: 12 additions & 0 deletions src/Compilers/Lua/Test/Portable/Syntax/SyntaxNormalizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Text.RegularExpressions;
using Loretta.CodeAnalysis.Lua.Test.Utilities;
using Loretta.Test.Utilities;
using Xunit;
using Xunit.Sdk;

Expand Down Expand Up @@ -1223,6 +1224,17 @@ public void SyntaxNormalizer_CorrectlyRewritesTypes(string input, string expecte
AssertNormalizeCore(type, expected);
}

[Fact]
[WorkItem(108, "https://github.com/LorettaDevs/Loretta/issues/108")]
public void SyntaxNormalizer_CorrectlyInsertsExpressionSpaces()
{
var tree = ParseAndValidate("print(1,2)", s_luaParseOptions);
var root = tree.GetRoot();

AssertNormalizeCore(root, "print(1, 2)");
}


#region Class Implementation Details

private static void AssertNormalizeCore(SyntaxNode node, string expected)
Expand Down

0 comments on commit 327f21e

Please sign in to comment.