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

Commit

Permalink
Finish writer implementation of the remaining IR nodes and added tests
Browse files Browse the repository at this point in the history
- SetTagHelperPropertyIRNode
- ChecksumIRNode
- UsingStatementIRNode
- Preallocated attributes target extension
- HtmlAttributeIRNode and friends
- Design time directive helper target extension
- Removed renderers and rendering conventions
- Regenerated IR baselines
Issue - #846 and #1051
  • Loading branch information
ajaybhargavb committed Apr 21, 2017
1 parent 1696e2a commit 4e2cd0c
Show file tree
Hide file tree
Showing 131 changed files with 3,100 additions and 2,308 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
{
public abstract class BasicWriter
{
public abstract void WriteChecksum(CSharpRenderingContext context, ChecksumIRNode node);

public abstract void WriteUsingStatement(CSharpRenderingContext context, UsingStatementIRNode node);

public abstract void WriteCSharpExpression(CSharpRenderingContext context, CSharpExpressionIRNode node);

public abstract void WriteCSharpStatement(CSharpRenderingContext context, CSharpStatementIRNode node);

public abstract void WriteHtmlContent(CSharpRenderingContext context, HtmlContentIRNode node);

public abstract void WriteHtmlAttribute(CSharpRenderingContext context, HtmlAttributeIRNode node);

public abstract void WriteHtmlAttributeValue(CSharpRenderingContext context, HtmlAttributeValueIRNode node);

public abstract void WriteCSharpAttributeValue(CSharpRenderingContext context, CSharpAttributeValueIRNode node);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
{
public class CSharpRenderingContext
{
private CSharpRenderingConventions _renderingConventions;

internal ICollection<DirectiveDescriptor> Directives { get; set; }

internal Func<string> IdGenerator { get; set; } = () => Guid.NewGuid().ToString("N");
Expand All @@ -20,23 +18,6 @@ public class CSharpRenderingContext

public CSharpCodeWriter Writer { get; set; }

internal CSharpRenderingConventions RenderingConventions
{
get
{
if (_renderingConventions == null)
{
_renderingConventions = new CSharpRenderingConventions(Writer);
}

return _renderingConventions;
}
set
{
_renderingConventions = value;
}
}

internal IList<RazorDiagnostic> Diagnostics { get; } = new List<RazorDiagnostic>();

internal RazorCodeDocument CodeDocument { get; set; }
Expand Down Expand Up @@ -101,6 +82,18 @@ public TagHelperWriterScope Push(TagHelperWriter writer)
return scope;
}

public TagHelperRenderingContextScope Push(TagHelperRenderingContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

var scope = new TagHelperRenderingContextScope(this, TagHelperRenderingContext);
TagHelperRenderingContext = context;
return scope;
}

public struct BasicWriterScope : IDisposable
{
private readonly CSharpRenderingContext _context;
Expand Down Expand Up @@ -154,5 +147,27 @@ public void Dispose()
_context.TagHelperWriter = _writer;
}
}

public struct TagHelperRenderingContextScope : IDisposable
{
private readonly CSharpRenderingContext _context;
private readonly TagHelperRenderingContext _renderingContext;

public TagHelperRenderingContextScope(CSharpRenderingContext context, TagHelperRenderingContext renderingContext)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

_context = context;
_renderingContext = renderingContext;
}

public void Dispose()
{
_context.TagHelperRenderingContext = _renderingContext;
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ internal class DefaultDocumentWriter : DocumentWriter
{
private readonly CSharpRenderingContext _context;
private readonly RuntimeTarget _target;
private readonly PageStructureCSharpRenderer _renderer;

public DefaultDocumentWriter(RuntimeTarget target, CSharpRenderingContext context, PageStructureCSharpRenderer renderer)
public DefaultDocumentWriter(RuntimeTarget target, CSharpRenderingContext context)
{
if (target == null)
{
Expand All @@ -24,14 +23,8 @@ public DefaultDocumentWriter(RuntimeTarget target, CSharpRenderingContext contex
throw new ArgumentNullException(nameof(context));
}

if (renderer == null)
{
throw new ArgumentNullException(nameof(renderer));
}

_target = target;
_context = context;
_renderer = renderer;
}

public override void WriteDocument(DocumentIRNode node)
Expand All @@ -41,7 +34,7 @@ public override void WriteDocument(DocumentIRNode node)
throw new ArgumentNullException(nameof(node));
}

var visitor = new Visitor(_target, _context, _renderer);
var visitor = new Visitor(_target, _context);
_context.RenderChildren = visitor.RenderChildren;
_context.RenderNode = visitor.Visit;

Expand All @@ -56,13 +49,11 @@ private class Visitor : RazorIRNodeVisitor
{
private readonly CSharpRenderingContext _context;
private readonly RuntimeTarget _target;
private readonly PageStructureCSharpRenderer _renderer;

public Visitor(RuntimeTarget target, CSharpRenderingContext context, PageStructureCSharpRenderer renderer)
public Visitor(RuntimeTarget target, CSharpRenderingContext context)
{
_target = target;
_context = context;
_renderer = renderer;
}

private CSharpRenderingContext Context => _context;
Expand All @@ -81,6 +72,16 @@ public override void VisitDocument(DocumentIRNode node)
RenderChildren(node);
}

public override void VisitChecksum(ChecksumIRNode node)
{
Context.BasicWriter.WriteChecksum(Context, node);
}

public override void VisitUsingStatement(UsingStatementIRNode node)
{
Context.BasicWriter.WriteUsingStatement(Context, node);
}

public override void VisitNamespace(NamespaceDeclarationIRNode node)
{
Context.Writer
Expand Down Expand Up @@ -188,6 +189,21 @@ public override void VisitCSharpStatement(CSharpStatementIRNode node)
Context.BasicWriter.WriteCSharpStatement(Context, node);
}

public override void VisitHtmlAttribute(HtmlAttributeIRNode node)
{
Context.BasicWriter.WriteHtmlAttribute(Context, node);
}

public override void VisitHtmlAttributeValue(HtmlAttributeValueIRNode node)
{
Context.BasicWriter.WriteHtmlAttributeValue(Context, node);
}

public override void VisitCSharpAttributeValue(CSharpAttributeValueIRNode node)
{
Context.BasicWriter.WriteCSharpAttributeValue(Context, node);
}

public override void VisitHtml(HtmlContentIRNode node)
{
Context.BasicWriter.WriteHtmlContent(Context, node);
Expand All @@ -200,10 +216,10 @@ public override void VisitDeclareTagHelperFields(DeclareTagHelperFieldsIRNode no

public override void VisitTagHelper(TagHelperIRNode node)
{
var initialRenderingContext = Context.TagHelperRenderingContext;
Context.TagHelperRenderingContext = new TagHelperRenderingContext();
Context.RenderChildren(node);
Context.TagHelperRenderingContext = initialRenderingContext;
using (Context.Push(new TagHelperRenderingContext()))
{
Context.RenderChildren(node);
}
}

public override void VisitInitializeTagHelperStructure(InitializeTagHelperStructureIRNode node)
Expand All @@ -221,16 +237,19 @@ public override void VisitAddTagHelperHtmlAttribute(AddTagHelperHtmlAttributeIRN
Context.TagHelperWriter.WriteAddTagHelperHtmlAttribute(Context, node);
}

public override void VisitSetTagHelperProperty(SetTagHelperPropertyIRNode node)
{
Context.TagHelperWriter.WriteSetTagHelperProperty(Context, node);
}

public override void VisitExecuteTagHelpers(ExecuteTagHelpersIRNode node)
{
Context.TagHelperWriter.WriteExecuteTagHelpers(Context, node);
}

public override void VisitDefault(RazorIRNode node)
{
// This is a temporary bridge to the renderer, which allows us to move functionality piecemeal
// into this class.
_renderer.Visit(node);
Context.RenderChildren(node);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,7 @@ public DefaultRuntimeTarget(RazorParserOptions options, IEnumerable<IRuntimeTarg

public override DocumentWriter CreateWriter(CSharpRenderingContext context)
{
PageStructureCSharpRenderer renderer;
if (_options.DesignTimeMode)
{
renderer = new DesignTimeCSharpRenderer(this, context);
}
else
{
renderer = new RuntimeCSharpRenderer(this, context);
}

return new DefaultDocumentWriter(this, context, renderer);
return new DefaultDocumentWriter(this, context);
}

public override TExtension GetExtension<TExtension>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
{
public class DesignTimeBasicWriter : BasicWriter
{
public override void WriteChecksum(CSharpRenderingContext context, ChecksumIRNode node)
{
// Do nothing
}

public override void WriteUsingStatement(CSharpRenderingContext context, UsingStatementIRNode node)
{
if (node.Source.HasValue)
{
using (context.Writer.BuildLinePragma(node.Source.Value))
{
context.AddLineMappingFor(node);
context.Writer.WriteUsing(node.Content);
}
}
else
{
context.Writer.WriteUsing(node.Content);
}
}

public override void WriteCSharpExpression(CSharpRenderingContext context, CSharpExpressionIRNode node)
{
if (context == null)
Expand Down Expand Up @@ -124,7 +145,17 @@ public override void WriteCSharpStatement(CSharpRenderingContext context, CSharp

public override void WriteHtmlAttribute(CSharpRenderingContext context, HtmlAttributeIRNode node)
{
throw new NotImplementedException();
context.RenderChildren(node);
}

public override void WriteHtmlAttributeValue(CSharpRenderingContext context, HtmlAttributeValueIRNode node)
{
context.RenderChildren(node);
}

public override void WriteCSharpAttributeValue(CSharpRenderingContext context, CSharpAttributeValueIRNode node)
{
context.RenderChildren(node);
}

public override void WriteHtmlContent(CSharpRenderingContext context, HtmlContentIRNode node)
Expand Down
Loading

0 comments on commit 4e2cd0c

Please sign in to comment.