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

Port to 2.0.1: Fix ModelExpression's in section directive blocks. #1687

Merged
merged 1 commit into from
Sep 15, 2017
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 @@ -35,9 +35,11 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte
}
}

for (; i < directive.Node.Children.Count; i++)
while (i != directive.Node.Children.Count)
{
// Move non-token children over to the section node so we don't have double references to children nodes.
section.Children.Add(directive.Node.Children[i]);
directive.Node.Children.RemoveAt(i);
}

directive.InsertAfter(section);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ public void Basic_Runtime()
RunRuntimeTest(references);
}

[Fact]
public void Sections_Runtime()
{
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
using Microsoft.AspNetCore.Mvc.ViewFeatures;

public class InputTestTagHelper : {typeof(TagHelper).FullName}
{{
public ModelExpression For {{ get; set; }}
}}
");
RunRuntimeTest(references);
}

[Fact]
public void _ViewImports_Runtime()
{
Expand Down Expand Up @@ -344,6 +358,24 @@ public void Basic_DesignTime()
RunDesignTimeTest(references);
}

[Fact]
public void Sections_DesignTime()
{
// This is a problem because we don't yet have multitargeting.
var error = "Delegate 'RenderAsyncDelegate' does not take 1 arguments";

var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
using Microsoft.AspNetCore.Mvc.ViewFeatures;

public class InputTestTagHelper : {typeof(TagHelper).FullName}
{{
public ModelExpression For {{ get; set; }}
}}
");

RunDesignTimeTest(references, new[] { error });
}

[Fact]
public void _ViewImports_DesignTime()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@model DateTime

@addTagHelper "InputTestTagHelper, AppCode"

@{
Layout = "_SectionTestLayout.cshtml";
}

<div>Some body</div>

