1- // Copyright (c) .NET Foundation. All rights reserved.
1+ // Copyright (c) .NET Foundation. All rights reserved.
22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
44using System ;
@@ -163,7 +163,7 @@ public override SyntaxNode VisitMarkupElement(MarkupElementSyntax node)
163163 if ( endTag != null )
164164 {
165165 var tagName = endTag . GetTagNameWithOptionalBang ( ) ;
166- if ( TryRewriteTagHelperEnd ( endTag , out tagHelperEnd ) )
166+ if ( TryRewriteTagHelperEnd ( startTag , endTag , out tagHelperEnd ) )
167167 {
168168 // This is a tag helper
169169 if ( startTag == null )
@@ -289,10 +289,10 @@ private bool TryRewriteTagHelperStart(
289289 return true ;
290290 }
291291
292- private bool TryRewriteTagHelperEnd ( MarkupEndTagSyntax tagBlock , out MarkupTagHelperEndTagSyntax rewritten )
292+ private bool TryRewriteTagHelperEnd ( MarkupStartTagSyntax startTag , MarkupEndTagSyntax endTag , out MarkupTagHelperEndTagSyntax rewritten )
293293 {
294294 rewritten = null ;
295- var tagName = tagBlock . GetTagNameWithOptionalBang ( ) ;
295+ var tagName = endTag . GetTagNameWithOptionalBang ( ) ;
296296 // Could not determine tag name, it can't be a TagHelper, continue on and track the element.
297297 if ( string . IsNullOrEmpty ( tagName ) || tagName . StartsWith ( "!" ) )
298298 {
@@ -301,13 +301,13 @@ private bool TryRewriteTagHelperEnd(MarkupEndTagSyntax tagBlock, out MarkupTagHe
301301
302302 var tracker = CurrentTagHelperTracker ;
303303 var tagNameScope = tracker ? . TagName ?? string . Empty ;
304- if ( ! IsPotentialTagHelperEnd ( tagName , tagBlock ) )
304+ if ( ! IsPotentialTagHelperEnd ( tagName , endTag ) )
305305 {
306306 return false ;
307307 }
308308
309309 // Validate that our end tag matches the currently scoped tag, if not we may need to error.
310- if ( tagNameScope . Equals ( tagName , StringComparison . OrdinalIgnoreCase ) )
310+ if ( startTag != null && tagNameScope . Equals ( tagName , StringComparison . OrdinalIgnoreCase ) )
311311 {
312312 // If there are additional end tags required before we can build our block it means we're in a
313313 // situation like this: <myth req="..."><myth></myth></myth> where we're at the inside </myth>.
@@ -318,7 +318,7 @@ private bool TryRewriteTagHelperEnd(MarkupEndTagSyntax tagBlock, out MarkupTagHe
318318 return false ;
319319 }
320320
321- ValidateEndTagSyntax ( tagName , tagBlock ) ;
321+ ValidateEndTagSyntax ( tagName , endTag ) ;
322322
323323 _trackerStack . Pop ( ) ;
324324 }
@@ -347,7 +347,7 @@ private bool TryRewriteTagHelperEnd(MarkupEndTagSyntax tagBlock, out MarkupTagHe
347347 // End tag TagHelper that states it shouldn't have an end tag.
348348 _errorSink . OnError (
349349 RazorDiagnosticFactory . CreateParsing_TagHelperMustNotHaveAnEndTag (
350- new SourceSpan ( SourceLocationTracker . Advance ( tagBlock . GetSourceLocation ( _source ) , "</" ) , tagName . Length ) ,
350+ new SourceSpan ( SourceLocationTracker . Advance ( endTag . GetSourceLocation ( _source ) , "</" ) , tagName . Length ) ,
351351 tagName ,
352352 descriptor . DisplayName ,
353353 invalidRule . TagStructure ) ) ;
@@ -358,7 +358,7 @@ private bool TryRewriteTagHelperEnd(MarkupEndTagSyntax tagBlock, out MarkupTagHe
358358 }
359359
360360 rewritten = SyntaxFactory . MarkupTagHelperEndTag (
361- tagBlock . OpenAngle , tagBlock . ForwardSlash , tagBlock . Bang , tagBlock . Name , tagBlock . MiscAttributeContent , tagBlock . CloseAngle ) ;
361+ endTag . OpenAngle , endTag . ForwardSlash , endTag . Bang , endTag . Name , endTag . MiscAttributeContent , endTag . CloseAngle ) ;
362362
363363 return true ;
364364 }
0 commit comments