From 1bccebd22a73556f536c53bef28e1b930d85c418 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Wed, 8 Jul 2020 12:43:09 +0100 Subject: [PATCH] Fix razor whitespace removal in methods (#23699) --- .../src/Components/ComponentWhitespacePass.cs | 16 ++-- .../ComponentCodeGenerationTestBase.cs | 29 +++++++ .../TestComponent.codegen.cs | 76 +++++++++++++++++++ .../TestComponent.ir.txt | 41 ++++++++++ .../TestComponent.mappings.txt | 46 +++++++++++ .../TestComponent.codegen.cs | 4 +- .../TestComponent.ir.txt | 4 - .../TestComponent.mappings.txt | 2 +- .../TestComponent.codegen.cs | 8 +- .../TestComponent.ir.txt | 4 - .../TestComponent.mappings.txt | 2 +- .../TestComponent.codegen.cs | 71 +++++++++++++++++ .../TestComponent.ir.txt | 24 ++++++ .../TestComponent.mappings.txt | 34 +++++++++ 14 files changed, 337 insertions(+), 24 deletions(-) create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.codegen.cs create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.ir.txt create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.mappings.txt create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.codegen.cs create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.ir.txt create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.mappings.txt diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentWhitespacePass.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentWhitespacePass.cs index 761e3eb8f4..34febfbf9a 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentWhitespacePass.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentWhitespacePass.cs @@ -45,14 +45,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Components return; } - var method = documentNode.FindPrimaryMethod(); - if (method != null) + var @class = documentNode.FindPrimaryClass(); + if (@class != null) { - RemoveContiguousWhitespace(method.Children, TraversalDirection.Forwards); - RemoveContiguousWhitespace(method.Children, TraversalDirection.Backwards); - var visitor = new Visitor(); - visitor.Visit(method); + visitor.Visit(@class); } } @@ -145,6 +142,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Components class Visitor : IntermediateNodeWalker { + public override void VisitMethodDeclaration(MethodDeclarationIntermediateNode node) + { + RemoveContiguousWhitespace(node.Children, TraversalDirection.Forwards); + RemoveContiguousWhitespace(node.Children, TraversalDirection.Backwards); + VisitDefault(node); + } + public override void VisitMarkupElement(MarkupElementIntermediateNode node) { RemoveContiguousWhitespace(node.Children, TraversalDirection.Forwards); diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs index 2c01ed31f2..d7d135b9b1 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -4685,6 +4685,35 @@ namespace Test CompileToAssembly(generated); } + [Fact] + public void WhiteSpace_InMarkupInFunctionsBlock() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@using Microsoft.AspNetCore.Components.Rendering +@code { + void MyMethod(RenderTreeBuilder __builder) + { + + } +} +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + [Fact] public void WhiteSpace_WithPreserveWhitespace() { diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.codegen.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.codegen.cs new file mode 100644 index 0000000000..f1c70de444 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.codegen.cs @@ -0,0 +1,76 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Components; +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +using Microsoft.AspNetCore.Components.Rendering; + +#line default +#line hidden +#nullable disable + public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + } + #pragma warning restore 1998 +#nullable restore +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + void MyMethod(RenderTreeBuilder __builder) + { + + +#line default +#line hidden +#nullable disable +#nullable restore +#line 6 "x:\dir\subdir\Test\TestComponent.cshtml" + for (var i = 0; i < 100; i++) + { + + +#line default +#line hidden +#nullable disable +#nullable restore +#line 9 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = i; + +#line default +#line hidden +#nullable disable +#nullable restore +#line 10 "x:\dir\subdir\Test\TestComponent.cshtml" + + } + +#line default +#line hidden +#nullable disable +#nullable restore +#line 12 "x:\dir\subdir\Test\TestComponent.cshtml" + + } + +#line default +#line hidden +#nullable disable + } +} +#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.ir.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.ir.txt new file mode 100644 index 0000000000..20ec455410 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.ir.txt @@ -0,0 +1,41 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components + UsingDirective - (1:0,1 [47] x:\dir\subdir\Test\TestComponent.cshtml) - Microsoft.AspNetCore.Components.Rendering + ClassDeclaration - - public partial - TestComponent - Microsoft.AspNetCore.Components.ComponentBase - + DesignTimeDirective - + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + HtmlContent - (48:0,48 [2] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (48:0,48 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + HtmlContent - (294:13,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (294:13,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (57:1,7 [65] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (57:1,7 [65] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n void MyMethod(RenderTreeBuilder __builder)\n {\n + MarkupElement - (122:4,8 [162] x:\dir\subdir\Test\TestComponent.cshtml) - ul + HtmlContent - (126:4,12 [14] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (126:4,12 [14] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (141:5,13 [62] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (141:5,13 [62] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - for (var i = 0; i < 100; i++)\n {\n + MarkupElement - (203:7,16 [51] x:\dir\subdir\Test\TestComponent.cshtml) - li + HtmlContent - (207:7,20 [22] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (207:7,20 [22] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpExpression - (230:8,21 [1] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (230:8,21 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - i + HtmlContent - (231:8,22 [18] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (231:8,22 [18] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (254:9,21 [15] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (254:9,21 [15] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n } + HtmlContent - (269:10,13 [10] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (269:10,13 [10] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (284:11,13 [9] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (284:11,13 [9] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n }\n diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.mappings.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.mappings.txt new file mode 100644 index 0000000000..28c9068715 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.mappings.txt @@ -0,0 +1,46 @@ +Source Location: (1:0,1 [47] x:\dir\subdir\Test\TestComponent.cshtml) +|using Microsoft.AspNetCore.Components.Rendering| +Generated Location: (320:12,0 [47] ) +|using Microsoft.AspNetCore.Components.Rendering| + +Source Location: (57:1,7 [65] x:\dir\subdir\Test\TestComponent.cshtml) +| + void MyMethod(RenderTreeBuilder __builder) + { + | +Generated Location: (1078:33,7 [65] ) +| + void MyMethod(RenderTreeBuilder __builder) + { + | + +Source Location: (141:5,13 [62] x:\dir\subdir\Test\TestComponent.cshtml) +|for (var i = 0; i < 100; i++) + { + | +Generated Location: (1278:43,13 [62] ) +|for (var i = 0; i < 100; i++) + { + | + +Source Location: (230:8,21 [1] x:\dir\subdir\Test\TestComponent.cshtml) +|i| +Generated Location: (1483:52,21 [1] ) +|i| + +Source Location: (254:9,21 [15] x:\dir\subdir\Test\TestComponent.cshtml) +| + }| +Generated Location: (1629:59,21 [15] ) +| + }| + +Source Location: (284:11,13 [9] x:\dir\subdir\Test\TestComponent.cshtml) +| + } +| +Generated Location: (1780:67,13 [9] ) +| + } +| + diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ChildComponent_InFunctionsDirective/TestComponent.codegen.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ChildComponent_InFunctionsDirective/TestComponent.codegen.cs index 03e45c5c04..78551fa4d6 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ChildComponent_InFunctionsDirective/TestComponent.codegen.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ChildComponent_InFunctionsDirective/TestComponent.codegen.cs @@ -38,10 +38,8 @@ using Microsoft.AspNetCore.Components.Rendering; #line default #line hidden #nullable disable - __builder.AddContent(0, " "); - __builder.OpenComponent(1); + __builder.OpenComponent(0); __builder.CloseComponent(); - __builder.AddMarkupContent(2, "\r\n"); #nullable restore #line 9 "x:\dir\subdir\Test\TestComponent.cshtml" } diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ChildComponent_InFunctionsDirective/TestComponent.ir.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ChildComponent_InFunctionsDirective/TestComponent.ir.txt index d41362a57c..85b0236128 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ChildComponent_InFunctionsDirective/TestComponent.ir.txt +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ChildComponent_InFunctionsDirective/TestComponent.ir.txt @@ -12,10 +12,6 @@ Document - LazyIntermediateToken - (55:2,2 [34] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderChildComponent(__builder); CSharpCode - (101:4,7 [69] x:\dir\subdir\Test\TestComponent.cshtml) LazyIntermediateToken - (101:4,7 [69] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n void RenderChildComponent(RenderTreeBuilder __builder)\n {\n - HtmlContent - (170:7,0 [8] x:\dir\subdir\Test\TestComponent.cshtml) - LazyIntermediateToken - (170:7,0 [8] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Component - (178:7,8 [15] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - HtmlContent - (193:7,23 [2] x:\dir\subdir\Test\TestComponent.cshtml) - LazyIntermediateToken - (193:7,23 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n CSharpCode - (195:8,0 [7] x:\dir\subdir\Test\TestComponent.cshtml) LazyIntermediateToken - (195:8,0 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - }\n diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ChildComponent_InFunctionsDirective/TestComponent.mappings.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ChildComponent_InFunctionsDirective/TestComponent.mappings.txt index 1ec6b9fca5..41c612f03b 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ChildComponent_InFunctionsDirective/TestComponent.mappings.txt +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ChildComponent_InFunctionsDirective/TestComponent.mappings.txt @@ -17,7 +17,7 @@ Generated Location: (968:33,7 [69] ) Source Location: (195:8,0 [7] x:\dir\subdir\Test\TestComponent.cshtml) | } | -Generated Location: (1343:46,0 [7] ) +Generated Location: (1249:44,0 [7] ) | } | diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/SingleLineControlFlowStatements_InCodeDirective/TestComponent.codegen.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/SingleLineControlFlowStatements_InCodeDirective/TestComponent.codegen.cs index 112f0033d0..0b28745c52 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/SingleLineControlFlowStatements_InCodeDirective/TestComponent.codegen.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/SingleLineControlFlowStatements_InCodeDirective/TestComponent.codegen.cs @@ -34,10 +34,9 @@ using Microsoft.AspNetCore.Components.Rendering; #line default #line hidden #nullable disable - __builder.AddContent(0, " "); - __builder.OpenElement(1, "p"); - __builder.AddContent(2, "Output: "); - __builder.AddContent(3, + __builder.OpenElement(0, "p"); + __builder.AddContent(1, "Output: "); + __builder.AddContent(2, #nullable restore #line 9 "x:\dir\subdir\Test\TestComponent.cshtml" output @@ -47,7 +46,6 @@ using Microsoft.AspNetCore.Components.Rendering; #nullable disable ); __builder.CloseElement(); - __builder.AddMarkupContent(4, "\r\n"); #nullable restore #line 10 "x:\dir\subdir\Test\TestComponent.cshtml" } diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/SingleLineControlFlowStatements_InCodeDirective/TestComponent.ir.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/SingleLineControlFlowStatements_InCodeDirective/TestComponent.ir.txt index ef0a36ec8c..b38e6f9f68 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/SingleLineControlFlowStatements_InCodeDirective/TestComponent.ir.txt +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/SingleLineControlFlowStatements_InCodeDirective/TestComponent.ir.txt @@ -10,14 +10,10 @@ Document - MethodDeclaration - - protected override - void - BuildRenderTree CSharpCode - (60:2,7 [213] x:\dir\subdir\Test\TestComponent.cshtml) LazyIntermediateToken - (60:2,7 [213] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n void RenderChildComponent(RenderTreeBuilder __builder)\n {\n var output = string.Empty;\n if (__builder == null) output = "Builder is null!";\n else output = "Builder is not null!";\n - HtmlContent - (273:8,0 [8] x:\dir\subdir\Test\TestComponent.cshtml) - LazyIntermediateToken - (273:8,0 [8] x:\dir\subdir\Test\TestComponent.cshtml) - Html - MarkupElement - (281:8,8 [22] x:\dir\subdir\Test\TestComponent.cshtml) - p HtmlContent - (284:8,11 [8] x:\dir\subdir\Test\TestComponent.cshtml) LazyIntermediateToken - (284:8,11 [8] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Output: CSharpExpression - (293:8,20 [6] x:\dir\subdir\Test\TestComponent.cshtml) LazyIntermediateToken - (293:8,20 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - output - HtmlContent - (303:8,30 [2] x:\dir\subdir\Test\TestComponent.cshtml) - LazyIntermediateToken - (303:8,30 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n CSharpCode - (305:9,0 [7] x:\dir\subdir\Test\TestComponent.cshtml) LazyIntermediateToken - (305:9,0 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - }\n diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/SingleLineControlFlowStatements_InCodeDirective/TestComponent.mappings.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/SingleLineControlFlowStatements_InCodeDirective/TestComponent.mappings.txt index 05d990ee12..d22c11086a 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/SingleLineControlFlowStatements_InCodeDirective/TestComponent.mappings.txt +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/SingleLineControlFlowStatements_InCodeDirective/TestComponent.mappings.txt @@ -18,7 +18,7 @@ Generated Location: (810:26,7 [213] ) Source Location: (305:9,0 [7] x:\dir\subdir\Test\TestComponent.cshtml) | } | -Generated Location: (1553:52,0 [7] ) +Generated Location: (1459:50,0 [7] ) | } | diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.codegen.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.codegen.cs new file mode 100644 index 0000000000..d5d4bdcc44 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.codegen.cs @@ -0,0 +1,71 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Components; +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +using Microsoft.AspNetCore.Components.Rendering; + +#line default +#line hidden +#nullable disable + public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + } + #pragma warning restore 1998 +#nullable restore +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + void MyMethod(RenderTreeBuilder __builder) + { + +#line default +#line hidden +#nullable disable + __builder.OpenElement(0, "ul"); +#nullable restore +#line 6 "x:\dir\subdir\Test\TestComponent.cshtml" + for (var i = 0; i < 100; i++) + { + +#line default +#line hidden +#nullable disable + __builder.OpenElement(1, "li"); + __builder.AddContent(2, +#nullable restore +#line 9 "x:\dir\subdir\Test\TestComponent.cshtml" + i + +#line default +#line hidden +#nullable disable + ); + __builder.CloseElement(); +#nullable restore +#line 11 "x:\dir\subdir\Test\TestComponent.cshtml" + } + +#line default +#line hidden +#nullable disable + __builder.CloseElement(); +#nullable restore +#line 13 "x:\dir\subdir\Test\TestComponent.cshtml" + } + +#line default +#line hidden +#nullable disable + } +} +#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.ir.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.ir.txt new file mode 100644 index 0000000000..266a0558b0 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.ir.txt @@ -0,0 +1,24 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [39] ) - Microsoft.AspNetCore.Components + UsingDirective - (1:0,1 [49] x:\dir\subdir\Test\TestComponent.cshtml) - Microsoft.AspNetCore.Components.Rendering + ClassDeclaration - - public partial - TestComponent - Microsoft.AspNetCore.Components.ComponentBase - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - (57:1,7 [57] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (57:1,7 [57] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n void MyMethod(RenderTreeBuilder __builder)\n {\n + MarkupElement - (122:4,8 [162] x:\dir\subdir\Test\TestComponent.cshtml) - ul + CSharpCode - (128:5,0 [12] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (128:5,0 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - + CSharpCode - (141:5,13 [46] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (141:5,13 [46] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - for (var i = 0; i < 100; i++)\n {\n + MarkupElement - (203:7,16 [51] x:\dir\subdir\Test\TestComponent.cshtml) - li + CSharpExpression - (230:8,21 [1] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (230:8,21 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - i + CSharpCode - (256:10,0 [15] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (256:10,0 [15] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - }\n + CSharpCode - (286:12,0 [7] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (286:12,0 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - }\n diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.mappings.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.mappings.txt new file mode 100644 index 0000000000..60b4af4894 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/WhiteSpace_InMarkupInFunctionsBlock/TestComponent.mappings.txt @@ -0,0 +1,34 @@ +Source Location: (57:1,7 [57] x:\dir\subdir\Test\TestComponent.cshtml) +| + void MyMethod(RenderTreeBuilder __builder) + { +| +Generated Location: (810:26,7 [57] ) +| + void MyMethod(RenderTreeBuilder __builder) + { +| + +Source Location: (141:5,13 [46] x:\dir\subdir\Test\TestComponent.cshtml) +|for (var i = 0; i < 100; i++) + { +| +Generated Location: (1041:36,13 [46] ) +|for (var i = 0; i < 100; i++) + { +| + +Source Location: (256:10,0 [15] x:\dir\subdir\Test\TestComponent.cshtml) +| } +| +Generated Location: (1474:55,0 [15] ) +| } +| + +Source Location: (286:12,0 [7] x:\dir\subdir\Test\TestComponent.cshtml) +| } +| +Generated Location: (1645:63,0 [7] ) +| } +| +