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

Commit

Permalink
Rely on Razors MalformedDirective identification for @page.
Browse files Browse the repository at this point in the history
  • Loading branch information
NTaylorMullen committed Jul 5, 2017
1 parent b9541be commit 78e50aa
Showing 1 changed file with 5 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,16 @@ static bool TryGetPageDirective(
var documentIRNode = codeDocument.GetDocumentIntermediateNode();
if (PageDirective.TryGetPageDirective(documentIRNode, out var pageDirective))
{
if (pageDirective.DirectiveNode is MalformedDirectiveIntermediateNode malformedNode)
{
logger.MalformedPageDirective(sourceDocument.FilePath, malformedNode.Diagnostics);
}

template = pageDirective.RouteTemplate;
return true;
}

template = null;

var visitor = new Visitor();
visitor.Visit(documentIRNode);
if (visitor.MalformedPageDirective != null)
{
logger.MalformedPageDirective(sourceDocument.FilePath, visitor.MalformedPageDirective.Diagnostics);
return true;
}

return false;
}

Expand All @@ -76,18 +72,5 @@ public void Configure(RazorParserOptionsBuilder options)
options.ParseOnlyLeadingDirectives = true;
}
}

private class Visitor : IntermediateNodeWalker
{
public MalformedDirectiveIntermediateNode MalformedPageDirective { get; private set; }

public override void VisitMalformedDirective(MalformedDirectiveIntermediateNode node)
{
if (node.Descriptor == PageDirective.Directive)
{
MalformedPageDirective = node;
}
}
}
}
}

0 comments on commit 78e50aa

Please sign in to comment.