Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Commit 69780da

Browse files
committed
Extra newline no longer rendered at the end of a code block
1 parent 08c8f9f commit 69780da

17 files changed

+45
-37
lines changed

src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ private void VerbatimBlock()
321321
PutCurrentBack();
322322
}
323323

324-
CompleteBlock(insertMarkerIfNecessary: false);
324+
CompleteBlock(insertMarkerIfNecessary: false, captureWhitespaceToEndOfLine: true);
325325
Output(SpanKind.MetaCode);
326326
}
327327

test/Microsoft.AspNet.Razor.Test/Parser/Html/HtmlDocumentTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,20 @@ public void ParseDocumentIgnoresTagsInContentsOfScriptTag()
290290
BlockFactory.MarkupTagBlock("</script>")));
291291
}
292292

293+
[Fact]
294+
public void ParseDocumentDoesNotRenderExtraNewLine()
295+
{
296+
ParseDocumentTest("@{\r\n}\r\n<html>",
297+
new MarkupBlock(
298+
Factory.EmptyHtml(),
299+
new StatementBlock(
300+
Factory.CodeTransition(),
301+
Factory.MetaCode("{").Accepts(AcceptedCharacters.None),
302+
Factory.Code("\r\n").AsStatement().AutoCompleteWith(null, false),
303+
Factory.MetaCode("}\r\n").Accepts(AcceptedCharacters.None)),
304+
BlockFactory.MarkupTagBlock("<html>")));
305+
}
306+
293307
[Fact]
294308
public void ParseSectionIgnoresTagsInContentsOfScriptTag()
295309
{

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/Blocks.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public override async Task ExecuteAsync()
2121
#line default
2222
#line hidden
2323

24-
Instrumentation.BeginContext(21, 4, true);
25-
WriteLiteral("\r\n\r\n");
24+
Instrumentation.BeginContext(23, 2, true);
25+
WriteLiteral("\r\n");
2626
Instrumentation.EndContext();
2727
#line 5 "Blocks.cshtml"
2828
while(i <= 10) {

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/CodeBlockWithTextElement.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ public override async Task ExecuteAsync()
5757
#line default
5858
#line hidden
5959

60-
Instrumentation.BeginContext(83, 2, true);
61-
WriteLiteral("\r\n");
62-
Instrumentation.EndContext();
6360
}
6461
#pragma warning restore 1998
6562
}

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/ComplexTagHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ public override async Task ExecuteAsync()
265265
#line default
266266
#line hidden
267267

268-
Instrumentation.BeginContext(805, 14, true);
269-
WriteLiteral("\r\n ");
268+
Instrumentation.BeginContext(807, 12, true);
269+
WriteLiteral(" ");
270270
Instrumentation.EndContext();
271271
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", TagMode.StartTagOnly, "test", async() => {
272272
}

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/ExpressionsInCode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public override async Task ExecuteAsync()
2222
#line default
2323
#line hidden
2424

25-
Instrumentation.BeginContext(54, 4, true);
26-
WriteLiteral("\r\n\r\n");
25+
Instrumentation.BeginContext(56, 2, true);
26+
WriteLiteral("\r\n");
2727
Instrumentation.EndContext();
2828
#line 6 "ExpressionsInCode.cshtml"
2929
if(foo != null) {

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/Instrumented.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public override async Task ExecuteAsync()
4242
#line default
4343
#line hidden
4444

45-
Instrumentation.BeginContext(94, 4, true);
46-
WriteLiteral("\r\n\r\n");
45+
Instrumentation.BeginContext(96, 2, true);
46+
WriteLiteral("\r\n");
4747
Instrumentation.EndContext();
4848
#line 8 "Instrumented.cshtml"
4949
while(i <= 10) {

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/MarkupInCodeBlock.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ public override async Task ExecuteAsync()
4040
#line default
4141
#line hidden
4242

43-
Instrumentation.BeginContext(96, 2, true);
44-
WriteLiteral("\r\n");
45-
Instrumentation.EndContext();
4643
}
4744
#pragma warning restore 1998
4845
}

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/NoLinePragmas.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public override async Task ExecuteAsync()
2121
#line default
2222
#line hidden
2323

24-
Instrumentation.BeginContext(21, 4, true);
25-
WriteLiteral("\r\n\r\n");
24+
Instrumentation.BeginContext(23, 2, true);
25+
WriteLiteral("\r\n");
2626
Instrumentation.EndContext();
2727
#line 5 ""
2828
while(i <= 10) {

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/NullConditionalExpressions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public override async Task ExecuteAsync()
7676
#line default
7777
#line hidden
7878

79-
Instrumentation.BeginContext(135, 4, true);
80-
WriteLiteral("\r\n\r\n");
79+
Instrumentation.BeginContext(137, 2, true);
80+
WriteLiteral("\r\n");
8181
Instrumentation.EndContext();
8282
Instrumentation.BeginContext(140, 13, false);
8383
#line 8 "NullConditionalExpressions.cshtml"

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/PrefixedAttributeTagHelpers.Reversed.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public override async Task ExecuteAsync()
4343
#line default
4444
#line hidden
4545

46-
Instrumentation.BeginContext(280, 51, true);
47-
WriteLiteral("\r\n\r\n<div class=\"randomNonTagHelperAttribute\">\r\n ");
46+
Instrumentation.BeginContext(282, 49, true);
47+
WriteLiteral("\r\n<div class=\"randomNonTagHelperAttribute\">\r\n ");
4848
Instrumentation.EndContext();
4949
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", TagMode.SelfClosing, "test", async() => {
5050
}

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/PrefixedAttributeTagHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public override async Task ExecuteAsync()
4343
#line default
4444
#line hidden
4545

