1
- // Copyright (c) .NET Foundation. All rights reserved.
1
+ // Copyright (c) .NET Foundation. All rights reserved.
2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
4
using System ;
@@ -163,7 +163,7 @@ public override SyntaxNode VisitMarkupElement(MarkupElementSyntax node)
163
163
if ( endTag != null )
164
164
{
165
165
var tagName = endTag . GetTagNameWithOptionalBang ( ) ;
166
- if ( TryRewriteTagHelperEnd ( endTag , out tagHelperEnd ) )
166
+ if ( TryRewriteTagHelperEnd ( startTag , endTag , out tagHelperEnd ) )
167
167
{
168
168
// This is a tag helper
169
169
if ( startTag == null )
@@ -289,10 +289,10 @@ private bool TryRewriteTagHelperStart(
289
289
return true ;
290
290
}
291
291
292
- private bool TryRewriteTagHelperEnd ( MarkupEndTagSyntax tagBlock , out MarkupTagHelperEndTagSyntax rewritten )
292
+ private bool TryRewriteTagHelperEnd ( MarkupStartTagSyntax startTag , MarkupEndTagSyntax endTag , out MarkupTagHelperEndTagSyntax rewritten )
293
293
{
294
294
rewritten = null ;
295
- var tagName = tagBlock . GetTagNameWithOptionalBang ( ) ;
295
+ var tagName = endTag . GetTagNameWithOptionalBang ( ) ;
296
296
// Could not determine tag name, it can't be a TagHelper, continue on and track the element.
297
297
if ( string . IsNullOrEmpty ( tagName ) || tagName . StartsWith ( "!" ) )
298
298
{
@@ -301,13 +301,13 @@ private bool TryRewriteTagHelperEnd(MarkupEndTagSyntax tagBlock, out MarkupTagHe
301
301
302
302
var tracker = CurrentTagHelperTracker ;
303
303
var tagNameScope = tracker ? . TagName ?? string . Empty ;
304
- if ( ! IsPotentialTagHelperEnd ( tagName , tagBlock ) )
304
+ if ( ! IsPotentialTagHelperEnd ( tagName , endTag ) )
305
305
{
306
306
return false ;
307
307
}
308
308
309
309
// 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 ) )
311
311
{
312
312
// If there are additional end tags required before we can build our block it means we're in a
313
313
// 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
318
318
return false ;
319
319
}
320
320
321
- ValidateEndTagSyntax ( tagName , tagBlock ) ;
321
+ ValidateEndTagSyntax ( tagName , endTag ) ;
322
322
323
323
_trackerStack . Pop ( ) ;
324
324
}
@@ -347,7 +347,7 @@ private bool TryRewriteTagHelperEnd(MarkupEndTagSyntax tagBlock, out MarkupTagHe
347
347
// End tag TagHelper that states it shouldn't have an end tag.
348
348
_errorSink . OnError (
349
349
RazorDiagnosticFactory . CreateParsing_TagHelperMustNotHaveAnEndTag (
350
- new SourceSpan ( SourceLocationTracker . Advance ( tagBlock . GetSourceLocation ( _source ) , "</" ) , tagName . Length ) ,
350
+ new SourceSpan ( SourceLocationTracker . Advance ( endTag . GetSourceLocation ( _source ) , "</" ) , tagName . Length ) ,
351
351
tagName ,
352
352
descriptor . DisplayName ,
353
353
invalidRule . TagStructure ) ) ;
@@ -358,7 +358,7 @@ private bool TryRewriteTagHelperEnd(MarkupEndTagSyntax tagBlock, out MarkupTagHe
358
358
}
359
359
360
360
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 ) ;
362
362
363
363
return true ;
364
364
}
0 commit comments