Merge branch 'rel/15.3' into dev
# Conflicts: # src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs # src/Microsoft.AspNetCore.Razor.Language/TagHelperDescriptorBuilder.cs # src/Microsoft.CodeAnalysis.Razor/ViewComponentTagHelperDescriptorFactory.cs # test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpDirectivesTest.cs # test/Microsoft.CodeAnalysis.Razor.Test/ViewComponentTagHelperDescriptorFactoryTest.cs
This commit is contained in:
commit
2eb443acb6
|
|
@ -1559,7 +1559,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
return;
|
||||
}
|
||||
|
||||
var outputKind = SpanKindInternal.Markup;
|
||||
switch (tokenDescriptor.Kind)
|
||||
{
|
||||
case DirectiveTokenKind.Type:
|
||||
|
|
@ -1572,8 +1571,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
outputKind = SpanKindInternal.Code;
|
||||
break;
|
||||
|
||||
case DirectiveTokenKind.Namespace:
|
||||
|
|
@ -1586,8 +1583,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
outputKind = SpanKindInternal.Code;
|
||||
break;
|
||||
|
||||
case DirectiveTokenKind.Member:
|
||||
|
|
@ -1603,8 +1598,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
CurrentSymbol.Content.Length);
|
||||
return;
|
||||
}
|
||||
|
||||
outputKind = SpanKindInternal.Code;
|
||||
break;
|
||||
|
||||
case DirectiveTokenKind.String:
|
||||
|
|
@ -1624,7 +1617,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
}
|
||||
|
||||
Span.ChunkGenerator = new DirectiveTokenChunkGenerator(tokenDescriptor);
|
||||
Output(outputKind, AcceptedCharactersInternal.NonWhiteSpace);
|
||||
Output(SpanKindInternal.Code, AcceptedCharactersInternal.NonWhiteSpace);
|
||||
}
|
||||
|
||||
AcceptWhile(IsSpacingToken(includeNewLines: false, includeComments: true));
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
new[] { '@', '!', '<', '/', '?', '[', '>', ']', '=', '"', '\'', '*' });
|
||||
|
||||
|
||||
private string _displayName;
|
||||
private string _documentation;
|
||||
private string _tagOutputHint;
|
||||
private HashSet<string> _allowedChildTags;
|
||||
|
|
@ -29,6 +30,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
private TagHelperDescriptorBuilder(string typeName, string assemblyName)
|
||||
{
|
||||
_typeName = typeName;
|
||||
_displayName = _typeName;
|
||||
_assemblyName = assemblyName;
|
||||
_metadata = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
}
|
||||
|
|
@ -133,6 +135,18 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
return this;
|
||||
}
|
||||
|
||||
public TagHelperDescriptorBuilder DisplayName(string displayName)
|
||||
{
|
||||
if (displayName == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(displayName));
|
||||
}
|
||||
|
||||
_displayName = displayName;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TagHelperDescriptor Build()
|
||||
{
|
||||
var validationDiagnostics = Validate();
|
||||
|
|
@ -146,7 +160,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
_typeName,
|
||||
_assemblyName,
|
||||
_typeName /* Name */,
|
||||
_typeName /* DisplayName */,
|
||||
_displayName,
|
||||
_documentation,
|
||||
_tagOutputHint,
|
||||
_tagMatchingRules ?? Enumerable.Empty<TagMatchingRule>(),
|
||||
|
|
|
|||
|
|
@ -34,8 +34,10 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
var shortName = GetShortName(type);
|
||||
var tagName = $"vc:{HtmlCase.ToHtmlCase(shortName)}";
|
||||
var typeName = $"__Generated__{shortName}ViewComponentTagHelper";
|
||||
var descriptorBuilder = TagHelperDescriptorBuilder.Create(typeName, assemblyName);
|
||||
|
||||
var displayName = shortName + "ViewComponentTagHelper";
|
||||
var descriptorBuilder = TagHelperDescriptorBuilder.Create(typeName, assemblyName)
|
||||
.DisplayName(displayName);
|
||||
|
||||
if (TryFindInvokeMethod(type, out var method, out var diagnostic))
|
||||
{
|
||||
var methodParameters = method.Parameters;
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, "\"AString\"", markup: false)
|
||||
Factory.Span(SpanKindInternal.Code, "\"AString\"", markup: false)
|
||||
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens[0]))
|
||||
.Accepts(AcceptedCharactersInternal.NonWhiteSpace)));
|
||||
}
|
||||
|
|
@ -255,7 +255,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
.Accepts(AcceptedCharactersInternal.NonWhiteSpace),
|
||||
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, "\"AString\"", markup: false)
|
||||
Factory.Span(SpanKindInternal.Code, "\"AString\"", markup: false)
|
||||
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens[2]))
|
||||
.Accepts(AcceptedCharactersInternal.NonWhiteSpace)));
|
||||
}
|
||||
|
|
@ -278,7 +278,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, "\"Header\"", markup: false)
|
||||
Factory.Span(SpanKindInternal.Code, "\"Header\"", markup: false)
|
||||
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens[0]))
|
||||
.Accepts(AcceptedCharactersInternal.NonWhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.AllWhiteSpace),
|
||||
|
|
@ -314,7 +314,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, "\"Name\"", markup: false)
|
||||
Factory.Span(SpanKindInternal.Code, "\"Name\"", markup: false)
|
||||
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens[0]))
|
||||
.Accepts(AcceptedCharactersInternal.NonWhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.AllWhiteSpace),
|
||||
|
|
@ -401,7 +401,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, "\"hello\"", markup: false)
|
||||
Factory.Span(SpanKindInternal.Code, "\"hello\"", markup: false)
|
||||
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens[0]))
|
||||
.Accepts(AcceptedCharactersInternal.NonWhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, " ; ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace)));
|
||||
|
|
@ -430,7 +430,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, "\"hello\"", markup: false)
|
||||
Factory.Span(SpanKindInternal.Code, "\"hello\"", markup: false)
|
||||
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens[0]))
|
||||
.Accepts(AcceptedCharactersInternal.NonWhiteSpace),
|
||||
|
||||
|
|
@ -461,7 +461,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, "\"Hello\"", markup: false)
|
||||
Factory.Span(SpanKindInternal.Code, "\"Hello\"", markup: false)
|
||||
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens[0]))
|
||||
.Accepts(AcceptedCharactersInternal.NonWhiteSpace),
|
||||
|
||||
|
|
@ -492,7 +492,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, "\"Hello\"", markup: false)
|
||||
Factory.Span(SpanKindInternal.Code, "\"Hello\"", markup: false)
|
||||
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens[0]))
|
||||
.Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
|
||||
expectedErorr);
|
||||
|
|
@ -521,7 +521,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, "\"Hello\"", markup: false)
|
||||
Factory.Span(SpanKindInternal.Code, "\"Hello\"", markup: false)
|
||||
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens[0]))
|
||||
.Accepts(AcceptedCharactersInternal.NonWhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.AllWhiteSpace),
|
||||
|
|
@ -979,7 +979,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, "\"simple-value\"", markup: false)
|
||||
Factory.Span(SpanKindInternal.Code, "\"simple-value\"", markup: false)
|
||||
.Accepts(AcceptedCharactersInternal.NonWhiteSpace)
|
||||
.With(chunkGenerator)));
|
||||
}
|
||||
|
|
@ -1004,7 +1004,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, "\"{formaction}?/{id}?\"", markup: false)
|
||||
Factory.Span(SpanKindInternal.Code, "\"{formaction}?/{id}?\"", markup: false)
|
||||
.Accepts(AcceptedCharactersInternal.NonWhiteSpace)
|
||||
.With(chunkGenerator)));
|
||||
}
|
||||
|
|
@ -1027,7 +1027,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.CodeTransition(),
|
||||
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
||||
Factory.Span(SpanKindInternal.Markup, "\"{formaction}?/{id}?\"", markup: false)
|
||||
Factory.Span(SpanKindInternal.Code, "\"{formaction}?/{id}?\"", markup: false)
|
||||
.Accepts(AcceptedCharactersInternal.NonWhiteSpace)
|
||||
.With(new DirectiveTokenChunkGenerator(descriptor.Tokens.First())),
|
||||
Factory.Span(SpanKindInternal.Code, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.Language
|
||||
{
|
||||
public class TagHelperDescriptorBuilderTest
|
||||
{
|
||||
[Fact]
|
||||
public void DisplayName_SetsDescriptorsDisplayName()
|
||||
{
|
||||
// Arrange
|
||||
var expectedDisplayName = "ExpectedDisplayName";
|
||||
var builder = TagHelperDescriptorBuilder.Create("TestTagHelper", "TestAssembly");
|
||||
|
||||
// Act
|
||||
var descriptor = builder.DisplayName(expectedDisplayName).Build();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedDisplayName, descriptor.DisplayName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DisplayName_DefaultsToTypeName()
|
||||
{
|
||||
// Arrange
|
||||
var expectedDisplayName = "TestTagHelper";
|
||||
var builder = TagHelperDescriptorBuilder.Create("TestTagHelper", "TestAssembly");
|
||||
|
||||
// Act
|
||||
var descriptor = builder.Build();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedDisplayName, descriptor.DisplayName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
using Xunit;
|
||||
using Microsoft.AspNetCore.Razor.Language.Legacy;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
||||
|
|
@ -22,6 +21,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
var expectedDescriptor = TagHelperDescriptorBuilder.Create(
|
||||
"__Generated__StringParameterViewComponentTagHelper",
|
||||
typeof(StringParameterViewComponent).GetTypeInfo().Assembly.GetName().Name)
|
||||
.DisplayName("StringParameterViewComponentTagHelper")
|
||||
.TagMatchingRule(rule =>
|
||||
rule
|
||||
.RequireTagName("vc:string-parameter")
|
||||
|
|
@ -57,6 +57,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
var expectedDescriptor = TagHelperDescriptorBuilder.Create(
|
||||
"__Generated__VariousParameterViewComponentTagHelper",
|
||||
typeof(VariousParameterViewComponent).GetTypeInfo().Assembly.GetName().Name)
|
||||
.DisplayName("VariousParameterViewComponentTagHelper")
|
||||
.TagMatchingRule(rule =>
|
||||
rule
|
||||
.RequireTagName("vc:various-parameter")
|
||||
|
|
@ -99,6 +100,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
var expectedDescriptor = TagHelperDescriptorBuilder.Create(
|
||||
"__Generated__GenericParameterViewComponentTagHelper",
|
||||
typeof(GenericParameterViewComponent).GetTypeInfo().Assembly.GetName().Name)
|
||||
.DisplayName("GenericParameterViewComponentTagHelper")
|
||||
.TagMatchingRule(rule =>
|
||||
rule
|
||||
.RequireTagName("vc:generic-parameter")
|
||||
|
|
|
|||
Loading…
Reference in New Issue