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

Fix ModelExpression's in section directive blocks. #1615

Merged
merged 1 commit into from
Aug 16, 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 @@ -109,7 +109,14 @@ public void Basic_Runtime()
[Fact]
public void Sections_Runtime()
{
var references = CreateCompilationReferences(CurrentMvcShim);
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
using Microsoft.AspNetCore.Mvc.ViewFeatures;

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

Expand Down Expand Up @@ -351,7 +358,14 @@ public void Basic_DesignTime()
[Fact]
public void Sections_DesignTime()
{
var references = CreateCompilationReferences(CurrentMvcShim);
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
using Microsoft.AspNetCore.Mvc.ViewFeatures;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +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
Expand Up @@ -11,11 +11,20 @@ namespace AspNetCore
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<dynamic>
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;
}
))();
Expand All @@ -27,13 +36,19 @@ private void __RazorDirectiveTokenHelpers__() {
#pragma warning disable 1998
public async override global::System.Threading.Tasks.Task ExecuteAsync()
{
#line 1 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml"
#line 5 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml"

Layout = "_SectionTestLayout.cshtml";

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

#line default
#line hidden
}
);
}
Expand All @@ -47,7 +62,7 @@ private void __RazorDirectiveTokenHelpers__() {
[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<dynamic> Html { get; private set; }
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
Expand Up @@ -8,7 +8,9 @@ Document -
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<dynamic> -
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
Expand All @@ -23,29 +25,47 @@ Document -
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 - (86:6,9 [8] Sections.cshtml) - Section1
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
CSharpCode - (2:0,2 [46] Sections.cshtml)
IntermediateToken - (2:0,2 [46] Sections.cshtml) - CSharp - \n Layout = "_SectionTestLayout.cshtml";\n
HtmlContent - (51:3,0 [26] Sections.cshtml)
IntermediateToken - (51:3,0 [2] Sections.cshtml) - Html - \n
IntermediateToken - (53:4,0 [5] Sections.cshtml) - Html - <div>
IntermediateToken - (58:4,5 [9] Sections.cshtml) - Html - Some body
IntermediateToken - (67:4,14 [6] Sections.cshtml) - Html - </div>
IntermediateToken - (73:4,20 [4] Sections.cshtml) - Html - \n\n
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 - (96:6,19 [39] Sections.cshtml)
IntermediateToken - (96:6,19 [6] Sections.cshtml) - Html - \n
IntermediateToken - (102:7,4 [5] Sections.cshtml) - Html - <div>
IntermediateToken - (107:7,9 [20] Sections.cshtml) - Html - This is in Section 1
IntermediateToken - (127:7,29 [6] Sections.cshtml) - Html - </div>
IntermediateToken - (133:7,35 [2] Sections.cshtml) - Html - \n
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 -
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
Source Location: (86:6,9 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
Source Location: (7:0,7 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|DateTime|
Generated Location: (742:19,0 [8] )
|DateTime|

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

Source Location: (152:10,9 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|Section1|
Generated Location: (697:18,22 [8] )
Generated Location: (997:27,22 [8] )
|Section1|

Source Location: (2:0,2 [46] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
Source Location: (68:4,2 [46] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|
Layout = "_SectionTestLayout.cshtml";
|
Generated Location: (1132:30,2 [46] )
Generated Location: (1432:39,2 [46] )
|
Layout = "_SectionTestLayout.cshtml";
|

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "c7635d54fa83ccf10a29be2f0a7b56d1703398a7"
#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))]
Expand All @@ -12,23 +12,71 @@ namespace AspNetCore
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<dynamic>
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()
{
#line 1 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml"
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(51, 26, true);
BeginContext(117, 26, true);
WriteLiteral("\r\n<div>Some body</div>\r\n\r\n");
EndContext();
DefineSection("Section1", async() => {
BeginContext(96, 39, true);
WriteLiteral("\r\n <div>This is in Section 1</div>\r\n");
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();
}
);
Expand All @@ -43,7 +91,7 @@ public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_c
[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<dynamic> Html { get; private set; }
public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<DateTime> Html { get; private set; }
}
}
#pragma warning restore 1591
Loading