Fix aspnet/AspNetCoredotnet/aspnetcore-tooling#6187
The bug here is that we have extra whitespace being written out when the
component renders. This happens because parser adds an empty C#
statement node to wrap all of the whitespace that precedes `@functions`.
This is tracked by aspnet/AspNetCoredotnet/aspnetcore-tooling#6207.
To fix this issue I'm allowing the whitespace pass to skip over an empty
C# statement to remove whitespace. This is sound because an empty C#
statement produces no output - we allow removing whitespace before and
after all nodes that produce no output.
\n\nCommit migrated from e68d93f458
This commit is contained in:
parent
14a8159919
commit
7f3a187455
|
|
@ -77,8 +77,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
break;
|
||||
|
||||
case CSharpCodeIntermediateNode codeIntermediateNode:
|
||||
// A C# code node could be empty. We can't remove them, but we can skip them.
|
||||
shouldRemoveNode = false;
|
||||
shouldContinueIteration = ComponentDocumentClassifierPass.IsBuildRenderTreeBaseCall(codeIntermediateNode);
|
||||
shouldContinueIteration =
|
||||
IsEmpty(codeIntermediateNode) ||
|
||||
ComponentDocumentClassifierPass.IsBuildRenderTreeBaseCall(codeIntermediateNode);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -110,5 +113,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
Forwards,
|
||||
Backwards
|
||||
}
|
||||
|
||||
private static bool IsEmpty(CSharpCodeIntermediateNode node)
|
||||
{
|
||||
for (var i = 0; i < node.Children.Count; i++)
|
||||
{
|
||||
if (!(node.Children[i] is IntermediateToken token && string.IsNullOrWhiteSpace(token.Content)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue