From 8d6e13082d47b61c0bfb5ee986be52933a5cdfb7 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Sun, 30 Jun 2019 16:39:11 -0700 Subject: [PATCH] Remove handling of pre-directive-attribute cases \n\nCommit migrated from https://github.com/dotnet/aspnetcore-tooling/commit/2e34a6ace6af53d404f70c6fb24cbfa621d89655 --- .../Components/ComponentBindLoweringPass.cs | 86 +++---------------- .../Components/ComponentDiagnosticFactory.cs | 28 ------ 2 files changed, 14 insertions(+), 100 deletions(-) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentBindLoweringPass.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentBindLoweringPass.cs index 9644399958..1cd58ab5c8 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentBindLoweringPass.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentBindLoweringPass.cs @@ -329,17 +329,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Components }; } - if (TryGetFormatNode( - parent, - node, - valueAttributeName, - out var formatNode)) - { - // If there is a format- attribute present, add a warning to say that it's unsupported. - parent.Children.Remove(formatNode); - parent.Diagnostics.Add(ComponentDiagnosticFactory.CreateBindAttribute_FormatNode_Unsupported(formatNode.Source)); - } - var valueExpressionTokens = new List(); var changeExpressionTokens = new List(); if (changeAttribute != null && changeAttribute.IsDelegateProperty()) @@ -489,54 +478,23 @@ namespace Microsoft.AspNetCore.Razor.Language.Components } } - private bool TryParseBindAttribute( - BindEntry bindEntry, - out string valueAttributeName, - out string changeAttributeName) + private bool TryParseBindAttribute(BindEntry bindEntry, out string valueAttributeName) { var attributeName = bindEntry.BindNode.AttributeName; valueAttributeName = null; - changeAttributeName = null; - - if (!attributeName.StartsWith("bind")) - { - return false; - } - - if (bindEntry.BindEventNode != null) - { - changeAttributeName = GetAttributeContent(bindEntry.BindEventNode)?.Content?.Trim('"'); - } if (attributeName == "bind") { return true; } - var segments = attributeName.Split('-'); - for (var i = 0; i < segments.Length; i++) + if (!attributeName.StartsWith("bind-")) { - if (string.IsNullOrEmpty(segments[i])) - { - return false; - } + return false; } - switch (segments.Length) - { - case 2: - valueAttributeName = segments[1]; - return true; - - case 3: - valueAttributeName = segments[1]; - changeAttributeName = segments[2]; - bindEntry.BindNode.Diagnostics.Add(ComponentDiagnosticFactory.CreateBindAttribute_UnsupportedFormat(bindEntry.BindNode.Source)); - return true; - - default: - return false; - } + valueAttributeName = attributeName.Substring("bind-".Length); + return true; } // Attempts to compute the attribute names that should be used for an instance of 'bind'. @@ -550,18 +508,25 @@ namespace Microsoft.AspNetCore.Razor.Language.Components out BoundAttributeDescriptor changeAttribute, out BoundAttributeDescriptor expressionAttribute) { + valueAttributeName = null; + changeAttributeName = null; + expressionAttributeName = null; valueAttribute = null; changeAttribute = null; expressionAttribute = null; - expressionAttributeName = null; // Even though some of our 'bind' tag helpers specify the attribute names, they // should still satisfy one of the valid syntaxes. - if (!TryParseBindAttribute(bindEntry, out valueAttributeName, out changeAttributeName)) + if (!TryParseBindAttribute(bindEntry, out valueAttributeName)) { return false; } + if (bindEntry.BindEventNode != null) + { + changeAttributeName = GetAttributeContent(bindEntry.BindEventNode)?.Content?.Trim('"'); + } + // The tag helper specifies attribute names, they should win. // // This handles cases like where the tag helper is @@ -628,29 +593,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Components return true; } - private bool TryGetFormatNode( - IntermediateNode node, - TagHelperDirectiveAttributeIntermediateNode attributeNode, - string valueAttributeName, - out TagHelperPropertyIntermediateNode formatNode) - { - for (var i = 0; i < node.Children.Count; i++) - { - var child = node.Children[i] as TagHelperPropertyIntermediateNode; - if (child != null && - child.TagHelper != null && - child.TagHelper == attributeNode.TagHelper && - child.AttributeName == "format-" + valueAttributeName) - { - formatNode = child; - return true; - } - } - - formatNode = null; - return false; - } - private void RewriteNodesForDelegateBind( IntermediateToken original, IntermediateToken format, diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentDiagnosticFactory.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentDiagnosticFactory.cs index 07a2657a6c..e095499508 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentDiagnosticFactory.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentDiagnosticFactory.cs @@ -348,34 +348,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Components return diagnostic; } - public static readonly RazorDiagnosticDescriptor BindAttribute_UnsupportedFormat = - new RazorDiagnosticDescriptor( - $"{DiagnosticPrefix}10005", - () => "Specifying event handlers in bind attributes are no longer supported. Specify it using the bind:event=... attribute instead.", - RazorDiagnosticSeverity.Warning); - - public static RazorDiagnostic CreateBindAttribute_UnsupportedFormat(SourceSpan? source) - { - var diagnostic = RazorDiagnostic.Create( - BindAttribute_UnsupportedFormat, - source ?? SourceSpan.Undefined); - return diagnostic; - } - - public static readonly RazorDiagnosticDescriptor BindAttribute_FormatNode_Unsupported = - new RazorDiagnosticDescriptor( - $"{DiagnosticPrefix}10006", - () => "Specifying format using 'format-...' attributes are no longer supported. Specify it using the 'bind-...:format=...' attribute instead.", - RazorDiagnosticSeverity.Warning); - - public static RazorDiagnostic CreateBindAttribute_FormatNode_Unsupported(SourceSpan? source) - { - var diagnostic = RazorDiagnostic.Create( - BindAttribute_FormatNode_Unsupported, - source ?? SourceSpan.Undefined); - return diagnostic; - } - public static readonly RazorDiagnosticDescriptor DuplicateMarkupAttribute = new RazorDiagnosticDescriptor( $"{DiagnosticPrefix}10007",