46-
Instrumentation.BeginContext(280, 51, true);
47-
WriteLiteral("\r\n\r\n<div class=\"randomNonTagHelperAttribute\">\r\n ");
46+
Instrumentation.BeginContext(282, 49, true);
47+
WriteLiteral("\r\n<div class=\"randomNonTagHelperAttribute\">\r\n ");
4848
Instrumentation.EndContext();
4949
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", TagMode.SelfClosing, "test", async() => {
5050
}

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/RazorComments.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ public override async Task ExecuteAsync()
4040
#line default
4141
#line hidden
4242

43-
Instrumentation.BeginContext(232, 4, true);
44-
WriteLiteral("\r\n\r\n");
43+
Instrumentation.BeginContext(234, 2, true);
44+
WriteLiteral("\r\n");
4545
Instrumentation.EndContext();
4646
#line 12 "RazorComments.cshtml"
4747
var bar = "@* bar *@";
4848

4949
#line default
5050
#line hidden
5151

52-
Instrumentation.BeginContext(263, 46, true);
53-
WriteLiteral("\r\n<p>But this should show the comment syntax: ");
52+
Instrumentation.BeginContext(265, 44, true);
53+
WriteLiteral("<p>But this should show the comment syntax: ");
5454
Instrumentation.EndContext();
5555
Instrumentation.BeginContext(310, 3, false);
5656
#line 13 "RazorComments.cshtml"

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/Sections.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public override async Task ExecuteAsync()
2121
#line default
2222
#line hidden
2323

24-
Instrumentation.BeginContext(47, 33, true);
25-
WriteLiteral("\r\n\r\n<div>This is in the Body>\r\n\r\n");
24+
Instrumentation.BeginContext(49, 31, true);
25+
WriteLiteral("\r\n<div>This is in the Body>\r\n\r\n");
2626
Instrumentation.EndContext();
2727
DefineSection("Section2", async(__razor_template_writer) => {
2828
Instrumentation.BeginContext(99, 39, true);

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/TagHelpersInSection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public override async Task ExecuteAsync()
3535
#line default
3636
#line hidden
3737

38-
Instrumentation.BeginContext(69, 4, true);
39-
WriteLiteral("\r\n\r\n");
38+
Instrumentation.BeginContext(71, 2, true);
39+
WriteLiteral("\r\n");
4040
Instrumentation.EndContext();
4141
DefineSection("MySection", async(__razor_template_writer) => {
4242
Instrumentation.BeginContext(93, 21, true);

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/Templates.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public override async Task ExecuteAsync()
7272
#line default
7373
#line hidden
7474

75-
Instrumentation.BeginContext(367, 10, true);
76-
WriteLiteral("\r\n\r\n<ul>\r\n");
75+
Instrumentation.BeginContext(369, 8, true);
76+
WriteLiteral("\r\n<ul>\r\n");
7777
Instrumentation.EndContext();
7878
Instrumentation.BeginContext(379, 11, false);
7979
#line 17 "Templates.cshtml"
@@ -156,8 +156,8 @@ public override async Task ExecuteAsync()
156156
#line default
157157
#line hidden
158158

159-
Instrumentation.BeginContext(574, 79, true);
160-
WriteLiteralTo(__razor_template_writer, "\r\n <ul>\r\n <li>Child Items... ?</li>\r\n </ul>\r\n </li>");
159+
Instrumentation.BeginContext(576, 77, true);
160+
WriteLiteralTo(__razor_template_writer, " <ul>\r\n <li>Child Items... ?</li>\r\n </ul>\r\n </li>");
161161
Instrumentation.EndContext();
162162
}
163163
)

test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/TransitionsInTagHelperAttributes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public override async Task ExecuteAsync()
3232
#line default
3333
#line hidden
3434

35-
Instrumentation.BeginContext(95, 4, true);
36-
WriteLiteral("\r\n\r\n");
35+
Instrumentation.BeginContext(97, 2, true);
36+
WriteLiteral("\r\n");
3737
Instrumentation.EndContext();
3838
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", TagMode.StartTagAndEndTag, "test", async() => {
3939
Instrumentation.BeginContext(128, 11, true);

0 commit comments

Comments
 (0)