Add the ability for `TagHelper`s to exist inside templates.

- Previously doing `@<mytaghelper />` was invalid due to how we constructed templates lambdas.

#489
This commit is contained in:
N. Taylor Mullen 2015-08-21 16:51:47 -07:00
parent dbcc5e240a
commit d0688a7e00
9 changed files with 159 additions and 21 deletions

View File

@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors
var currentTargetWriterName = Context.TargetWriterName;
Context.TargetWriterName = TemplateWriterName;
using (Writer.BuildLambda(endLine: false, parameterNames: TemplateWriterName))
using (Writer.BuildAsyncLambda(endLine: false, parameterNames: TemplateWriterName))
{
Accept(chunk.Children);
}

View File

@ -297,13 +297,59 @@ namespace Microsoft.AspNet.Razor.Test.Generator
tabTest: TabTest.NoTabs,
expectedDesignTimePragmas: new List<LineMapping>()
{
BuildLineMapping(20, 1, 13, 526, 22, 12, 36),
BuildLineMapping(74, 2, 22, 648, 29, 22, 1),
BuildLineMapping(79, 2, 27, 739, 34, 27, 15),
BuildLineMapping(113, 7, 2, 824, 41, 6, 12),
BuildLineMapping(129, 8, 1, 905, 46, 6, 4),
BuildLineMapping(142, 8, 1005, 48, 14, 3),
BuildLineMapping(204, 13, 5, 1192, 60, 6, 3)
BuildLineMapping(
documentAbsoluteIndex: 20,
documentLineIndex: 1,
documentCharacterOffsetIndex: 13,
generatedAbsoluteIndex: 526,
generatedLineIndex: 22,
generatedCharacterOffsetIndex: 12,
contentLength: 36),
BuildLineMapping(
documentAbsoluteIndex: 74,
documentLineIndex: 2,
generatedAbsoluteIndex: 648,
generatedLineIndex: 29,
characterOffsetIndex: 22,
contentLength: 1),
BuildLineMapping(
documentAbsoluteIndex: 79,
documentLineIndex: 2,
generatedAbsoluteIndex: 739,
generatedLineIndex: 34,
characterOffsetIndex: 27,
contentLength: 15),
BuildLineMapping(
documentAbsoluteIndex: 113,
documentLineIndex: 7,
documentCharacterOffsetIndex: 2,
generatedAbsoluteIndex: 824,
generatedLineIndex: 41,
generatedCharacterOffsetIndex: 6,
contentLength: 12),
BuildLineMapping(
documentAbsoluteIndex: 129,
documentLineIndex: 8,
documentCharacterOffsetIndex: 1,
generatedAbsoluteIndex: 905,
generatedLineIndex: 46,
generatedCharacterOffsetIndex: 6,
contentLength: 4),
BuildLineMapping(
documentAbsoluteIndex: 142,
documentLineIndex: 8,
generatedAbsoluteIndex: 1010,
generatedLineIndex: 48,
characterOffsetIndex: 14,
contentLength: 3),
BuildLineMapping(
documentAbsoluteIndex: 204,
documentLineIndex: 13,
documentCharacterOffsetIndex: 5,
generatedAbsoluteIndex: 1197,
generatedLineIndex: 60,
generatedCharacterOffsetIndex: 6,
contentLength: 3),
});
}

View File

@ -812,10 +812,32 @@ namespace Microsoft.AspNet.Razor.Test.Generator
generatedCharacterOffsetIndex: 49,
contentLength: 1),
BuildLineMapping(
documentAbsoluteIndex: 1309,
documentLineIndex: 34,
generatedAbsoluteIndex: 5492,
documentAbsoluteIndex: 1306,
documentLineIndex: 33,
generatedAbsoluteIndex: 5501,
generatedLineIndex: 204,
characterOffsetIndex: 9,
contentLength: 11),
BuildLineMapping(
documentAbsoluteIndex: 1361,
documentLineIndex: 33,
documentCharacterOffsetIndex: 64,
generatedAbsoluteIndex: 5790,
generatedLineIndex: 208,
generatedCharacterOffsetIndex: 63,
contentLength: 7),
BuildLineMapping(
documentAbsoluteIndex: 1326,
documentLineIndex: 33,
generatedAbsoluteIndex: 5948,
generatedLineIndex: 214,
characterOffsetIndex: 29,
contentLength: 3),
BuildLineMapping(
documentAbsoluteIndex: 1390,
documentLineIndex: 35,
generatedAbsoluteIndex: 6063,
generatedLineIndex: 225,
characterOffsetIndex: 0,
contentLength: 1),
}

View File

@ -201,7 +201,28 @@ __PTagHelper.Age = ("My age is this long.".Length);
#line default
#line hidden
#line 35 "ComplexTagHelpers.cshtml"
#line 34 "ComplexTagHelpers.cshtml"
__o = someMethod(item => new Template(async(__razor_template_writer) => {
__InputTagHelper = CreateTagHelper<InputTagHelper>();
__InputTagHelper2 = CreateTagHelper<InputTagHelper2>();
#line 34 "ComplexTagHelpers.cshtml"
__InputTagHelper2.Checked = checked;
#line default
#line hidden
__PTagHelper = CreateTagHelper<PTagHelper>();
#line 34 "ComplexTagHelpers.cshtml"
__PTagHelper.Age = 123;
#line default
#line hidden
}
)
);
#line default
#line hidden
#line 36 "ComplexTagHelpers.cshtml"
}
#line default

