Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ public void ConditionalAttributes2()
[IntegrationTestFact]
public void TagHelpersWithBoundAttributes() => RunTagHelpersTest(TestTagHelperDescriptors.SimpleTagHelperDescriptors);

[IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/12261")]
public void TagHelpersWithBoundAttributesAndRazorComment() => RunTagHelpersTest(TestTagHelperDescriptors.SimpleTagHelperDescriptors);

[IntegrationTestFact]
public void TagHelpersWithPrefix() => RunTagHelpersTest(TestTagHelperDescriptors.SimpleTagHelperDescriptors);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ public void ConditionalAttribute_CommentBefore()
ParseDocumentTest("""<p @* comment *@ class="@c" />""");
}

[Fact, WorkItem("https://github.com/dotnet/razor/issues/12261")]
public void AttributeAfterComment()
{
ParseDocumentTest("""<p class="first" @* comment *@ data-value="second" />""");
}

[Fact]
public void EscapedAttributeName_WithValue()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2472,4 +2472,104 @@ public void Rewrites_MinimizedComponentDirectiveAttributes()
builder.AllowCSharpInMarkupAttributeArea = false;
});
}

[Fact, WorkItem("https://github.com/dotnet/razor/issues/12261")]
public void TagHelper_AttributeAfterRazorComment()
{
// Arrange
var descriptors = ImmutableArray.Create(
TagHelperDescriptorBuilder.CreateTagHelper("PTagHelper", "TestAssembly")
.TagMatchingRuleDescriptor(rule => rule.RequireTagName("p"))
.BoundAttributeDescriptor(attribute => attribute
.Name("attribute-1")
.PropertyName("Attribute1")
.TypeName(typeof(string).FullName))
.BoundAttributeDescriptor(attribute => attribute
.Name("not-visible")
.PropertyName("NotVisible")
.TypeName(typeof(bool).FullName))
.Build());

// Act & Assert
EvaluateData(descriptors, """
<p
attribute-1="true"
@* visible *@
not-visible>
</p>
""");
}

[Fact, WorkItem("https://github.com/dotnet/razor/issues/12261")]
public void TagHelper_MultipleAttributesAfterRazorComment()
{
// Arrange
var descriptors = ImmutableArray.Create(
TagHelperDescriptorBuilder.CreateTagHelper("PTagHelper", "TestAssembly")
.TagMatchingRuleDescriptor(rule => rule.RequireTagName("p"))
.BoundAttributeDescriptor(attribute => attribute
.Name("attr-1")
.PropertyName("Attr1")
.TypeName(typeof(string).FullName))
.BoundAttributeDescriptor(attribute => attribute
.Name("attr-2")
.PropertyName("Attr2")
.TypeName(typeof(string).FullName))
.BoundAttributeDescriptor(attribute => attribute
.Name("attr-3")
.PropertyName("Attr3")
.TypeName(typeof(string).FullName))
.Build());

// Act & Assert
EvaluateData(descriptors, """
<p attr-1="first" @* comment *@ attr-2="second" attr-3="third"></p>
""");
}

[Fact, WorkItem("https://github.com/dotnet/razor/issues/12261")]
public void TagHelper_MultipleInterleavedRazorComments()
{
// Arrange
var descriptors = ImmutableArray.Create(
TagHelperDescriptorBuilder.CreateTagHelper("InputTagHelper", "TestAssembly")
.TagMatchingRuleDescriptor(rule => rule.RequireTagName("input"))
.BoundAttributeDescriptor(attribute => attribute
.Name("type")
.PropertyName("Type")
.TypeName(typeof(string).FullName))
.BoundAttributeDescriptor(attribute => attribute
.Name("value")
.PropertyName("Value")
.TypeName(typeof(string).FullName))
.Build());

// Act & Assert
EvaluateData(descriptors, """
<input @* comment1 *@ type="text" @* comment2 *@ value="test" @* comment3 *@ />
""");
}

