Bring back errors for missing tags in component documents (dotnet/aspnetcore-tooling#351)

\n\nCommit migrated from ca1e656f6b
This commit is contained in:
Ajay Bhargav Baaskaran 2019-03-21 12:22:28 -07:00 committed by GitHub
parent b2b207faa1
commit 62199e2195
4 changed files with 29 additions and 17 deletions

View File

@ -50,16 +50,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
return RazorDiagnostic.Create(UnexpectedClosingTag, span ?? SourceSpan.Undefined, tagName);
}
public static readonly RazorDiagnosticDescriptor MismatchedClosingTag = new RazorDiagnosticDescriptor(
"BL9982",
() => "Mismatching closing tag. Found '{0}' but expected '{1}'.",
RazorDiagnosticSeverity.Error);
public static RazorDiagnostic Create_MismatchedClosingTag(SourceSpan? span, string expectedTagName, string tagName)
{
return RazorDiagnostic.Create(MismatchedClosingTag, span ?? SourceSpan.Undefined, expectedTagName, tagName);
}
public static readonly RazorDiagnosticDescriptor UnexpectedClosingTagForVoidElement = new RazorDiagnosticDescriptor(
"BL9983",
() => "Unexpected closing tag '{0}'. The element '{0}' is a void element, and should be used without a closing tag.",

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.AspNetCore.Razor.Language.Components;
using Microsoft.AspNetCore.Razor.Language.Extensions;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
using Microsoft.AspNetCore.Razor.Language.Legacy;
@ -1137,13 +1138,34 @@ namespace Microsoft.AspNetCore.Razor.Language
public override void VisitMarkupElement(MarkupElementSyntax node)
{
_builder.Push(new MarkupElementIntermediateNode()
var element = new MarkupElementIntermediateNode()
{
Source = BuildSourceSpanFromNode(node),
// Could be empty while the tag is being typed in.
TagName = node.StartTag?.GetTagNameWithOptionalBang() ?? node.EndTag?.GetTagName() ?? string.Empty,
});
TagName = node.StartTag?.GetTagNameWithOptionalBang() ?? node.EndTag?.GetTagNameWithOptionalBang() ?? string.Empty,
};
if (node.StartTag != null && node.EndTag != null && node.StartTag.IsVoidElement())
{
element.Diagnostics.Add(
ComponentDiagnosticFactory.Create_UnexpectedClosingTagForVoidElement(
BuildSourceSpanFromNode(node.EndTag), node.EndTag.GetTagNameWithOptionalBang()));
}
else if (node.StartTag != null && node.EndTag == null && !node.StartTag.IsVoidElement() && !node.StartTag.IsSelfClosing())
{
element.Diagnostics.Add(
ComponentDiagnosticFactory.Create_UnclosedTag(
BuildSourceSpanFromNode(node.StartTag), node.StartTag.GetTagNameWithOptionalBang()));
}
else if (node.StartTag == null && node.EndTag != null)
{
element.Diagnostics.Add(
ComponentDiagnosticFactory.Create_UnexpectedClosingTag(
BuildSourceSpanFromNode(node.EndTag), node.EndTag.GetTagNameWithOptionalBang()));
}
_builder.Push(element);
base.VisitMarkupElement(node);

View File

@ -162,7 +162,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var endTag = (MarkupEndTagSyntax)Visit(node.EndTag);
if (endTag != null)
{
var tagName = endTag.GetTagName();
var tagName = endTag.GetTagNameWithOptionalBang();
if (TryRewriteTagHelperEnd(endTag, out tagHelperEnd))
{
// This is a tag helper
@ -288,7 +288,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private bool TryRewriteTagHelperEnd(MarkupEndTagSyntax tagBlock, out MarkupTagHelperEndTagSyntax rewritten)
{
rewritten = null;
var tagName = tagBlock.GetTagName();
var tagName = tagBlock.GetTagNameWithOptionalBang();
// Could not determine tag name, it can't be a TagHelper, continue on and track the element.
if (string.IsNullOrEmpty(tagName) || tagName.StartsWith("!"))
{
@ -599,7 +599,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void ValidateParentAllowsPlainEndTag(MarkupEndTagSyntax tagBlock)
{
var tagName = tagBlock.GetTagName();
var tagName = tagBlock.GetTagNameWithOptionalBang();
// Treat partial tags such as '</' which have no tag names as content.
if (string.IsNullOrEmpty(tagName))

View File

@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Syntax
public SyntaxList<RazorSyntaxNode> Children => GetLegacyChildren();
public string GetTagName()
public string GetTagNameWithOptionalBang()
{
return Name.IsMissing ? string.Empty : Bang?.Content + Name.Content;
}