Fix aspnet/AspNetCoredotnet/aspnetcore-tooling#6186

The issue here is that the compiler generates a different syntax tree
for `data-` attributes :(. I've added a note to dotnet/aspnetcore-tooling#6112 to follow up on
the compiler behavior. We used to parse data- attributes differently for
components, but I really don't think having the compiler special case
them makes sense.

For now I've added a workaround here to lower `data-` attributes in a
fashion similar to other dynamic attribute values.
\n\nCommit migrated from f5109fbfec
This commit is contained in:
Ryan Nowak 2018-12-31 14:54:10 -08:00
parent 7f3a187455
commit f973693438
1 changed files with 33 additions and 1 deletions

View File

@ -1192,7 +1192,7 @@ namespace Microsoft.AspNetCore.Razor.Language
Source = BuildSourceSpanFromNode(node),
});
}
// Example
// <input checked="hello-world `@false`"/>
// Prefix= (space)
@ -1348,6 +1348,22 @@ namespace Microsoft.AspNetCore.Razor.Language
// We need to capture this in the IR so that we can give each piece the correct source mappings
public override void VisitCSharpExplicitExpression(CSharpExplicitExpressionSyntax node)
{
if (_builder.Current is HtmlAttributeIntermediateNode)
{
// This can happen inside a data- attribute
_builder.Push(new CSharpExpressionAttributeValueIntermediateNode()
{
Prefix = string.Empty,
Source = this.BuildSourceSpanFromNode(node),
});
base.VisitCSharpExplicitExpression(node);
_builder.Pop();
return;
}
if (_builder.Current is CSharpExpressionAttributeValueIntermediateNode)
{
base.VisitCSharpExplicitExpression(node);
@ -1385,6 +1401,22 @@ namespace Microsoft.AspNetCore.Razor.Language
public override void VisitCSharpImplicitExpression(CSharpImplicitExpressionSyntax node)
{
if (_builder.Current is HtmlAttributeIntermediateNode)
{
// This can happen inside a data- attribute
_builder.Push(new CSharpExpressionAttributeValueIntermediateNode()
{
Prefix = string.Empty,
Source = this.BuildSourceSpanFromNode(node),
});
base.VisitCSharpImplicitExpression(node);
_builder.Pop();
return;
}
if (_builder.Current is CSharpExpressionAttributeValueIntermediateNode)
{
base.VisitCSharpImplicitExpression(node);