提交 f941893d 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #13076 from CyrusNajmabadi/preserveTrivia

Preserve trivia when converting a property to a method.

Fixes #12143
......@@ -293,6 +293,23 @@ private int GetProp()
}", compareTokens: false);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)]
public async Task TestComputedPropWithTrailingTriviaAfterArrow()
{
await TestAsync(
@"class C
{
public int [||]Prop => /* return 42 */ 42;
}",
@"class C
{
public int GetProp()
{
return /* return 42 */ 42;
}
}", compareTokens: false);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)]
public async Task TestAbstractProperty()
{
......
......@@ -132,8 +132,13 @@ public override SyntaxNode GetPropertyDeclaration(SyntaxToken token)
if (propertyDeclaration.ExpressionBody != null)
{
var returnStatement = SyntaxFactory.ReturnStatement(propertyDeclaration.ExpressionBody.Expression)
.WithSemicolonToken(propertyDeclaration.SemicolonToken);
var returnKeyword = SyntaxFactory.Token(SyntaxKind.ReturnKeyword)
.WithTrailingTrivia(propertyDeclaration.ExpressionBody.ArrowToken.TrailingTrivia);
var returnStatement = SyntaxFactory.ReturnStatement(
returnKeyword,
propertyDeclaration.ExpressionBody.Expression,
propertyDeclaration.SemicolonToken);
statements.Add(returnStatement);
}
else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册