Allow nullable types with generic arguments in directives
This commit is contained in:
parent
4fe07f2298
commit
364fc1a55d
|
|
@ -959,7 +959,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
if (Optional(CSharpSymbolType.Identifier) || Optional(CSharpSymbolType.Keyword))
|
if (Optional(CSharpSymbolType.Identifier) || Optional(CSharpSymbolType.Keyword))
|
||||||
{
|
{
|
||||||
Optional(CSharpSymbolType.QuestionMark); // Nullable
|
|
||||||
if (Optional(CSharpSymbolType.DoubleColon))
|
if (Optional(CSharpSymbolType.DoubleColon))
|
||||||
{
|
{
|
||||||
if (!Optional(CSharpSymbolType.Identifier))
|
if (!Optional(CSharpSymbolType.Identifier))
|
||||||
|
|
@ -975,6 +974,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
NamespaceOrTypeName();
|
NamespaceOrTypeName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional(CSharpSymbolType.QuestionMark); // Nullable
|
||||||
|
|
||||||
while (At(CSharpSymbolType.LeftBracket))
|
while (At(CSharpSymbolType.LeftBracket))
|
||||||
{
|
{
|
||||||
Balance(BalancingModes.None);
|
Balance(BalancingModes.None);
|
||||||
|
|
|
||||||
|
|
@ -784,6 +784,33 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
Factory.MetaCode(" ; ").Accepts(AcceptedCharactersInternal.WhiteSpace)));
|
Factory.MetaCode(" ; ").Accepts(AcceptedCharactersInternal.WhiteSpace)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("string?")]
|
||||||
|
[InlineData("string?[]")]
|
||||||
|
[InlineData("global::System.Int32?")]
|
||||||
|
[InlineData("KeyValuePair<string, string>?")]
|
||||||
|
[InlineData("KeyValuePair<string, string>?[]")]
|
||||||
|
[InlineData("global::System.Collections.Generic.KeyValuePair<string, string>?[]")]
|
||||||
|
public void DirectiveDescriptor_AllowsNullableTypes(string expectedType)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var descriptor = DirectiveDescriptor.CreateDirective(
|
||||||
|
"custom",
|
||||||
|
DirectiveKind.SingleLine,
|
||||||
|
b => b.AddTypeToken());
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
ParseCodeBlockTest(
|
||||||
|
$"@custom {expectedType}",
|
||||||
|
new[] { descriptor },
|
||||||
|
new DirectiveBlock(
|
||||||
|
new DirectiveChunkGenerator(descriptor),
|
||||||
|
Factory.CodeTransition(),
|
||||||
|
Factory.MetaCode("custom").Accepts(AcceptedCharactersInternal.None),
|
||||||
|
Factory.Span(SpanKindInternal.Code, " ", markup: false).Accepts(AcceptedCharactersInternal.WhiteSpace),
|
||||||
|
Factory.Span(SpanKindInternal.Code, expectedType, markup: false).AsDirectiveToken(descriptor.Tokens[0])));
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DirectiveDescriptor_ErrorsExtraContentAfterDirective()
|
public void DirectiveDescriptor_ErrorsExtraContentAfterDirective()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue