Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing mappings for @layout #11639

Closed
wants to merge 4 commits into from
Closed
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 @@ -2360,6 +2360,20 @@ public void ExplicitExpression_Whitespace()
CompileToAssembly(generated);
}

[IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/11551")]
public void LayoutDirective()
{
// Act
var generated = CompileToCSharp("""
@layout System.Object
""");

// Assert
AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
CompileToAssembly(generated);
}

#endregion

#region Bind
Expand Down Expand Up @@ -10568,7 +10582,7 @@ @layout MainLayout
Diagnostic(ErrorCode.ERR_NameNotInContext, "Foo").WithArguments("Foo").WithLocation(5, 2),
// (33,13): error CS0103: The name '__builder' does not exist in the current context
// __builder.AddContent(0,
Diagnostic(ErrorCode.ERR_NameNotInContext, "__builder").WithArguments("__builder").WithLocation(33, 13)]);
Diagnostic(ErrorCode.ERR_NameNotInContext, "__builder").WithArguments("__builder").WithLocation(41, 13)]);
}

[IntegrationTestFact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
UsingDirective - (1:0,1 [17] x:\dir\subdir\Test\_Imports.razor) - System.Text
UsingDirective - (21:1,1 [23] x:\dir\subdir\Test\_Imports.razor) - System.Reflection
CSharpCode -
IntermediateToken - - CSharp - [global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))]
IntermediateToken - - CSharp - [global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(
IntermediateToken - - CSharp - MainLayout
IntermediateToken - - CSharp - ))]
ClassDeclaration - - public partial - _Imports - object -
DesignTimeDirective -
DirectiveToken - (56:3,8 [10] x:\dir\subdir\Test\_Imports.razor) - MainLayout
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
[global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(System.Object))]
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((global::System.Action)(() => {
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
System.Object __typeHelper = default!;

#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
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [20] ) - global::System
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [25] ) - global::System.Linq
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
CSharpCode -
IntermediateToken - - CSharp - [global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(
IntermediateToken - - CSharp - System.Object
IntermediateToken - - CSharp - ))]
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
DirectiveToken - (8:0,8 [13] x:\dir\subdir\Test\TestComponent.cshtml) - System.Object
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Source Location: (8:0,8 [13] x:\dir\subdir\Test\TestComponent.cshtml)
|System.Object|
Generated Location: (769:22,0 [13] )
|System.Object|

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ namespace Test
;
#line default
#line hidden
[global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))]
[global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(
#nullable restore
#line (4,9)-(4,19) "x:\dir\subdir\Test\_Imports.razor"
MainLayout

#line default
#line hidden
#nullable disable
))]
#nullable restore
public partial class _Imports : object
#nullable disable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
UsingDirective - (1:0,1 [17] x:\dir\subdir\Test\_Imports.razor) - System.Text
UsingDirective - (21:1,1 [23] x:\dir\subdir\Test\_Imports.razor) - System.Reflection
CSharpCode -
IntermediateToken - - CSharp - [global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))]
IntermediateToken - - CSharp - [global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(
IntermediateToken - (56:3,8 [10] x:\dir\subdir\Test\_Imports.razor) - CSharp - MainLayout
IntermediateToken - - CSharp - ))]
ClassDeclaration - - public partial - _Imports - object -
MethodDeclaration - - protected - void - Execute
CSharpExpression - (69:4,1 [3] x:\dir\subdir\Test\_Imports.razor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ Source Location: (21:1,1 [23] x:\dir\subdir\Test\_Imports.razor)
Generated Location: (488:18,0 [23] )
|using System.Reflection|

Source Location: (56:3,8 [10] x:\dir\subdir\Test\_Imports.razor)
|MainLayout|
Generated Location: (723:27,0 [10] )
|MainLayout|

Source Location: (69:4,1 [3] x:\dir\subdir\Test\_Imports.razor)
|Foo|
Generated Location: (953:35,0 [3] )
Generated Location: (1086:43,0 [3] )
|Foo|

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
[global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(
#nullable restore
#line (1,9)-(1,22) "x:\dir\subdir\Test\TestComponent.cshtml"
System.Object

#line default
#line hidden
#nullable disable
))]
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [20] ) - global::System
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [25] ) - global::System.Linq
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
CSharpCode -
IntermediateToken - - CSharp - [global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(
IntermediateToken - (8:0,8 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - System.Object
IntermediateToken - - CSharp - ))]
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
MethodDeclaration - - protected override - void - BuildRenderTree
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Source Location: (8:0,8 [13] x:\dir\subdir\Test\TestComponent.cshtml)
|System.Object|
Generated Location: (479:15,0 [13] )
|System.Object|

Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte
}

var attributeNode = new CSharpCodeIntermediateNode();
attributeNode.Children.Add(new IntermediateToken()
{
Kind = TokenKind.CSharp,
Content = $"[global::{ComponentsApi.LayoutAttribute.FullTypeName}(typeof({token.Content}))]",
});
attributeNode.Children.AddRange([
IntermediateToken.CreateCSharpToken($"[global::{ComponentsApi.LayoutAttribute.FullTypeName}(typeof("),
IntermediateToken.CreateCSharpToken(token.Content, documentNode.Options.DesignTime ? null : token.Source),
IntermediateToken.CreateCSharpToken("))]")
]);

// Insert the new attribute on top of the class
for (var i = 0; i < @namespace.Children.Count; i++)
Expand Down
Loading