Fix an assumption in ComponentBindLoweringPass (dotnet/aspnetcore-tooling#212)

\n\nCommit migrated from 315f804d6e
This commit is contained in:
Ajay Bhargav Baaskaran 2019-02-14 17:25:52 -08:00 committed by GitHub
parent 67ef6b7e3c
commit 0ab2a1e586
1 changed files with 11 additions and 7 deletions

View File

@ -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)),
};
}
}
}