Fix TypeInference code gen for non-generic parameter (dotnet/aspnetcore-tooling#433)
\n\nCommit migrated from 4233bc593c
This commit is contained in:
parent
dd5dac97e5
commit
956606ee5d
|
|
@ -182,16 +182,27 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
var p = new List<(string seqName, string typeName, string parameterName)>();
|
||||
foreach (var attribute in node.Component.Attributes)
|
||||
{
|
||||
p.Add(($"__seq{p.Count}", attribute.TypeName, $"__arg{p.Count}"));
|
||||
var typeName = attribute.TypeName;
|
||||
if (attribute.BoundAttribute != null && !attribute.BoundAttribute.IsGenericTypedProperty())
|
||||
{
|
||||
typeName = "global::" + typeName;
|
||||
}
|
||||
p.Add(($"__seq{p.Count}", typeName, $"__arg{p.Count}"));
|
||||
}
|
||||
|
||||
foreach (var childContent in node.Component.ChildContents)
|
||||
{
|
||||
p.Add(($"__seq{p.Count}", childContent.TypeName, $"__arg{p.Count}"));
|
||||
var typeName = childContent.TypeName;
|
||||
if (childContent.BoundAttribute != null && !childContent.BoundAttribute.IsGenericTypedProperty())
|
||||
{
|
||||
typeName = "global::" + typeName;
|
||||
}
|
||||
p.Add(($"__seq{p.Count}", typeName, $"__arg{p.Count}"));
|
||||
}
|
||||
|
||||
foreach (var capture in node.Component.Captures)
|
||||
{
|
||||
// The capture type name should already contain the global:: prefix.
|
||||
p.Add(($"__seq{p.Count}", capture.TypeName, $"__arg{p.Count}"));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2788,6 +2788,47 @@ namespace Test
|
|||
CompileToAssembly(generated);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenericComponent_NonGenericParameter_TypeInference()
|
||||
{
|
||||
// Arrange
|
||||
AdditionalSyntaxTrees.Add(Parse(@"
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Test.Shared;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
public class MyComponent<TItem> : ComponentBase
|
||||
{
|
||||
[Parameter] TItem Item { get; set; }
|
||||
[Parameter] MyClass Foo { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
namespace Test.Shared
|
||||
{
|
||||
public class MyClass
|
||||
{
|
||||
}
|
||||
}
|
||||
"));
|
||||
|
||||
// Act
|
||||
var generated = CompileToCSharp(@"
|
||||
@using Test.Shared
|
||||
<MyComponent Item=""3"" Foo=""@Hello"" />
|
||||
|
||||
@functions {
|
||||
MyClass Hello = new MyClass();
|
||||
}
|
||||
");
|
||||
|
||||
// Assert
|
||||
AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
|
||||
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
|
||||
CompileToAssembly(generated);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Ref
|
||||
|
|
|
|||
|
|
@ -0,0 +1,80 @@
|
|||
// <auto-generated/>
|
||||
#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 Test.Shared;
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#nullable disable
|
||||
public 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.RenderTree.RenderTreeBuilder builder)
|
||||
{
|
||||
__Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, -1, -1,
|
||||
#nullable restore
|
||||
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
|
||||
3
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#nullable disable
|
||||
, -1,
|
||||
#nullable restore
|
||||
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
|
||||
Hello
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#nullable disable
|
||||
);
|
||||
#nullable restore
|
||||
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
|
||||
__o = typeof(MyComponent<>);
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#nullable disable
|
||||
}
|
||||
#pragma warning restore 1998
|
||||
#nullable restore
|
||||
#line 4 "x:\dir\subdir\Test\TestComponent.cshtml"
|
||||
|
||||
MyClass Hello = new MyClass();
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#nullable disable
|
||||
}
|
||||
}
|
||||
namespace __Blazor.Test.TestComponent
|
||||
{
|
||||
#line hidden
|
||||
internal static class TypeInference
|
||||
{
|
||||
public static void CreateMyComponent_0<TItem>(global::Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0, int __seq1, global::Test.Shared.MyClass __arg1)
|
||||
{
|
||||
builder.OpenComponent<global::Test.MyComponent<TItem>>(seq);
|
||||
builder.AddAttribute(__seq0, "Item", __arg0);
|
||||
builder.AddAttribute(__seq1, "Foo", __arg1);
|
||||
builder.CloseComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore 1591
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
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 [17] x:\dir\subdir\Test\TestComponent.cshtml) - Test.Shared
|
||||
ClassDeclaration - - public - 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 - (18:0,18 [2] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
IntermediateToken - (18:0,18 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
|
||||
Component - (20:1,0 [37] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent
|
||||
ComponentAttribute - (39:1,19 [1] x:\dir\subdir\Test\TestComponent.cshtml) - Item - AttributeStructure.DoubleQuotes
|
||||
IntermediateToken - (39:1,19 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - 3
|
||||
ComponentAttribute - (47:1,27 [6] x:\dir\subdir\Test\TestComponent.cshtml) - Foo - AttributeStructure.DoubleQuotes
|
||||
CSharpExpression - (48:1,28 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
IntermediateToken - (48:1,28 [5] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - Hello
|
||||
HtmlContent - (57:1,37 [4] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
IntermediateToken - (57:1,37 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
|
||||
HtmlContent - (112:5,1 [2] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
IntermediateToken - (112:5,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
|
||||
CSharpCode - (73:3,12 [38] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
IntermediateToken - (73:3,12 [38] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n MyClass Hello = new MyClass();\n
|
||||
NamespaceDeclaration - - __Blazor.Test.TestComponent
|
||||
ClassDeclaration - - internal static - TypeInference - -
|
||||
ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
Source Location: (1:0,1 [17] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|using Test.Shared|
|
||||
Generated Location: (320:12,0 [17] )
|
||||
|using Test.Shared|
|
||||
|
||||
Source Location: (39:1,19 [1] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|3|
|
||||
Generated Location: (1095:32,19 [1] )
|
||||
|3|
|
||||
|
||||
Source Location: (48:1,28 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|Hello|
|
||||
Generated Location: (1266:40,28 [5] )
|
||||
|Hello|
|
||||
|
||||
Source Location: (73:3,12 [38] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|
|
||||
MyClass Hello = new MyClass();
|
||||
|
|
||||
Generated Location: (1620:57,12 [38] )
|
||||
|
|
||||
MyClass Hello = new MyClass();
|
||||
|
|
||||
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
// <auto-generated/>
|
||||
#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;
|
||||
using Test.Shared;
|
||||
public class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
|
||||
{
|
||||
#pragma warning disable 1998
|
||||
protected override void BuildRenderTree(Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder)
|
||||
{
|
||||
__Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, 0, 1, 3, 2, Hello);
|
||||
}
|
||||
#pragma warning restore 1998
|
||||
#nullable restore
|
||||
#line 4 "x:\dir\subdir\Test\TestComponent.cshtml"
|
||||
|
||||
MyClass Hello = new MyClass();
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#nullable disable
|
||||
}
|
||||
}
|
||||
namespace __Blazor.Test.TestComponent
|
||||
{
|
||||
#line hidden
|
||||
internal static class TypeInference
|
||||
{
|
||||
public static void CreateMyComponent_0<TItem>(global::Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0, int __seq1, global::Test.Shared.MyClass __arg1)
|
||||
{
|
||||
builder.OpenComponent<global::Test.MyComponent<TItem>>(seq);
|
||||
builder.AddAttribute(__seq0, "Item", __arg0);
|
||||
builder.AddAttribute(__seq1, "Foo", __arg1);
|
||||
builder.CloseComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore 1591
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
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 [19] x:\dir\subdir\Test\TestComponent.cshtml) - Test.Shared
|
||||
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
|
||||
MethodDeclaration - - protected override - void - BuildRenderTree
|
||||
Component - (20:1,0 [37] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent
|
||||
ComponentAttribute - (39:1,19 [1] x:\dir\subdir\Test\TestComponent.cshtml) - Item - AttributeStructure.DoubleQuotes
|
||||
IntermediateToken - (39:1,19 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - 3
|
||||
ComponentAttribute - (47:1,27 [6] x:\dir\subdir\Test\TestComponent.cshtml) - Foo - AttributeStructure.DoubleQuotes
|
||||
CSharpExpression - (48:1,28 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
IntermediateToken - (48:1,28 [5] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - Hello
|
||||
CSharpCode - (73:3,12 [38] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
IntermediateToken - (73:3,12 [38] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n MyClass Hello = new MyClass();\n
|
||||
NamespaceDeclaration - - __Blazor.Test.TestComponent
|
||||
ClassDeclaration - - internal static - TypeInference - -
|
||||
ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
Source Location: (73:3,12 [38] x:\dir\subdir\Test\TestComponent.cshtml)
|
||||
|
|
||||
MyClass Hello = new MyClass();
|
||||
|
|
||||
Generated Location: (764:21,12 [38] )
|
||||
|
|
||||
MyClass Hello = new MyClass();
|
||||
|
|
||||
|
||||
Loading…
Reference in New Issue