React to aspnet/Razor#996
This commit is contained in:
parent
eb820106e2
commit
38e1e7d14e
|
|
@ -20,13 +20,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class Pass : IRazorIRPass
|
internal class Pass : RazorIRPassBase, IRazorDirectiveClassifierPass
|
||||||
{
|
{
|
||||||
public RazorEngine Engine { get; set; }
|
public override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
|
||||||
|
|
||||||
public int Order => RazorIRPass.DirectiveClassifierOrder;
|
|
||||||
|
|
||||||
public DocumentIRNode Execute(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
|
|
||||||
{
|
{
|
||||||
var visitor = new Visitor();
|
var visitor = new Visitor();
|
||||||
visitor.Visit(irDocument);
|
visitor.Visit(irDocument);
|
||||||
|
|
@ -62,8 +58,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
|
|
||||||
visitor.Class.Children.Add(member);
|
visitor.Class.Children.Add(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
return irDocument;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +83,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
{
|
{
|
||||||
Directives.Add(node);
|
Directives.Add(node);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,14 +56,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class Pass : IRazorIRPass
|
internal class Pass : RazorIRPassBase, IRazorDirectiveClassifierPass
|
||||||
{
|
{
|
||||||
public RazorEngine Engine { get; set; }
|
|
||||||
|
|
||||||
// Runs after the @inherits directive
|
// Runs after the @inherits directive
|
||||||
public int Order => RazorIRPass.DirectiveClassifierOrder + 5;
|
public override int Order => 5;
|
||||||
|
|
||||||
public DocumentIRNode Execute(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
|
public override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
|
||||||
{
|
{
|
||||||
var visitor = new Visitor();
|
var visitor = new Visitor();
|
||||||
var modelType = GetModelType(irDocument, visitor);
|
var modelType = GetModelType(irDocument, visitor);
|
||||||
|
|
@ -82,7 +80,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
}
|
}
|
||||||
|
|
||||||
visitor.Class.BaseType = baseType;
|
visitor.Class.BaseType = baseType;
|
||||||
return irDocument;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,18 +8,12 @@ using Microsoft.AspNetCore.Razor.Evolution.Intermediate;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
{
|
{
|
||||||
public class ModelExpressionPass : IRazorIRPass
|
public class ModelExpressionPass : RazorIRPassBase, IRazorIROptimizationPass
|
||||||
{
|
{
|
||||||
public RazorEngine Engine { get; set; }
|
public override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
|
||||||
|
|
||||||
public int Order => RazorIRPass.LoweringOrder;
|
|
||||||
|
|
||||||
public DocumentIRNode Execute(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
|
|
||||||
{
|
{
|
||||||
var visitor = new Visitor();
|
var visitor = new Visitor();
|
||||||
visitor.Visit(irDocument);
|
visitor.Visit(irDocument);
|
||||||
|
|
||||||
return irDocument;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Visitor : RazorIRNodeWalker
|
private class Visitor : RazorIRNodeWalker
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,13 @@ using Microsoft.AspNetCore.Razor.Evolution.Intermediate;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
{
|
{
|
||||||
public class PagesPropertyInjectionPass : IRazorIRPass
|
public class PagesPropertyInjectionPass : RazorIRPassBase, IRazorIROptimizationPass
|
||||||
{
|
{
|
||||||
public RazorEngine Engine { get; set; }
|
public override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
|
||||||
|
|
||||||
public int Order => RazorIRPass.LoweringOrder;
|
|
||||||
|
|
||||||
public DocumentIRNode Execute(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
|
|
||||||
{
|
{
|
||||||
if (irDocument.DocumentKind != RazorPageDocumentClassifierPass.RazorPageDocumentKind)
|
if (irDocument.DocumentKind != RazorPageDocumentClassifierPass.RazorPageDocumentKind)
|
||||||
{
|
{
|
||||||
return irDocument;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var modelType = ModelDirective.GetModelType(irDocument);
|
var modelType = ModelDirective.GetModelType(irDocument);
|
||||||
|
|
@ -39,8 +35,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
|
|
||||||
@class.Children.Add(vddProperty);
|
@class.Children.Add(vddProperty);
|
||||||
@class.Children.Add(modelProperty);
|
@class.Children.Add(modelProperty);
|
||||||
|
|
||||||
return irDocument;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Visitor : RazorIRNodeWalker
|
private class Visitor : RazorIRNodeWalker
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,9 @@ using Microsoft.AspNetCore.Razor.Evolution.Legacy;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
{
|
{
|
||||||
public class ViewComponentTagHelperPass : IRazorIRPass
|
public class ViewComponentTagHelperPass : RazorIRPassBase, IRazorIROptimizationPass
|
||||||
{
|
{
|
||||||
public RazorEngine Engine { get; set; }
|
public override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
|
||||||
|
|
||||||
public int Order => RazorIRPass.LoweringOrder;
|
|
||||||
|
|
||||||
public DocumentIRNode Execute(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
|
|
||||||
{
|
{
|
||||||
var visitor = new Visitor();
|
var visitor = new Visitor();
|
||||||
visitor.Visit(irDocument);
|
visitor.Visit(irDocument);
|
||||||
|
|
@ -25,7 +21,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
if (visitor.Class == null || visitor.TagHelpers.Count == 0)
|
if (visitor.Class == null || visitor.TagHelpers.Count == 0)
|
||||||
{
|
{
|
||||||
// Nothing to do, bail.
|
// Nothing to do, bail.
|
||||||
return irDocument;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var tagHelper in visitor.TagHelpers)
|
foreach (var tagHelper in visitor.TagHelpers)
|
||||||
|
|
@ -42,8 +38,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
{
|
{
|
||||||
RewriteCreateNode(visitor.Namespace, visitor.Class, createNode);
|
RewriteCreateNode(visitor.Namespace, visitor.Class, createNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return irDocument;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GenerateVCTHClass(ClassDeclarationIRNode @class, TagHelperDescriptor tagHelper)
|
private void GenerateVCTHClass(ClassDeclarationIRNode @class, TagHelperDescriptor tagHelper)
|
||||||
|
|
|
||||||
|
|
@ -197,19 +197,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
// Notice we're not registering the InjectDirective.Pass here so we can run it on demand.
|
// Notice we're not registering the InjectDirective.Pass here so we can run it on demand.
|
||||||
b.AddDirective(InjectDirective.Directive);
|
b.AddDirective(InjectDirective.Directive);
|
||||||
b.AddDirective(ModelDirective.Directive);
|
b.AddDirective(ModelDirective.Directive);
|
||||||
|
|
||||||
// HACK - Remove the DefaultDirectiveIRPass so it can't remove our directives.
|
|
||||||
IRazorEngineFeature badFeature = null;
|
|
||||||
foreach (var feature in b.Features)
|
|
||||||
{
|
|
||||||
if (string.Equals("DefaultDirectiveIRPass", feature.GetType().Name, StringComparison.Ordinal))
|
|
||||||
{
|
|
||||||
badFeature = feature;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
b.Features.Remove(badFeature);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -220,7 +207,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
var phase = engine.Phases[i];
|
var phase = engine.Phases[i];
|
||||||
phase.Execute(codeDocument);
|
phase.Execute(codeDocument);
|
||||||
|
|
||||||
if (phase is IRazorIRPhase)
|
if (phase is IRazorDocumentClassifierPhase)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -180,19 +180,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
{
|
{
|
||||||
// Notice we're not registering the ModelDirective.Pass here so we can run it on demand.
|
// Notice we're not registering the ModelDirective.Pass here so we can run it on demand.
|
||||||
b.AddDirective(ModelDirective.Directive);
|
b.AddDirective(ModelDirective.Directive);
|
||||||
|
|
||||||
// HACK - Remove the DefaultDirectiveIRPass so it can't remove our directives.
|
|
||||||
IRazorEngineFeature badFeature = null;
|
|
||||||
foreach (var feature in b.Features)
|
|
||||||
{
|
|
||||||
if (string.Equals("DefaultDirectiveIRPass", feature.GetType().Name, StringComparison.Ordinal))
|
|
||||||
{
|
|
||||||
badFeature = feature;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
b.Features.Remove(badFeature);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -203,7 +190,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
var phase = engine.Phases[i];
|
var phase = engine.Phases[i];
|
||||||
phase.Execute(codeDocument);
|
phase.Execute(codeDocument);
|
||||||
|
|
||||||
if (phase is IRazorIRPhase)
|
if (phase is IRazorDocumentClassifierPhase)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
var phase = engine.Phases[i];
|
var phase = engine.Phases[i];
|
||||||
phase.Execute(codeDocument);
|
phase.Execute(codeDocument);
|
||||||
|
|
||||||
if (phase is IRazorIRPhase)
|
if (phase is IRazorDirectiveClassifierPhase)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -207,11 +207,15 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
|
|
||||||
private static DocumentIRNode CreateIRDocument(RazorEngine engine, RazorCodeDocument codeDocument)
|
private static DocumentIRNode CreateIRDocument(RazorEngine engine, RazorCodeDocument codeDocument)
|
||||||
{
|
{
|
||||||
var phases = engine.Phases.TakeWhile(p => !(p is IRazorIRPhase));
|
for (var i = 0; i < engine.Phases.Count; i++)
|
||||||
|
|
||||||
foreach (var phase in phases)
|
|
||||||
{
|
{
|
||||||
|
var phase = engine.Phases[i];
|
||||||
phase.Execute(codeDocument);
|
phase.Execute(codeDocument);
|
||||||
|
|
||||||
|
if (phase is IRazorIRLoweringPhase)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return codeDocument.GetIRDocument();
|
return codeDocument.GetIRDocument();
|
||||||
|
|
|
||||||
|
|
@ -233,11 +233,15 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
|
|
||||||
private static DocumentIRNode CreateIRDocument(RazorEngine engine, RazorCodeDocument codeDocument)
|
private static DocumentIRNode CreateIRDocument(RazorEngine engine, RazorCodeDocument codeDocument)
|
||||||
{
|
{
|
||||||
var phases = engine.Phases.TakeWhile(p => !(p is IRazorIRPhase));
|
for (var i = 0; i < engine.Phases.Count; i++)
|
||||||
|
|
||||||
foreach (var phase in phases)
|
|
||||||
{
|
{
|
||||||
|
var phase = engine.Phases[i];
|
||||||
phase.Execute(codeDocument);
|
phase.Execute(codeDocument);
|
||||||
|
|
||||||
|
if (phase is IRazorIRLoweringPhase)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return codeDocument.GetIRDocument();
|
return codeDocument.GetIRDocument();
|
||||||
|
|
|
||||||
|
|
@ -187,12 +187,12 @@ public class __Generated__TagCloudViewComponentTagHelper : Microsoft.AspNetCore.
|
||||||
// Assert
|
// Assert
|
||||||
var tagHelper = FindTagHelperNode(irDocument);
|
var tagHelper = FindTagHelperNode(irDocument);
|
||||||
Assert.Equal(expectedVCTHName, Assert.IsType<CreateTagHelperIRNode>(tagHelper.Children[1]).TagHelperTypeName);
|
Assert.Equal(expectedVCTHName, Assert.IsType<CreateTagHelperIRNode>(tagHelper.Children[1]).TagHelperTypeName);
|
||||||
Assert.IsType<AddPreallocatedTagHelperHtmlAttributeIRNode>(tagHelper.Children[2]);
|
Assert.IsType<AddTagHelperHtmlAttributeIRNode>(tagHelper.Children[2]);
|
||||||
|
|
||||||
var @class = FindClassNode(irDocument);
|
var @class = FindClassNode(irDocument);
|
||||||
Assert.Equal(4, @class.Children.Count);
|
Assert.Equal(3, @class.Children.Count);
|
||||||
|
|
||||||
var vcthClass = Assert.IsType<CSharpStatementIRNode>(@class.Children[3]);
|
var vcthClass = Assert.IsType<CSharpStatementIRNode>(@class.Children[2]);
|
||||||
Assert.Equal(@"[Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute(""tagcloud"")]
|
Assert.Equal(@"[Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute(""tagcloud"")]
|
||||||
public class __Generated__TagCloudViewComponentTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
|
public class __Generated__TagCloudViewComponentTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
|
||||||
{
|
{
|
||||||
|
|
@ -339,7 +339,7 @@ public class __Generated__TagCloudViewComponentTagHelper : Microsoft.AspNetCore.
|
||||||
var phase = engine.Phases[i];
|
var phase = engine.Phases[i];
|
||||||
phase.Execute(codeDocument);
|
phase.Execute(codeDocument);
|
||||||
|
|
||||||
if (phase is IRazorIRPhase)
|
if (phase is IRazorDirectiveClassifierPhase)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue