From 78a19c07e90b1a086c28e455cef16099ea11bdca Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Tue, 20 Feb 2018 14:57:31 +0000 Subject: [PATCH] In RazorCompiler, allow HTML comments --- samples/StandaloneApp/App.cshtml | 8 +++++++- .../BlazorIntermediateNodeWriter.cs | 3 +++ .../RazorCompilerTest.cs | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/samples/StandaloneApp/App.cshtml b/samples/StandaloneApp/App.cshtml index 00e26124af..e7bed1320d 100644 --- a/samples/StandaloneApp/App.cshtml +++ b/samples/StandaloneApp/App.cshtml @@ -1,2 +1,8 @@ @using Microsoft.AspNetCore.Blazor.Browser.Routing - + + diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorIntermediateNodeWriter.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorIntermediateNodeWriter.cs index 9621a56aa8..3901555366 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorIntermediateNodeWriter.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorIntermediateNodeWriter.cs @@ -285,6 +285,9 @@ namespace Microsoft.AspNetCore.Blazor.Razor break; } + case HtmlTokenType.Comment: + break; + default: throw new InvalidCastException($"Unsupported token type: {nextToken.Type.ToString()}"); } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs index e02ec49362..cb825b3307 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs @@ -187,6 +187,19 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test frame => AssertFrame.Element(frame, "img", 1, 1)); } + [Fact] + public void SupportsComments() + { + // Arrange/Act + var component = CompileToComponent("StartEnd"); + var frames = GetRenderTree(component); + + // Assert + Assert.Collection(frames, + frame => AssertFrame.Text(frame, "Start", 0), + frame => AssertFrame.Text(frame, "End", 1)); + } + [Fact] public void SupportsAttributesWithLiteralValues() {