Correct logic for GetTagName

\n\nCommit migrated from 72a389149a
This commit is contained in:
Ajay Bhargav Baaskaran 2018-12-06 01:12:07 -08:00
parent 0c71f4f520
commit cf6b1d7135
2 changed files with 30 additions and 6 deletions

View File

@ -221,7 +221,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var tagName = startTag.GetTagName();
// Could not determine tag name, it can't be a TagHelper, continue on and track the element.
if (tagName == null)
if (tagName == null || tagName.StartsWith("!"))
{
return false;
}
@ -288,7 +288,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
rewritten = null;
var tagName = tagBlock.GetTagName();
// Could not determine tag name, it can't be a TagHelper, continue on and track the element.
if (tagName == null)
if (tagName == null || tagName.StartsWith("!"))
{
return false;
}

View File

@ -243,15 +243,33 @@ namespace Microsoft.AspNetCore.Razor.Language.Syntax
throw new ArgumentNullException(nameof(tagBlock));
}
if (tagBlock.Children.Count == 0 || !(tagBlock.Children[0] is MarkupTextLiteralSyntax childLiteral))
MarkupTextLiteralSyntax nameLiteral = null;
var isBangTag = false;
if (tagBlock.Children.Count > 0 && tagBlock.Children[0] is MarkupTextLiteralSyntax firstChild)
{
if (firstChild.GetContent().StartsWith("<") &&
tagBlock.Children.Count >= 3 &&
tagBlock.Children[1] is RazorMetaCodeSyntax &&
tagBlock.Children[2] is MarkupTextLiteralSyntax potentialBangTagName)
{
isBangTag = true;
nameLiteral = potentialBangTagName;
}
else
{
nameLiteral = firstChild;
}
}
if (nameLiteral == null)
{
return null;
}
SyntaxToken textToken = null;
for (var i = 0; i < childLiteral.LiteralTokens.Count; i++)
for (var i = 0; i < nameLiteral.LiteralTokens.Count; i++)
{
var token = childLiteral.LiteralTokens[i];
var token = nameLiteral.LiteralTokens[i];
if (token != null &&
(token.Kind == SyntaxKind.Whitespace || token.Kind == SyntaxKind.Text))
@ -266,7 +284,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Syntax
return null;
}
return textToken.Kind == SyntaxKind.Whitespace ? null : textToken.Content;
var name = textToken.Kind == SyntaxKind.Whitespace ? null : textToken.Content;
if (name != null && isBangTag)
{
name = "!" + name;
}
return name;
}
public static bool IsSelfClosing(this MarkupTagBlockSyntax tagBlock)