From bfbb9a78a2e3a1b5983959ac69410156598bf306 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Mon, 1 Jul 2019 16:39:20 -0700 Subject: [PATCH] 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 https://github.com/dotnet/aspnetcore-tooling/commit/09b50151ef3f15ed05f5e8efc68e540a6781704e --- .../src/Extensions/EliminateMethodBodyPass.cs | 4 ++-- .../ComponentDeclarationIntegrationTest.cs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/EliminateMethodBodyPass.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/EliminateMethodBodyPass.cs index 96d336ca72..c14950aae5 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/EliminateMethodBodyPass.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/EliminateMethodBodyPass.cs @@ -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) { diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDeclarationIntegrationTest.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDeclarationIntegrationTest.cs index 25ec85093b..b3e35fd973 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDeclarationIntegrationTest.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDeclarationIntegrationTest.cs @@ -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 +
+"); + + // 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() {