View File

@ -1,4 +1,4 @@
#pragma checksum "ComplexTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "29efbebdd0277d2835528479690b48268c1dc03b"
#pragma checksum "ComplexTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "7e06587198159a7cdea48c42e64a766a79a12cf7"
namespace TestOutput
{
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
@ -437,10 +437,58 @@ __PTagHelper.Age = ("My age is this long.".Length);
await WriteTagHelperAsync(__tagHelperExecutionContext);
Instrumentation.EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.End();
Instrumentation.BeginContext(1295, 14, true);
Instrumentation.BeginContext(1295, 10, true);
WriteLiteral("\r\n ");
Instrumentation.EndContext();
Instrumentation.BeginContext(1306, 11, false);
#line 34 "ComplexTagHelpers.cshtml"
Write(someMethod(item => new Template(async(__razor_template_writer) => {
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", TagMode.StartTagAndEndTag, "test", async() => {
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", TagMode.SelfClosing, "test", async() => {
}
, StartTagHelperWritingScope, EndTagHelperWritingScope);
__InputTagHelper = CreateTagHelper<InputTagHelper>();
__tagHelperExecutionContext.Add(__InputTagHelper);
__InputTagHelper2 = CreateTagHelper<InputTagHelper2>();
__tagHelperExecutionContext.Add(__InputTagHelper2);
#line 34 "ComplexTagHelpers.cshtml"
__InputTagHelper2.Checked = checked;
#line default
#line hidden
__tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked);
__tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
Instrumentation.BeginContext(1345, 26, false);
await WriteTagHelperAsync(__tagHelperExecutionContext);
Instrumentation.EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.End();
}
, StartTagHelperWritingScope, EndTagHelperWritingScope);
__PTagHelper = CreateTagHelper<PTagHelper>();
__tagHelperExecutionContext.Add(__PTagHelper);
#line 34 "ComplexTagHelpers.cshtml"
__PTagHelper.Age = 123;
#line default
#line hidden
__tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age);
__tagHelperExecutionContext.AddHtmlAttribute("class", Html.Raw("hello"));
__tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
Instrumentation.BeginContext(1318, 57, false);
await WriteTagHelperToAsync(__razor_template_writer, __tagHelperExecutionContext);
Instrumentation.EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.End();
}
)
));
#line default
#line hidden
Instrumentation.EndContext();
Instrumentation.BeginContext(1376, 14, true);
WriteLiteral("\r\n </div>\r\n");
Instrumentation.EndContext();
#line 35 "ComplexTagHelpers.cshtml"
#line 36 "ComplexTagHelpers.cshtml"
}
#line default

View File

@ -44,7 +44,7 @@ __o = Foo(Bar.Baz);
#line default
#line hidden
#line 9 "DesignTime.cshtml"
__o = Foo(item => new Template((__razor_template_writer) => {
__o = Foo(item => new Template(async(__razor_template_writer) => {
#line 9 "DesignTime.cshtml"
__o = baz;

View File

@ -22,7 +22,7 @@ namespace TestOutput
#line default
#line hidden
item => new Template((__razor_template_writer) => {
item => new Template(async(__razor_template_writer) => {
Instrumentation.BeginContext(35, 10, true);
WriteLiteralTo(__razor_template_writer, "<p>Bar</p>");
Instrumentation.EndContext();

View File

@ -36,7 +36,7 @@ namespace TestOutput
#line default
#line hidden
item => new Template((__razor_template_writer) => {
item => new Template(async(__razor_template_writer) => {
Instrumentation.BeginContext(325, 11, true);
WriteLiteralTo(__razor_template_writer, "This works ");
Instrumentation.EndContext();
@ -77,7 +77,7 @@ Write(foo(""));
Instrumentation.EndContext();
Instrumentation.BeginContext(379, 11, false);
#line 17 "Templates.cshtml"
Write(Repeat(10, item => new Template((__razor_template_writer) => {
Write(Repeat(10, item => new Template(async(__razor_template_writer) => {
Instrumentation.BeginContext(391, 10, true);
WriteLiteralTo(__razor_template_writer, "<li>Item #");
Instrumentation.EndContext();
@ -104,7 +104,7 @@ WriteTo(__razor_template_writer, item);
Instrumentation.BeginContext(430, 16, false);
#line 21 "Templates.cshtml"
Write(Repeat(10,
item => new Template((__razor_template_writer) => {
item => new Template(async(__razor_template_writer) => {
Instrumentation.BeginContext(448, 14, true);
WriteLiteralTo(__razor_template_writer, " This is line#");
Instrumentation.EndContext();
@ -130,7 +130,7 @@ WriteTo(__razor_template_writer, item);
Instrumentation.EndContext();
Instrumentation.BeginContext(506, 11, false);
#line 27 "Templates.cshtml"
Write(Repeat(10, item => new Template((__razor_template_writer) => {
Write(Repeat(10, item => new Template(async(__razor_template_writer) => {
Instrumentation.BeginContext(518, 20, true);
WriteLiteralTo(__razor_template_writer, "<li>\r\n Item #");
Instrumentation.EndContext();

View File

@ -31,5 +31,6 @@
<p age="@("My age is this long.".Length)">
<input checked=" @( DateTimeOffset.Now.Year ) > 2014 " />
</p>
@someMethod(@<p age="123" class="hello"><input checked=@checked /></p>)
</div>
}