Skip to content

Commit

Permalink
Make sure null conditionals break like regular expressions (#593)
Browse files Browse the repository at this point in the history
closes #561

Co-authored-by: Lasath Fernando <devel@lasath.org>
  • Loading branch information
belav and shocklateboy92 authored Feb 7, 2022
1 parent 6be42ee commit 38400ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class ClassName
.DoSomething___________________()
.DoSomething___________________();

this.DoSomething___________________()
?.DoSomething___________________()
?.DoSomething___________________();

base.DoSomething___________________()
.DoSomething___________________()
.DoSomething___________________();
Expand Down Expand Up @@ -157,8 +161,8 @@ class ClassName
two__________________________________
);

SomeObject?
.CallMethod(parameter_______________________________________________________________)
SomeObject
?.CallMethod(parameter_______________________________________________________________)
.ToArray();

SomeObject
Expand Down
5 changes: 5 additions & 0 deletions Src/CSharpier/DocTypes/Doc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ namespace CSharpier.DocTypes;

internal abstract class Doc
{
public override string ToString()
{
return DocSerializer.Serialize(this);
}

public static implicit operator Doc(string value)
{
return new StringDoc(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,11 @@ And we want to work with them from Left to Right
}
else if (expression is ConditionalAccessExpressionSyntax conditionalAccessExpressionSyntax)
{
FlattenAndPrintNodes(conditionalAccessExpressionSyntax.Expression, printedNodes);
printedNodes.Add(
new PrintedNode(
conditionalAccessExpressionSyntax,
Doc.Concat(
Node.Print(conditionalAccessExpressionSyntax.Expression),
Token.Print(conditionalAccessExpressionSyntax.OperatorToken)
)
Token.Print(conditionalAccessExpressionSyntax.OperatorToken)
)
);
FlattenAndPrintNodes(conditionalAccessExpressionSyntax.WhenNotNull, printedNodes);
Expand Down

0 comments on commit 38400ba

Please sign in to comment.