Remove pranav's hack

This is part 1 of the right fix for the directive getting removed. This
pass has the wrong order, an it should be running sooner before the
directive is processed by the default processor.
This commit is contained in:
Ryan Nowak 2017-02-10 11:55:50 -08:00
parent af5648c1f7
commit 2cdd84f437
3 changed files with 28 additions and 11 deletions

View File

@ -42,7 +42,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
var tokens = directive.Tokens.ToArray();
if (tokens.Length >= 1)
{
document.Parent = directive;
return tokens[0].Content;
}
}
@ -62,7 +61,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
public RazorEngine Engine { get; set; }
// Runs after the @inherits directive
public int Order => RazorIRPass.DefaultDirectiveClassifierOrder + 5;
public int Order => RazorIRPass.DirectiveClassifierOrder + 5;
public DocumentIRNode Execute(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
{
@ -95,15 +94,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
public IList<DirectiveIRNode> ModelDirectives { get; } = new List<DirectiveIRNode>();
public override void VisitDocument(DocumentIRNode node)
{
if (node.Parent != null)
{
ModelDirectives.Add((DirectiveIRNode)node.Parent);
}
base.VisitDocument(node);
}
public override void VisitClass(ClassDeclarationIRNode node)
{
if (Class == null)

View File

@ -197,6 +197,19 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
// Notice we're not registering the InjectDirective.Pass here so we can run it on demand.
b.AddDirective(InjectDirective.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);
});
}

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Text;
using Microsoft.AspNetCore.Razor.Evolution;
@ -179,6 +180,19 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
{
// Notice we're not registering the ModelDirective.Pass here so we can run it on demand.
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);
});
}