[Fact, WorkItem("https://github.com/dotnet/razor/issues/12261")]
public void TagHelper_MinimizedAttributeAfterRazorComment()
{
// Arrange
var descriptors = ImmutableArray.Create(
TagHelperDescriptorBuilder.CreateTagHelper("InputTagHelper", "TestAssembly")
.TagMatchingRuleDescriptor(rule => rule.RequireTagName("input"))
.BoundAttributeDescriptor(attribute => attribute
.Name("type")
.PropertyName("Type")
.TypeName(typeof(string).FullName))
.BoundAttributeDescriptor(attribute => attribute
.Name("checked")
.PropertyName("Checked")
.TypeName(typeof(bool).FullName))
.Build());

// Act & Assert
EvaluateData(descriptors, """
<input type="checkbox" @* comment *@ checked />
""");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@addTagHelper *, TestAssembly
<input value="Hello" @* comment between attributes *@ bound="World" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// <auto-generated/>
#pragma warning disable 1591
namespace AspNetCoreGeneratedDocument
{
#line default
using TModel = global::System.Object;
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Mvc;
using global::Microsoft.AspNetCore.Mvc.Rendering;
using global::Microsoft.AspNetCore.Mvc.ViewFeatures;
#line default
#line hidden
[global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/TagHelpersWithBoundAttributesAndRazorComment.cshtml")]
[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute]
#nullable restore
internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_TagHelpersWithBoundAttributesAndRazorComment : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<dynamic>
#nullable disable
{
#line hidden
#pragma warning disable 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext;
#pragma warning restore 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
private global::InputTagHelper __InputTagHelper;
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((global::System.Action)(() => {
#nullable restore
#line 1 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/TagHelpersWithBoundAttributesAndRazorComment.cshtml"
global::System.Object __typeHelper = "*, TestAssembly";

#line default
#line hidden
#nullable disable
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
public async override global::System.Threading.Tasks.Task ExecuteAsync()
{
__InputTagHelper = CreateTagHelper<global::InputTagHelper>();
__InputTagHelper.FooProp = "Hello";
__InputTagHelper.BoundProp = "World";
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
}
#pragma warning restore 1998
#nullable restore
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } = default!;
#nullable disable
#nullable restore
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } = default!;
#nullable disable
#nullable restore
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } = default!;
#nullable disable
#nullable restore
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } = default!;
#nullable disable
#nullable restore
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<dynamic> Html { get; private set; } = default!;
#nullable disable
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*~~~~~~~~~*/ ~~ /*~~~~~~~~*/
<input value="Hello" ~~ /*~~~*/ /*~~~*/ /*~~~~~~*/ ~~ bound="World" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Document -
NamespaceDeclaration - - AspNetCoreGeneratedDocument
UsingDirective - - TModel = global::System.Object
UsingDirective - (1:0,1 [20] ) - global::System
UsingDirective - (24:1,1 [40] ) - global::System.Collections.Generic
UsingDirective - (67:2,1 [25] ) - global::System.Linq
UsingDirective - (95:3,1 [36] ) - global::System.Threading.Tasks
UsingDirective - (134:4,1 [38] ) - global::Microsoft.AspNetCore.Mvc
UsingDirective - (175:5,1 [48] ) - global::Microsoft.AspNetCore.Mvc.Rendering
UsingDirective - (226:6,1 [51] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures
RazorCompiledItemMetadataAttribute -
CreateNewOnMetadataUpdateAttribute -
ClassDeclaration - - internal sealed - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_TagHelpersWithBoundAttributesAndRazorComment - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<dynamic> -
DefaultTagHelperRuntime -
FieldDeclaration - - private - global::InputTagHelper - __InputTagHelper
DesignTimeDirective -
DirectiveToken - (287:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>
DirectiveToken - (350:7,71 [4] ) - Html
DirectiveToken - (364:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper
DirectiveToken - (419:8,63 [4] ) - Json
DirectiveToken - (433:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper
DirectiveToken - (487:9,62 [9] ) - Component
DirectiveToken - (506:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper
DirectiveToken - (550:10,52 [3] ) - Url
DirectiveToken - (563:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider
DirectiveToken - (634:11,79 [23] ) - ModelExpressionProvider
DirectiveToken - (673:12,14 [104] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor
DirectiveToken - (793:13,14 [95] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper, Microsoft.AspNetCore.Mvc.Razor
DirectiveToken - (904:14,14 [95] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper, Microsoft.AspNetCore.Mvc.Razor
DirectiveToken - (14:0,14 [15] TagHelpersWithBoundAttributesAndRazorComment.cshtml) - *, TestAssembly
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (29:0,29 [2] TagHelpersWithBoundAttributesAndRazorComment.cshtml)
LazyIntermediateToken - (29:0,29 [2] TagHelpersWithBoundAttributesAndRazorComment.cshtml) - Html - \n
TagHelper - (31:1,0 [70] TagHelpersWithBoundAttributesAndRazorComment.cshtml) - input - TagMode.SelfClosing
DefaultTagHelperBody -
DefaultTagHelperCreate - - InputTagHelper
DefaultTagHelperProperty - (45:1,14 [5] TagHelpersWithBoundAttributesAndRazorComment.cshtml) - value - string InputTagHelper.FooProp - HtmlAttributeValueStyle.DoubleQuotes
HtmlContent - (45:1,14 [5] TagHelpersWithBoundAttributesAndRazorComment.cshtml)
LazyIntermediateToken - (45:1,14 [5] TagHelpersWithBoundAttributesAndRazorComment.cshtml) - Html - Hello
DefaultTagHelperProperty - (92:1,61 [5] TagHelpersWithBoundAttributesAndRazorComment.cshtml) - bound - string InputTagHelper.BoundProp - HtmlAttributeValueStyle.DoubleQuotes
HtmlContent - (92:1,61 [5] TagHelpersWithBoundAttributesAndRazorComment.cshtml)
LazyIntermediateToken - (92:1,61 [5] TagHelpersWithBoundAttributesAndRazorComment.cshtml) - Html - World
DefaultTagHelperExecute -
HtmlContent - (101:1,70 [2] TagHelpersWithBoundAttributesAndRazorComment.cshtml)
LazyIntermediateToken - (101:1,70 [2] TagHelpersWithBoundAttributesAndRazorComment.cshtml) - Html - \n
Inject -
Inject -
Inject -
Inject -
Inject -
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Source Location: (14:0,14 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/TagHelpersWithBoundAttributesAndRazorComment.cshtml)
|*, TestAssembly|
Generated Location: (1815:32,38 [15] )
|*, TestAssembly|

Loading
Loading