Skip to content

Commit 3c463c8

Browse files
Use FindDescendentReferences in DirectiveRemovalOptimizationPass
There's no need to use a custom visitor when there's a perfectly good helper that does the job.
1 parent b73e3f4 commit 3c463c8

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#nullable disable
5-
6-
using System.Collections.Generic;
74
using Microsoft.AspNetCore.Razor.Language.Intermediate;
85

96
namespace Microsoft.AspNetCore.Razor.Language;
@@ -14,25 +11,12 @@ internal class DirectiveRemovalOptimizationPass : IntermediateNodePassBase, IRaz
1411

1512
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
1613
{
17-
var visitor = new Visitor();
18-
visitor.VisitDocument(documentNode);
19-
20-
foreach (var nodeReference in visitor.DirectiveNodes)
14+
foreach (var nodeReference in documentNode.FindDescendantReferences<DirectiveIntermediateNode>())
2115
{
2216
// Lift the diagnostics in the directive node up to the document node.
2317
documentNode.AddDiagnosticsFromNode(nodeReference.Node);
2418

2519
nodeReference.Remove();
2620
}
2721
}
28-
29-
private class Visitor : IntermediateNodeWalker
30-
{
31-
public IList<IntermediateNodeReference> DirectiveNodes { get; } = new List<IntermediateNodeReference>();
32-
33-
public override void VisitDirective(DirectiveIntermediateNode node)
34-
{
35-
DirectiveNodes.Add(new IntermediateNodeReference(Parent, node));
36-
}
37-
}
3822
}

0 commit comments

Comments
 (0)