Handle multiple nested sections correctly (dotnet/aspnetcore-tooling#196)
\n\nCommit migrated from 26e8d86b21
This commit is contained in:
parent
57c10c0321
commit
73ca91f603
|
|
@ -65,15 +65,23 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
public override SyntaxNode VisitRazorDirective(RazorDirectiveSyntax node)
|
||||
{
|
||||
if (_nestedLevel > 0)
|
||||
if (node.DirectiveDescriptor?.Directive != SectionDirective.Directive.Directive)
|
||||
{
|
||||
// We only want to track the nesting of section directives.
|
||||
return base.VisitRazorDirective(node);
|
||||
}
|
||||
|
||||
_nestedLevel++;
|
||||
var result = (RazorDirectiveSyntax)base.VisitRazorDirective(node);
|
||||
|
||||
if (_nestedLevel > 1)
|
||||
{
|
||||
var directiveStart = node.Transition.GetSourceLocation(_syntaxTree.Source);
|
||||
var errorLength = /* @ */ 1 + SectionDirective.Directive.Directive.Length;
|
||||
var error = RazorDiagnosticFactory.CreateParsing_SectionsCannotBeNested(new SourceSpan(directiveStart, errorLength));
|
||||
node = node.AppendDiagnostic(error);
|
||||
result = result.AppendDiagnostic(error);
|
||||
}
|
||||
_nestedLevel++;
|
||||
var result = base.VisitRazorDirective(node);
|
||||
|
||||
_nestedLevel--;
|
||||
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Reference in New Issue