Fix a bug with ref and declaration phase

This fixes a regression in the new `@ref` support, where the build will
fail during the declaration pass.

The problem is that the EliminateMethodBodyPass runs really early and
wipes out the usage of `@ref` before we have a chance to see it. The
solution is to make it run really late. This makes sense because we
basically just use this pass to do cleanup.
\n\nCommit migrated from 09b50151ef
This commit is contained in:
Ryan Nowak 2019-07-01 16:39:20 -07:00
parent dbf5b80f97
commit bfbb9a78a2
2 changed files with 17 additions and 2 deletions

View File

@ -8,8 +8,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
{
internal sealed class EliminateMethodBodyPass : IntermediateNodePassBase, IRazorOptimizationPass
{
// Run early in the optimization phase
public override int Order => int.MinValue;
// Run late in the optimization phase
public override int Order => int.MaxValue;
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{

View File

@ -70,6 +70,21 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
Assert.Same(typeof(StringBuilder), property.PropertyType);
}
[Fact]
public void DeclarationConfiguration_IncludesRef()
{
// Arrange & Act
var component = CompileToComponent(@"
@using System.Text
<div @ref=""myDiv"" />
");
// Assert
var field = component.GetType().GetField("myDiv", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(field);
Assert.Same(typeof(ElementRef), field.FieldType);
}
[Fact]
public void DeclarationConfiguration_IncludesInherits()
{