@section Section1 {
<div>This is in Section 1</div>
<input-test for="Date" />
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// <auto-generated/>
#pragma warning disable 1591
[assembly:global::Microsoft.AspNetCore.Mvc.Razor.Compilation.RazorViewAttribute(null, typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_cshtml))]
namespace AspNetCore
{
#line hidden
using TModel = global::System.Object;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<DateTime>
{
private global::InputTestTagHelper __InputTestTagHelper;
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
DateTime __typeHelper = default(DateTime);
}
))();
((System.Action)(() => {
global::System.Object __typeHelper = "InputTestTagHelper, AppCode";
}
))();
((System.Action)(() => {
global::System.Object Section1 = null;
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
public async override global::System.Threading.Tasks.Task ExecuteAsync()
{
#line 5 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml"

Layout = "_SectionTestLayout.cshtml";

#line default
#line hidden
DefineSection("Section1", async(__razor_section_writer) => {
__InputTestTagHelper = CreateTagHelper<global::InputTestTagHelper>();
#line 13 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml"
__InputTestTagHelper.For = ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Date);

#line default
#line hidden
}
);
}
#pragma warning restore 1998
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<DateTime> Html { get; private set; }
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Document -
CSharpCode -
IntermediateToken - - CSharp - [assembly:global::Microsoft.AspNetCore.Mvc.Razor.Compilation.RazorViewAttribute(null, typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_cshtml))]
NamespaceDeclaration - - AspNetCore
UsingDirective - - TModel = global::System.Object
UsingDirective - (1:0,1 [12] ) - System
UsingDirective - (16:1,1 [32] ) - System.Collections.Generic
UsingDirective - (51:2,1 [17] ) - System.Linq
UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks
UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc
UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering
UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<DateTime> -
DefaultTagHelperRuntime -
FieldDeclaration - - private - global::InputTestTagHelper - __InputTestTagHelper
DesignTimeDirective -
DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>
DirectiveToken - (294:7,71 [4] ) - Html
DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper
DirectiveToken - (363:8,63 [4] ) - Json
DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper
DirectiveToken - (431:9,62 [9] ) - Component
DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper
DirectiveToken - (494:10,52 [3] ) - Url
DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider
DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider
DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor
DirectiveToken - (729:13,14 [87] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper, Microsoft.AspNetCore.Mvc.Razor
DirectiveToken - (832:14,14 [87] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper, Microsoft.AspNetCore.Mvc.Razor
DirectiveToken - (7:0,7 [8] Sections.cshtml) - DateTime
DirectiveToken - (33:2,14 [29] Sections.cshtml) - "InputTestTagHelper, AppCode"
DirectiveToken - (152:10,9 [8] Sections.cshtml) - Section1
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static System.Object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (17:1,0 [2] Sections.cshtml)
IntermediateToken - (17:1,0 [2] Sections.cshtml) - Html - \n
HtmlContent - (62:2,43 [4] Sections.cshtml)
IntermediateToken - (62:2,43 [4] Sections.cshtml) - Html - \n\n
CSharpCode - (68:4,2 [46] Sections.cshtml)
IntermediateToken - (68:4,2 [46] Sections.cshtml) - CSharp - \n Layout = "_SectionTestLayout.cshtml";\n
HtmlContent - (117:7,0 [26] Sections.cshtml)
IntermediateToken - (117:7,0 [2] Sections.cshtml) - Html - \n
IntermediateToken - (119:8,0 [5] Sections.cshtml) - Html - <div>
IntermediateToken - (124:8,5 [9] Sections.cshtml) - Html - Some body
IntermediateToken - (133:8,14 [6] Sections.cshtml) - Html - </div>
IntermediateToken - (139:8,20 [4] Sections.cshtml) - Html - \n\n
Section - - Section1
HtmlContent - (162:10,19 [43] Sections.cshtml)
IntermediateToken - (162:10,19 [6] Sections.cshtml) - Html - \n
IntermediateToken - (168:11,4 [5] Sections.cshtml) - Html - <div>
IntermediateToken - (173:11,9 [20] Sections.cshtml) - Html - This is in Section 1
IntermediateToken - (193:11,29 [6] Sections.cshtml) - Html - </div>
IntermediateToken - (199:11,35 [6] Sections.cshtml) - Html - \n
TagHelper - (205:12,4 [25] Sections.cshtml) - input-test - TagMode.SelfClosing
DefaultTagHelperBody -
DefaultTagHelperCreate - - InputTestTagHelper
DefaultTagHelperProperty - (222:12,21 [4] Sections.cshtml) - for - Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression InputTestTagHelper.For - HtmlAttributeValueStyle.DoubleQuotes
CSharpExpression -
IntermediateToken - - CSharp - ModelExpressionProvider.CreateModelExpression(ViewData, __model =>
IntermediateToken - - CSharp - __model.
IntermediateToken - (222:12,21 [4] Sections.cshtml) - CSharp - Date
IntermediateToken - - CSharp - )
DefaultTagHelperExecute -
HtmlContent - (230:12,29 [2] Sections.cshtml)
IntermediateToken - (230:12,29 [2] Sections.cshtml) - Html - \n
Inject -
Inject -
Inject -
Inject -
Inject -
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Source Location: (7:0,7 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|DateTime|
Generated Location: (923:20,0 [8] )
|DateTime|

Source Location: (33:2,14 [29] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|"InputTestTagHelper, AppCode"|
Generated Location: (1064:24,37 [29] )
|"InputTestTagHelper, AppCode"|

Source Location: (152:10,9 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|Section1|
Generated Location: (1178:28,22 [8] )
|Section1|

Source Location: (68:4,2 [46] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|
Layout = "_SectionTestLayout.cshtml";
|
Generated Location: (1613:40,2 [46] )
|
Layout = "_SectionTestLayout.cshtml";
|

Source Location: (222:12,21 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|Date|
Generated Location: (2038:48,102 [4] )
|Date|

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "dbec91fd88a09c6a2e35b5adedb3f8ab8e3ae486"
// <auto-generated/>
#pragma warning disable 1591
[assembly:global::Microsoft.AspNetCore.Mvc.Razor.Compilation.RazorViewAttribute(null, typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_cshtml))]
namespace AspNetCore
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<DateTime>
{
#line hidden
#pragma warning disable 0169
private string __tagHelperStringValueBuffer;
#pragma warning restore 0169
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext;
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __backed__tagHelperScopeManager = null;
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __tagHelperScopeManager
{
get
{
if (__backed__tagHelperScopeManager == null)
{
__backed__tagHelperScopeManager = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager(StartTagHelperWritingScope, EndTagHelperWritingScope);
}
return __backed__tagHelperScopeManager;
}
}
private global::InputTestTagHelper __InputTestTagHelper;
#pragma warning disable 1998
public async override global::System.Threading.Tasks.Task ExecuteAsync()
{
BeginContext(17, 2, true);
WriteLiteral("\r\n");
EndContext();
BeginContext(64, 2, true);
WriteLiteral("\r\n");
EndContext();
#line 5 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml"

Layout = "_SectionTestLayout.cshtml";

#line default
#line hidden
BeginContext(117, 26, true);
WriteLiteral("\r\n<div>Some body</div>\r\n\r\n");
EndContext();
DefineSection("Section1", async() => {
BeginContext(162, 43, true);
WriteLiteral("\r\n <div>This is in Section 1</div>\r\n ");
EndContext();
BeginContext(205, 25, false);
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.SelfClosing, "test", async() => {
}
);
__InputTestTagHelper = CreateTagHelper<global::InputTestTagHelper>();
__tagHelperExecutionContext.Add(__InputTestTagHelper);
#line 13 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml"
__InputTestTagHelper.For = ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Date);

#line default
#line hidden
__tagHelperExecutionContext.AddTagHelperAttribute("for", __InputTestTagHelper.For, global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
if (!__tagHelperExecutionContext.Output.IsContentModified)
{
await __tagHelperExecutionContext.SetOutputContentAsync();
}
Write(__tagHelperExecutionContext.Output);
__tagHelperExecutionContext = __tagHelperScopeManager.End();
EndContext();
BeginContext(230, 2, true);
WriteLiteral("\r\n");
EndContext();
}
);
}
#pragma warning restore 1998
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<DateTime> Html { get; private set; }
}
}
#pragma warning restore 1591
Loading