Skip to content

Commit

Permalink
Generate conditional access, member binding expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
AnaCoda authored Aug 16, 2023
1 parent 0835036 commit 4773cc7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ CancellationToken token
private bool m_removeAsyncAnywhere;

public TransformResult<MethodDeclarationSyntax> Transform( MethodDeclarationSyntax decl ) {
// TODO: remove CancellationToken parameters
decl = decl.WithAttributeLists( ReplaceGenerateSyncAttribute( decl.AttributeLists ) )
.WithModifiers( RemoveAsyncModifier( decl.Modifiers ) )
.WithIdentifier( RemoveAsyncSuffix( decl.Identifier ) )
Expand Down Expand Up @@ -328,6 +327,13 @@ private ExpressionSyntax Transform( ExpressionSyntax expr )
AnonymousObjectCreationExpressionSyntax anonCreationExpr => anonCreationExpr
.WithInitializers( TransformAnonDecls( anonCreationExpr.Initializers ) ),

ConditionalAccessExpressionSyntax condAccessExpr => condAccessExpr
.WithExpression( Transform( condAccessExpr.Expression ) )
.WithWhenNotNull( Transform( condAccessExpr.WhenNotNull ) ),

MemberBindingExpressionSyntax memBindExpr => memBindExpr
.WithName( Transform( memBindExpr.Name ) ),

_ => UnhandledSyntax( expr )
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,15 @@ public void AsyncParenthesizedBlockLambda() {
Assert.AreEqual( @"[Blocking] void Bar() { Create( () => { using( new Context() ) { Baz(); } } ); }", actual.Value.ToFullString() );
}

[Test]
public void ConditionalAccessExpression() {
var actual = Transform( @"[GenerateSync] async Task BarAsync() { await m_baz?.PushAsync(); }" );

Assert.IsTrue( actual.Success );
Assert.IsEmpty( actual.Diagnostics );
Assert.AreEqual( @"[Blocking] void Bar() { m_baz?.Push(); }", actual.Value.ToFullString() );
}

[Test]
public void Silly() {
var actual = Transform( @"[GenerateSync]
Expand Down

0 comments on commit 4773cc7

Please sign in to comment.