Remove explicit scope managment
This commit is contained in:
parent
7408bcd025
commit
647ce7515d
|
|
@ -10,8 +10,11 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
||||||
public abstract class CodeRenderingContext
|
public abstract class CodeRenderingContext
|
||||||
{
|
{
|
||||||
internal static readonly object NewLineString = "NewLineString";
|
internal static readonly object NewLineString = "NewLineString";
|
||||||
|
|
||||||
internal static readonly object SuppressUniqueIds = "SuppressUniqueIds";
|
internal static readonly object SuppressUniqueIds = "SuppressUniqueIds";
|
||||||
|
|
||||||
|
public abstract IEnumerable<IntermediateNode> Ancestors { get; }
|
||||||
|
|
||||||
public abstract CodeWriter CodeWriter { get; }
|
public abstract CodeWriter CodeWriter { get; }
|
||||||
|
|
||||||
public abstract RazorDiagnosticCollection Diagnostics { get; }
|
public abstract RazorDiagnosticCollection Diagnostics { get; }
|
||||||
|
|
@ -19,8 +22,6 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
||||||
public abstract string DocumentKind { get; }
|
public abstract string DocumentKind { get; }
|
||||||
|
|
||||||
public abstract ItemCollection Items { get; }
|
public abstract ItemCollection Items { get; }
|
||||||
|
|
||||||
public abstract IEnumerable<IntermediateNode> Ancestors { get; }
|
|
||||||
|
|
||||||
public abstract IntermediateNodeWriter NodeWriter { get; }
|
public abstract IntermediateNodeWriter NodeWriter { get; }
|
||||||
|
|
||||||
|
|
@ -30,36 +31,14 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
||||||
|
|
||||||
public abstract RazorSourceDocument SourceDocument { get; }
|
public abstract RazorSourceDocument SourceDocument { get; }
|
||||||
|
|
||||||
public abstract Scope CreateScope();
|
public abstract void AddLineMappingFor(IntermediateNode node);
|
||||||
|
|
||||||
public abstract Scope CreateScope(IntermediateNodeWriter writer);
|
|
||||||
|
|
||||||
public abstract void EndScope();
|
|
||||||
|
|
||||||
public abstract void RenderNode(IntermediateNode node);
|
public abstract void RenderNode(IntermediateNode node);
|
||||||
|
|
||||||
|
public abstract void RenderNode(IntermediateNode node, IntermediateNodeWriter writer);
|
||||||
|
|
||||||
public abstract void RenderChildren(IntermediateNode node);
|
public abstract void RenderChildren(IntermediateNode node);
|
||||||
|
|
||||||
public abstract void AddLineMappingFor(IntermediateNode node);
|
public abstract void RenderChildren(IntermediateNode node, IntermediateNodeWriter writer);
|
||||||
|
|
||||||
public struct Scope : IDisposable
|
|
||||||
{
|
|
||||||
private readonly CodeRenderingContext _context;
|
|
||||||
|
|
||||||
public Scope(CodeRenderingContext context)
|
|
||||||
{
|
|
||||||
if (context == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
_context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
_context.EndScope();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,28 +130,6 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
||||||
LineMappings.Add(lineMapping);
|
LineMappings.Add(lineMapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Scope CreateScope()
|
|
||||||
{
|
|
||||||
CreateScope(Current.Writer);
|
|
||||||
return new Scope(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Scope CreateScope(IntermediateNodeWriter writer)
|
|
||||||
{
|
|
||||||
if (writer == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(writer));
|
|
||||||
}
|
|
||||||
|
|
||||||
_scopes.Add(new ScopeInternal(writer));
|
|
||||||
return new Scope(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void EndScope()
|
|
||||||
{
|
|
||||||
_scopes.RemoveAt(_scopes.Count - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void RenderChildren(IntermediateNode node)
|
public override void RenderChildren(IntermediateNode node)
|
||||||
{
|
{
|
||||||
if (node == null)
|
if (node == null)
|
||||||
|
|
@ -169,6 +147,30 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
||||||
_ancestors.Pop();
|
_ancestors.Pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void RenderChildren(IntermediateNode node, IntermediateNodeWriter writer)
|
||||||
|
{
|
||||||
|
if (node == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(node));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (writer == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(writer));
|
||||||
|
}
|
||||||
|
|
||||||
|
_scopes.Add(new ScopeInternal(writer));
|
||||||
|
_ancestors.Push(node);
|
||||||
|
|
||||||
|
for (var i = 0; i < node.Children.Count; i++)
|
||||||
|
{
|
||||||
|
Visitor.Visit(node.Children[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
_ancestors.Pop();
|
||||||
|
_scopes.RemoveAt(_scopes.Count - 1);
|
||||||
|
}
|
||||||
|
|
||||||
public override void RenderNode(IntermediateNode node)
|
public override void RenderNode(IntermediateNode node)
|
||||||
{
|
{
|
||||||
if (node == null)
|
if (node == null)
|
||||||
|
|
@ -179,6 +181,25 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
||||||
Visitor.Visit(node);
|
Visitor.Visit(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void RenderNode(IntermediateNode node, IntermediateNodeWriter writer)
|
||||||
|
{
|
||||||
|
if (node == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(node));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (writer == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(writer));
|
||||||
|
}
|
||||||
|
|
||||||
|
_scopes.Add(new ScopeInternal(writer));
|
||||||
|
|
||||||
|
Visitor.Visit(node);
|
||||||
|
|
||||||
|
_scopes.RemoveAt(_scopes.Count - 1);
|
||||||
|
}
|
||||||
|
|
||||||
private struct ScopeInternal
|
private struct ScopeInternal
|
||||||
{
|
{
|
||||||
public ScopeInternal(IntermediateNodeWriter writer)
|
public ScopeInternal(IntermediateNodeWriter writer)
|
||||||
|
|
|
||||||
|
|
@ -113,13 +113,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
|
||||||
.WriteStringLiteral(uniqueId)
|
.WriteStringLiteral(uniqueId)
|
||||||
.WriteParameterSeparator();
|
.WriteParameterSeparator();
|
||||||
|
|
||||||
// We remove and redirect writers so TagHelper authors can retrieve content.
|
using (context.CodeWriter.BuildAsyncLambda())
|
||||||
using (context.CreateScope(new RuntimeNodeWriter()))
|
|
||||||
{
|
{
|
||||||
using (context.CodeWriter.BuildAsyncLambda())
|
// We remove and redirect writers so TagHelper authors can retrieve content.
|
||||||
{
|
context.RenderChildren(node, new RuntimeNodeWriter());
|
||||||
context.RenderChildren(node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.CodeWriter.WriteEndMethodInvocation();
|
context.CodeWriter.WriteEndMethodInvocation();
|
||||||
|
|
@ -239,10 +236,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
|
||||||
.Write(attributeValueStyleParameter)
|
.Write(attributeValueStyleParameter)
|
||||||
.WriteEndMethodInvocation();
|
.WriteEndMethodInvocation();
|
||||||
|
|
||||||
using (context.CreateScope(new TagHelperHtmlAttributeRuntimeNodeWriter()))
|
context.RenderChildren(node, new TagHelperHtmlAttributeRuntimeNodeWriter());
|
||||||
{
|
|
||||||
context.RenderChildren(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
context.CodeWriter
|
context.CodeWriter
|
||||||
.WriteMethodInvocation(
|
.WriteMethodInvocation(
|
||||||
|
|
@ -261,10 +255,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
|
||||||
// We're building a writing scope around the provided chunks which captures everything written from the
|
// We're building a writing scope around the provided chunks which captures everything written from the
|
||||||
// page. Therefore, we do not want to write to any other buffer since we're using the pages buffer to
|
// page. Therefore, we do not want to write to any other buffer since we're using the pages buffer to
|
||||||
// ensure we capture all content that's written, directly or indirectly.
|
// ensure we capture all content that's written, directly or indirectly.
|
||||||
using (context.CreateScope(new RuntimeNodeWriter()))
|
context.RenderChildren(node, new RuntimeNodeWriter());
|
||||||
{
|
|
||||||
context.RenderChildren(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
context.CodeWriter
|
context.CodeWriter
|
||||||
.WriteStartAssignment(StringValueBufferVariableName)
|
.WriteStartAssignment(StringValueBufferVariableName)
|
||||||
|
|
@ -367,10 +358,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
|
||||||
{
|
{
|
||||||
context.CodeWriter.WriteMethodInvocation(BeginWriteTagHelperAttributeMethodName);
|
context.CodeWriter.WriteMethodInvocation(BeginWriteTagHelperAttributeMethodName);
|
||||||
|
|
||||||
using (context.CreateScope(new LiteralRuntimeNodeWriter()))
|
context.RenderChildren(node, new LiteralRuntimeNodeWriter());
|
||||||
{
|
|
||||||
context.RenderChildren(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
context.CodeWriter
|
context.CodeWriter
|
||||||
.WriteStartAssignment(StringValueBufferVariableName)
|
.WriteStartAssignment(StringValueBufferVariableName)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue