General cleanup of bind code
Removed support for more obsolete cases and cleaned up some out-of-date
comments.
\n\nCommit migrated from 19c6a6fa4b
This commit is contained in:
parent
8d6e13082d
commit
e9ac371854
|
|
@ -282,7 +282,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
||||||
// Skip anything we can't understand. It's important that we don't crash, that will bring down
|
// Skip anything we can't understand. It's important that we don't crash, that will bring down
|
||||||
// the build.
|
// the build.
|
||||||
node.Diagnostics.Add(ComponentDiagnosticFactory.CreateBindAttribute_InvalidSyntax(
|
node.Diagnostics.Add(ComponentDiagnosticFactory.CreateBindAttribute_InvalidSyntax(
|
||||||
node.Source,
|
node.Source,
|
||||||
node.AttributeName));
|
node.AttributeName));
|
||||||
return new[] { node };
|
return new[] { node };
|
||||||
}
|
}
|
||||||
|
|
@ -331,15 +331,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
||||||
|
|
||||||
var valueExpressionTokens = new List<IntermediateToken>();
|
var valueExpressionTokens = new List<IntermediateToken>();
|
||||||
var changeExpressionTokens = new List<IntermediateToken>();
|
var changeExpressionTokens = new List<IntermediateToken>();
|
||||||
|
|
||||||
|
// DOM-based event handlers use EventCallback, so if we see a delegate here it's a component.
|
||||||
if (changeAttribute != null && changeAttribute.IsDelegateProperty())
|
if (changeAttribute != null && changeAttribute.IsDelegateProperty())
|
||||||
{
|
{
|
||||||
RewriteNodesForDelegateBind(
|
RewriteNodesForComponentDelegateBind(
|
||||||
original,
|
original,
|
||||||
format,
|
valueExpressionTokens,
|
||||||
culture,
|
|
||||||
valueAttribute,
|
|
||||||
changeAttribute,
|
|
||||||
valueExpressionTokens,
|
|
||||||
changeExpressionTokens);
|
changeExpressionTokens);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -401,7 +399,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
||||||
changeNode.Children[0].Children.Add(changeExpressionTokens[i]);
|
changeNode.Children[0].Children.Add(changeExpressionTokens[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new[] { valueNode, changeNode };
|
return new[] { valueNode, changeNode };
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -593,111 +591,35 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RewriteNodesForDelegateBind(
|
private void RewriteNodesForComponentDelegateBind(
|
||||||
IntermediateToken original,
|
IntermediateToken original,
|
||||||
IntermediateToken format,
|
List<IntermediateToken> valueExpressionTokens,
|
||||||
IntermediateToken culture,
|
|
||||||
BoundAttributeDescriptor valueAttribute,
|
|
||||||
BoundAttributeDescriptor changeAttribute,
|
|
||||||
List<IntermediateToken> valueExpressionTokens,
|
|
||||||
List<IntermediateToken> changeExpressionTokens)
|
List<IntermediateToken> changeExpressionTokens)
|
||||||
{
|
{
|
||||||
// Now rewrite the content of the value node to look like:
|
// Now rewrite the content of the value node to look like:
|
||||||
//
|
//
|
||||||
// BindMethods.GetValue(<code>) OR
|
// BindMethods.GetValue(<code>)
|
||||||
// BindMethods.GetValue(<code>, <format>)
|
|
||||||
valueExpressionTokens.Add(new IntermediateToken()
|
valueExpressionTokens.Add(new IntermediateToken()
|
||||||
{
|
{
|
||||||
Content = $"{ComponentsApi.BindMethods.GetValue}(",
|
Content = $"{ComponentsApi.BindMethods.GetValue}(",
|
||||||
Kind = TokenKind.CSharp
|
Kind = TokenKind.CSharp
|
||||||
});
|
});
|
||||||
valueExpressionTokens.Add(original);
|
valueExpressionTokens.Add(original);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(format?.Content))
|
|
||||||
{
|
|
||||||
valueExpressionTokens.Add(new IntermediateToken()
|
|
||||||
{
|
|
||||||
Content = ", format: ",
|
|
||||||
Kind = TokenKind.CSharp,
|
|
||||||
});
|
|
||||||
valueExpressionTokens.Add(format);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(culture?.Content))
|
|
||||||
{
|
|
||||||
valueExpressionTokens.Add(new IntermediateToken()
|
|
||||||
{
|
|
||||||
Content = ", culture: ",
|
|
||||||
Kind = TokenKind.CSharp,
|
|
||||||
});
|
|
||||||
valueExpressionTokens.Add(culture);
|
|
||||||
}
|
|
||||||
|
|
||||||
valueExpressionTokens.Add(new IntermediateToken()
|
valueExpressionTokens.Add(new IntermediateToken()
|
||||||
{
|
{
|
||||||
Content = ")",
|
Content = ")",
|
||||||
Kind = TokenKind.CSharp,
|
Kind = TokenKind.CSharp,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Now rewrite the content of the change-handler node. There are two cases we care about
|
// Now rewrite the content of the change-handler node. Since it's a component attribute,
|
||||||
// here. If it's a component attribute, then don't use the 'BindMethods' wrapper. We expect
|
// we don't use the 'BindMethods' wrapper. We expect component attributes to always 'match' on type.
|
||||||
// component attributes to always 'match' on type.
|
|
||||||
//
|
//
|
||||||
// __value => <code> = __value
|
// __value => <code> = __value
|
||||||
//
|
changeExpressionTokens.Add(new IntermediateToken()
|
||||||
// For general DOM attributes, we need to be able to create a delegate that accepts UIEventArgs
|
|
||||||
// so we use BindMethods.SetValueHandler
|
|
||||||
//
|
|
||||||
// BindMethods.SetValueHandler(__value => <code> = __value, <code>) OR
|
|
||||||
// BindMethods.SetValueHandler(__value => <code> = __value, <code>, <format>)
|
|
||||||
//
|
|
||||||
// Note that the linemappings here are applied to the value attribute, not the change attribute.
|
|
||||||
if (changeAttribute == null)
|
|
||||||
{
|
{
|
||||||
changeExpressionTokens.Add(new IntermediateToken()
|
Content = $"__value => {original.Content} = __value",
|
||||||
{
|
Kind = TokenKind.CSharp,
|
||||||
Content = $"{ComponentsApi.BindMethods.SetValueHandler}(__value => {original.Content} = __value",
|
});
|
||||||
Kind = TokenKind.CSharp
|
|
||||||
});
|
|
||||||
changeExpressionTokens.Add(new IntermediateToken()
|
|
||||||
{
|
|
||||||
Content = original.Content,
|
|
||||||
Kind = TokenKind.CSharp
|
|
||||||
});
|
|
||||||
|
|
||||||
if (format != null)
|
|
||||||
{
|
|
||||||
changeExpressionTokens.Add(new IntermediateToken()
|
|
||||||
{
|
|
||||||
Content = $", format: {format.Content}",
|
|
||||||
Kind = TokenKind.CSharp
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (culture != null)
|
|
||||||
{
|
|
||||||
changeExpressionTokens.Add(new IntermediateToken()
|
|
||||||
{
|
|
||||||
Content = $", culture: {culture.Content}",
|
|
||||||
Kind = TokenKind.CSharp
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
changeExpressionTokens.Add(new IntermediateToken()
|
|
||||||
{
|
|
||||||
Content = ")",
|
|
||||||
Kind = TokenKind.CSharp
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Component
|
|
||||||
changeExpressionTokens.Add(new IntermediateToken()
|
|
||||||
{
|
|
||||||
Content = $"__value => {original.Content} = __value",
|
|
||||||
Kind = TokenKind.CSharp
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RewriteNodesForEventCallbackBind(
|
private void RewriteNodesForEventCallbackBind(
|
||||||
|
|
@ -711,8 +633,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
||||||
{
|
{
|
||||||
// Now rewrite the content of the value node to look like:
|
// Now rewrite the content of the value node to look like:
|
||||||
//
|
//
|
||||||
// BindMethods.GetValue(<code>) OR
|
// BindMethods.GetValue(<code>, format: <format>, culture: <culture>)
|
||||||
// BindMethods.GetValue(<code>, <format>)
|
|
||||||
valueExpressionTokens.Add(new IntermediateToken()
|
valueExpressionTokens.Add(new IntermediateToken()
|
||||||
{
|
{
|
||||||
Content = $"{ComponentsApi.BindMethods.GetValue}(",
|
Content = $"{ComponentsApi.BindMethods.GetValue}(",
|
||||||
|
|
@ -760,8 +681,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
||||||
// For general DOM attributes, we need to be able to create a delegate that accepts UIEventArgs
|
// For general DOM attributes, we need to be able to create a delegate that accepts UIEventArgs
|
||||||
// so we use 'CreateBinder'
|
// so we use 'CreateBinder'
|
||||||
//
|
//
|
||||||
// EventCallbackFactory.CreateBinder(this, __value => <code> = __value, <code>) OR
|
// EventCallbackFactory.CreateBinder(this, __value => <code> = __value, <code>, format: <format>, culture: <culture>)
|
||||||
// EventCallbackFactory.CreateBinder(this, __value => <code> = __value, <code>, <format>)
|
|
||||||
//
|
//
|
||||||
// Note that the linemappings here are applied to the value attribute, not the change attribute.
|
// Note that the linemappings here are applied to the value attribute, not the change attribute.
|
||||||
if (changeAttribute == null)
|
if (changeAttribute == null)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue