зеркало из https://github.com/dotnet/razor.git
Fix an assumption in ComponentBindLoweringPass (#212)
This commit is contained in:
Родитель
4b95c23145
Коммит
315f804d6e
|
@ -507,15 +507,19 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
return GetToken(node);
|
||||
}
|
||||
|
||||
// In error cases we won't have a single token, but we still want to generate the code.
|
||||
IntermediateToken GetToken(IntermediateNode parent)
|
||||
{
|
||||
return
|
||||
parent.Children.Count == 1 ? (IntermediateToken)parent.Children[0] : new IntermediateToken()
|
||||
{
|
||||
Kind = TokenKind.CSharp,
|
||||
Content = string.Join(string.Empty, parent.Children.OfType<IntermediateToken>().Select(t => t.Content)),
|
||||
};
|
||||
if (parent.Children.Count == 1 && parent.Children[0] is IntermediateToken token)
|
||||
{
|
||||
return token;
|
||||
}
|
||||
|
||||
// In error cases we won't have a single token, but we still want to generate the code.
|
||||
return new IntermediateToken()
|
||||
{
|
||||
Kind = TokenKind.CSharp,
|
||||
Content = string.Join(string.Empty, parent.Children.OfType<IntermediateToken>().Select(t => t.Content)),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,5 +79,22 @@ namespace Test
|
|||
var diagnostic = Assert.Single(generated.Diagnostics);
|
||||
Assert.Equal("BL9991", diagnostic.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bind_InvalidUseOfDirective_DoesNotThrow()
|
||||
{
|
||||
var generated = CompileToCSharp(@"
|
||||
@addTagHelper *, TestAssembly
|
||||
<input type=""text"" bind=""@page"" />
|
||||
@functions {
|
||||
public string page { get; set; } = ""text"";
|
||||
}");
|
||||
|
||||
// Assert
|
||||
Assert.Collection(
|
||||
generated.Diagnostics,
|
||||
d => Assert.Equal("RZ2005", d.Id),
|
||||
d => Assert.Equal("RZ1011", d.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче