aspnetcore/src/Microsoft.AspNetCore.Razor..../DirectiveRemovalIROptimizat...

35 lines
1.1 KiB
C#

// 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.Collections.Generic;
using Microsoft.AspNetCore.Razor.Evolution.Intermediate;
namespace Microsoft.AspNetCore.Razor.Evolution
{
internal class DirectiveRemovalIROptimizationPass : RazorIRPassBase, IRazorIROptimizationPass
{
public override int Order => RazorIRPass.DefaultFeatureOrder + 50;
public override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
{
var visitor = new Visitor();
visitor.VisitDocument(irDocument);
foreach (var node in visitor.DirectiveNodes)
{
node.Parent.Children.Remove(node);
}
}
private class Visitor : RazorIRNodeWalker
{
public IList<DirectiveIRNode> DirectiveNodes { get; } = new List<DirectiveIRNode>();
public override void VisitDirective(DirectiveIRNode node)
{
DirectiveNodes.Add(node);
}
}
}
}