From e104451f79e23b5140d7ef8748d3b99c1734fd59 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Tue, 3 Jan 2017 12:46:56 -0800 Subject: [PATCH] Make SourceSpan public Cleansup SourceSpan and makes it public where its used. --- Razor.sln | 105 +++--------------- ...faultRazorDesignTimeCSharpLoweringPhase.cs | 44 ++++---- .../DefaultRazorIRLoweringPhase.cs | 87 ++++++++------- .../DefaultRazorRuntimeCSharpLoweringPhase.cs | 44 ++++---- ...reallocatedTagHelperHtmlAttributeIRNode.cs | 2 +- .../AddTagHelperHtmlAttributeIRNode.cs | 2 +- .../CSharpAttributeValueIRNode.cs | 3 +- .../Intermediate/CSharpExpressionIRNode.cs | 3 +- .../Intermediate/CSharpStatementIRNode.cs | 2 +- .../Intermediate/CSharpTokenIRNode.cs | 3 +- .../Intermediate/ChecksumIRNode.cs | 3 +- .../Intermediate/ClassDeclarationIRNode.cs | 3 +- .../Intermediate/CreateTagHelperIRNode.cs | 2 +- ...arePreallocatedTagHelperAttributeIRNode.cs | 2 +- ...reallocatedTagHelperHtmlAttributeIRNode.cs | 2 +- .../DeclareTagHelperFieldsIRNode.cs | 2 +- .../Intermediate/DirectiveIRNode.cs | 2 +- .../Intermediate/DirectiveTokenIRNode.cs | 2 +- .../Intermediate/DocumentIRNode.cs | 2 +- .../Intermediate/ExecuteTagHelpersIRNode.cs | 3 +- .../Intermediate/HtmlAttributeIRNode.cs | 3 +- .../Intermediate/HtmlAttributeValueIRNode.cs | 3 +- .../Intermediate/HtmlContentIRNode.cs | 3 +- .../InitializeTagHelperStructureIRNode.cs | 2 +- .../NamespaceDeclarationIRNode.cs | 3 +- .../Intermediate/RazorIRNode.cs | 3 +- .../RazorMethodDeclarationIRNode.cs | 3 +- .../SetPreallocatedTagHelperPropertyIRNode.cs | 2 +- .../SetTagHelperPropertyIRNode.cs | 2 +- .../Intermediate/TagHelperIRNode.cs | 2 +- .../Intermediate/TemplateIRNode.cs | 3 +- .../Intermediate/UsingStatementIRNode.cs | 3 +- .../Legacy/CSharpCodeWriter.cs | 2 +- .../Legacy/LineMapping.cs | 6 +- .../RazorCSharpLoweringPhaseBase.cs | 6 +- .../RazorDesignTimeIRPass.cs | 8 +- .../MappingLocation.cs => SourceSpan.cs} | 56 +++++----- .../LineMappingsSerializer.cs | 4 +- .../IntegrationTests/RazorIRNodeWriter.cs | 6 +- .../Intermediate/DefaultRazorIRBuilderTest.cs | 2 +- .../RazorIRBuilderExtensionsTest.cs | 6 +- .../Intermediate/RazorIRNodeWalkerTest.cs | 3 +- .../Legacy/CSharpCodeWriterTest.cs | 4 +- .../LineMappingTest.cs => SourceSpanTest.cs} | 71 ++++++------ 44 files changed, 217 insertions(+), 307 deletions(-) rename src/Microsoft.AspNetCore.Razor.Evolution/{Legacy/MappingLocation.cs => SourceSpan.cs} (59%) rename test/Microsoft.AspNetCore.Razor.Evolution.Test/{Legacy/LineMappingTest.cs => SourceSpanTest.cs} (54%) diff --git a/Razor.sln b/Razor.sln index d75d12a28b..e5d7f0a150 100644 --- a/Razor.sln +++ b/Razor.sln @@ -1,30 +1,20 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26009.0 +VisualStudioVersion = 15.0.26014.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3C0D6505-79B3-49D0-B4C3-176F0F1836ED}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{92463391-81BE-462B-AC3C-78C6C760741F}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor", "src\Microsoft.AspNetCore.Razor\Microsoft.AspNetCore.Razor.csproj", "{EDA30434-C567-44DC-B8B6-2566A7F77163}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Test", "test\Microsoft.AspNetCore.Razor.Test\Microsoft.AspNetCore.Razor.Test.csproj", "{87C7338B-0C06-4C7B-BE75-A2368AE26797}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Runtime", "src\Microsoft.AspNetCore.Razor.Runtime\Microsoft.AspNetCore.Razor.Runtime.csproj", "{D0196096-1B01-4133-AACE-1A10A0F7247C}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F8C12DD6-659D-405A-AA27-FB22AD92A010}" ProjectSection(SolutionItems) = preProject global.json = global.json NuGet.config = NuGet.config EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorPageGenerator", "src\RazorPageGenerator\RazorPageGenerator.csproj", "{7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Evolution", "src\Microsoft.AspNetCore.Razor.Evolution\Microsoft.AspNetCore.Razor.Evolution.csproj", "{932F3C9C-A6C0-40D3-BA50-9309886242FC}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Evolution.Test", "test\Microsoft.AspNetCore.Razor.Evolution.Test\Microsoft.AspNetCore.Razor.Evolution.Test.csproj", "{969357A4-CCF1-46D9-B002-9AA072AFC75C}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Runtime.Test", "test\Microsoft.AspNetCore.Razor.Runtime.Test\Microsoft.AspNetCore.Razor.Runtime.Test.csproj", "{277AB67E-9C8D-4799-A18C-C628E70A8664}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Evolution.Test", "test\Microsoft.AspNetCore.Razor.Evolution.Test\Microsoft.AspNetCore.Razor.Evolution.Test.csproj", "{9077988C-F1E0-4758-9D0C-FE3A937579E5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -36,54 +26,6 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {EDA30434-C567-44DC-B8B6-2566A7F77163}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EDA30434-C567-44DC-B8B6-2566A7F77163}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EDA30434-C567-44DC-B8B6-2566A7F77163}.Debug|x64.ActiveCfg = Debug|x64 - {EDA30434-C567-44DC-B8B6-2566A7F77163}.Debug|x64.Build.0 = Debug|x64 - {EDA30434-C567-44DC-B8B6-2566A7F77163}.Debug|x86.ActiveCfg = Debug|x86 - {EDA30434-C567-44DC-B8B6-2566A7F77163}.Debug|x86.Build.0 = Debug|x86 - {EDA30434-C567-44DC-B8B6-2566A7F77163}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EDA30434-C567-44DC-B8B6-2566A7F77163}.Release|Any CPU.Build.0 = Release|Any CPU - {EDA30434-C567-44DC-B8B6-2566A7F77163}.Release|x64.ActiveCfg = Release|x64 - {EDA30434-C567-44DC-B8B6-2566A7F77163}.Release|x64.Build.0 = Release|x64 - {EDA30434-C567-44DC-B8B6-2566A7F77163}.Release|x86.ActiveCfg = Release|x86 - {EDA30434-C567-44DC-B8B6-2566A7F77163}.Release|x86.Build.0 = Release|x86 - {87C7338B-0C06-4C7B-BE75-A2368AE26797}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {87C7338B-0C06-4C7B-BE75-A2368AE26797}.Debug|Any CPU.Build.0 = Debug|Any CPU - {87C7338B-0C06-4C7B-BE75-A2368AE26797}.Debug|x64.ActiveCfg = Debug|x64 - {87C7338B-0C06-4C7B-BE75-A2368AE26797}.Debug|x64.Build.0 = Debug|x64 - {87C7338B-0C06-4C7B-BE75-A2368AE26797}.Debug|x86.ActiveCfg = Debug|x86 - {87C7338B-0C06-4C7B-BE75-A2368AE26797}.Debug|x86.Build.0 = Debug|x86 - {87C7338B-0C06-4C7B-BE75-A2368AE26797}.Release|Any CPU.ActiveCfg = Release|Any CPU - {87C7338B-0C06-4C7B-BE75-A2368AE26797}.Release|Any CPU.Build.0 = Release|Any CPU - {87C7338B-0C06-4C7B-BE75-A2368AE26797}.Release|x64.ActiveCfg = Release|x64 - {87C7338B-0C06-4C7B-BE75-A2368AE26797}.Release|x64.Build.0 = Release|x64 - {87C7338B-0C06-4C7B-BE75-A2368AE26797}.Release|x86.ActiveCfg = Release|x86 - {87C7338B-0C06-4C7B-BE75-A2368AE26797}.Release|x86.Build.0 = Release|x86 - {D0196096-1B01-4133-AACE-1A10A0F7247C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D0196096-1B01-4133-AACE-1A10A0F7247C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D0196096-1B01-4133-AACE-1A10A0F7247C}.Debug|x64.ActiveCfg = Debug|x64 - {D0196096-1B01-4133-AACE-1A10A0F7247C}.Debug|x64.Build.0 = Debug|x64 - {D0196096-1B01-4133-AACE-1A10A0F7247C}.Debug|x86.ActiveCfg = Debug|x86 - {D0196096-1B01-4133-AACE-1A10A0F7247C}.Debug|x86.Build.0 = Debug|x86 - {D0196096-1B01-4133-AACE-1A10A0F7247C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D0196096-1B01-4133-AACE-1A10A0F7247C}.Release|Any CPU.Build.0 = Release|Any CPU - {D0196096-1B01-4133-AACE-1A10A0F7247C}.Release|x64.ActiveCfg = Release|x64 - {D0196096-1B01-4133-AACE-1A10A0F7247C}.Release|x64.Build.0 = Release|x64 - {D0196096-1B01-4133-AACE-1A10A0F7247C}.Release|x86.ActiveCfg = Release|x86 - {D0196096-1B01-4133-AACE-1A10A0F7247C}.Release|x86.Build.0 = Release|x86 - {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Debug|x64.ActiveCfg = Debug|x64 - {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Debug|x64.Build.0 = Debug|x64 - {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Debug|x86.ActiveCfg = Debug|x86 - {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Debug|x86.Build.0 = Debug|x86 - {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Release|Any CPU.Build.0 = Release|Any CPU - {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Release|x64.ActiveCfg = Release|x64 - {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Release|x64.Build.0 = Release|x64 - {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Release|x86.ActiveCfg = Release|x86 - {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Release|x86.Build.0 = Release|x86 {932F3C9C-A6C0-40D3-BA50-9309886242FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {932F3C9C-A6C0-40D3-BA50-9309886242FC}.Debug|Any CPU.Build.0 = Debug|Any CPU {932F3C9C-A6C0-40D3-BA50-9309886242FC}.Debug|x64.ActiveCfg = Debug|x64 @@ -96,41 +38,24 @@ Global {932F3C9C-A6C0-40D3-BA50-9309886242FC}.Release|x64.Build.0 = Release|x64 {932F3C9C-A6C0-40D3-BA50-9309886242FC}.Release|x86.ActiveCfg = Release|x86 {932F3C9C-A6C0-40D3-BA50-9309886242FC}.Release|x86.Build.0 = Release|x86 - {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Debug|x64.ActiveCfg = Debug|x64 - {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Debug|x64.Build.0 = Debug|x64 - {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Debug|x86.ActiveCfg = Debug|x86 - {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Debug|x86.Build.0 = Debug|x86 - {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Release|Any CPU.Build.0 = Release|Any CPU - {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Release|x64.ActiveCfg = Release|x64 - {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Release|x64.Build.0 = Release|x64 - {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Release|x86.ActiveCfg = Release|x86 - {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Release|x86.Build.0 = Release|x86 - {277AB67E-9C8D-4799-A18C-C628E70A8664}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {277AB67E-9C8D-4799-A18C-C628E70A8664}.Debug|Any CPU.Build.0 = Debug|Any CPU - {277AB67E-9C8D-4799-A18C-C628E70A8664}.Debug|x64.ActiveCfg = Debug|x64 - {277AB67E-9C8D-4799-A18C-C628E70A8664}.Debug|x64.Build.0 = Debug|x64 - {277AB67E-9C8D-4799-A18C-C628E70A8664}.Debug|x86.ActiveCfg = Debug|x86 - {277AB67E-9C8D-4799-A18C-C628E70A8664}.Debug|x86.Build.0 = Debug|x86 - {277AB67E-9C8D-4799-A18C-C628E70A8664}.Release|Any CPU.ActiveCfg = Release|Any CPU - {277AB67E-9C8D-4799-A18C-C628E70A8664}.Release|Any CPU.Build.0 = Release|Any CPU - {277AB67E-9C8D-4799-A18C-C628E70A8664}.Release|x64.ActiveCfg = Release|x64 - {277AB67E-9C8D-4799-A18C-C628E70A8664}.Release|x64.Build.0 = Release|x64 - {277AB67E-9C8D-4799-A18C-C628E70A8664}.Release|x86.ActiveCfg = Release|x86 - {277AB67E-9C8D-4799-A18C-C628E70A8664}.Release|x86.Build.0 = Release|x86 + {9077988C-F1E0-4758-9D0C-FE3A937579E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9077988C-F1E0-4758-9D0C-FE3A937579E5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9077988C-F1E0-4758-9D0C-FE3A937579E5}.Debug|x64.ActiveCfg = Debug|x64 + {9077988C-F1E0-4758-9D0C-FE3A937579E5}.Debug|x64.Build.0 = Debug|x64 + {9077988C-F1E0-4758-9D0C-FE3A937579E5}.Debug|x86.ActiveCfg = Debug|x86 + {9077988C-F1E0-4758-9D0C-FE3A937579E5}.Debug|x86.Build.0 = Debug|x86 + {9077988C-F1E0-4758-9D0C-FE3A937579E5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9077988C-F1E0-4758-9D0C-FE3A937579E5}.Release|Any CPU.Build.0 = Release|Any CPU + {9077988C-F1E0-4758-9D0C-FE3A937579E5}.Release|x64.ActiveCfg = Release|x64 + {9077988C-F1E0-4758-9D0C-FE3A937579E5}.Release|x64.Build.0 = Release|x64 + {9077988C-F1E0-4758-9D0C-FE3A937579E5}.Release|x86.ActiveCfg = Release|x86 + {9077988C-F1E0-4758-9D0C-FE3A937579E5}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {EDA30434-C567-44DC-B8B6-2566A7F77163} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED} - {87C7338B-0C06-4C7B-BE75-A2368AE26797} = {92463391-81BE-462B-AC3C-78C6C760741F} - {D0196096-1B01-4133-AACE-1A10A0F7247C} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED} - {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED} {932F3C9C-A6C0-40D3-BA50-9309886242FC} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED} - {969357A4-CCF1-46D9-B002-9AA072AFC75C} = {92463391-81BE-462B-AC3C-78C6C760741F} - {277AB67E-9C8D-4799-A18C-C628E70A8664} = {92463391-81BE-462B-AC3C-78C6C760741F} + {9077988C-F1E0-4758-9D0C-FE3A937579E5} = {92463391-81BE-462B-AC3C-78C6C760741F} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorDesignTimeCSharpLoweringPhase.cs b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorDesignTimeCSharpLoweringPhase.cs index 910ffef46b..8982b941e4 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorDesignTimeCSharpLoweringPhase.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorDesignTimeCSharpLoweringPhase.cs @@ -54,11 +54,11 @@ namespace Microsoft.AspNetCore.Razor.Evolution return; } - if (node.SourceRange != null) + if (node.Source != null) { - using (new LinePragmaWriter(Context.Writer, node.SourceRange)) + using (new LinePragmaWriter(Context.Writer, node.Source.Value)) { - var padding = BuildOffsetPadding(RazorDesignTimeIRPass.DesignTimeVariable.Length, node.SourceRange, Context); + var padding = BuildOffsetPadding(RazorDesignTimeIRPass.DesignTimeVariable.Length, node.Source.Value, Context); Context.Writer .Write(padding) @@ -94,11 +94,11 @@ namespace Microsoft.AspNetCore.Razor.Evolution public override void VisitCSharpStatement(CSharpStatementIRNode node) { - if (node.SourceRange != null) + if (node.Source != null) { - using (new LinePragmaWriter(Context.Writer, node.SourceRange)) + using (new LinePragmaWriter(Context.Writer, node.Source.Value)) { - var padding = BuildOffsetPadding(0, node.SourceRange, Context); + var padding = BuildOffsetPadding(0, node.Source.Value, Context); Context.Writer.Write(padding); AddLineMappingFor(node); @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution const string TypeHelper = "__typeHelper"; var tokenKind = node.Descriptor.Kind; - if (node.SourceRange == null || node.Descriptor.Kind == DirectiveTokenKind.Literal) + if (node.Source == null || node.Descriptor.Kind == DirectiveTokenKind.Literal) { return; } @@ -268,10 +268,10 @@ namespace Microsoft.AspNetCore.Razor.Evolution } else { - var firstMappedChild = node.Children.FirstOrDefault(child => child.SourceRange != null) as RazorIRNode; - var valueStart = firstMappedChild?.SourceRange; + var firstMappedChild = node.Children.FirstOrDefault(child => child.Source != null) as RazorIRNode; + var valueStart = firstMappedChild?.Source; - using (new LinePragmaWriter(Context.Writer, node.SourceRange)) + using (new LinePragmaWriter(Context.Writer, node.Source.Value)) { var assignmentPrefixLength = propertyValueAccessor.Length + " = ".Length; if (node.Descriptor.IsEnum && @@ -282,7 +282,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution if (valueStart != null) { - var padding = BuildOffsetPadding(assignmentPrefixLength, node.SourceRange, Context); + var padding = BuildOffsetPadding(assignmentPrefixLength, node.Source.Value, Context); Context.Writer.Write(padding); } @@ -297,7 +297,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution { if (valueStart != null) { - var padding = BuildOffsetPadding(assignmentPrefixLength, node.SourceRange, Context); + var padding = BuildOffsetPadding(assignmentPrefixLength, node.Source.Value, Context); Context.Writer.Write(padding); } @@ -305,7 +305,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution Context.Writer.WriteStartAssignment(propertyValueAccessor); } - RenderTagHelperAttributeInline(node, node.SourceRange); + RenderTagHelperAttributeInline(node, node.Source.Value); Context.Writer.WriteLine(";"); } @@ -328,8 +328,8 @@ namespace Microsoft.AspNetCore.Razor.Evolution private void AddLineMappingFor(RazorIRNode node) { - var sourceLocation = node.SourceRange; - var generatedLocation = new MappingLocation(Context.Writer.GetCurrentSourceLocation(), node.SourceRange.ContentLength); + var sourceLocation = node.Source.Value; + var generatedLocation = new SourceSpan(Context.Writer.GetCurrentSourceLocation(), sourceLocation.Length); var lineMapping = new LineMapping(sourceLocation, generatedLocation); Context.LineMappings.Add(lineMapping); @@ -337,7 +337,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution private void RenderTagHelperAttributeInline( RazorIRNode node, - MappingLocation documentLocation) + SourceSpan documentLocation) { if (node is SetTagHelperPropertyIRNode || node is CSharpExpressionIRNode) { @@ -348,7 +348,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution } else if (node is HtmlContentIRNode) { - if (node.SourceRange != null) + if (node.Source != null) { AddLineMappingFor(node); } @@ -357,7 +357,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution } else if (node is CSharpTokenIRNode) { - if (node.SourceRange != null) + if (node.Source != null) { AddLineMappingFor(node); } @@ -367,17 +367,17 @@ namespace Microsoft.AspNetCore.Razor.Evolution else if (node is CSharpStatementIRNode) { Context.ErrorSink.OnError( - new SourceLocation(documentLocation.AbsoluteIndex, documentLocation.CharacterIndex, documentLocation.ContentLength), + new SourceLocation(documentLocation.AbsoluteIndex, documentLocation.CharacterIndex, documentLocation.Length), LegacyResources.TagHelpers_CodeBlocks_NotSupported_InAttributes, - documentLocation.ContentLength); + documentLocation.Length); } else if (node is TemplateIRNode) { var attributeValueNode = (SetTagHelperPropertyIRNode)node.Parent; Context.ErrorSink.OnError( - new SourceLocation(documentLocation.AbsoluteIndex, documentLocation.CharacterIndex, documentLocation.ContentLength), + new SourceLocation(documentLocation.AbsoluteIndex, documentLocation.CharacterIndex, documentLocation.Length), LegacyResources.FormatTagHelpers_InlineMarkupBlocks_NotSupported_InAttributes(attributeValueNode.Descriptor.TypeName), - documentLocation.ContentLength); + documentLocation.Length); } } } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorIRLoweringPhase.cs b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorIRLoweringPhase.cs index 3af0b9543b..ba397fd859 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorIRLoweringPhase.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorIRLoweringPhase.cs @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution Name = chunkGenerator.Name, Prefix = chunkGenerator.Prefix, Suffix = chunkGenerator.Suffix, - SourceRange = BuildSourceRangeFromNode(block), + Source = BuildSourceRangeFromNode(block), }); } @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution Builder.Push(new CSharpAttributeValueIRNode() { Prefix = chunkGenerator.Prefix, - SourceRange = BuildSourceRangeFromNode(block), + Source = BuildSourceRangeFromNode(block), }); } @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution { Prefix = chunkGenerator.Prefix, Content = chunkGenerator.Value, - SourceRange = BuildSourceRangeFromNode(span), + Source = BuildSourceRangeFromNode(span), }); } @@ -125,19 +125,19 @@ namespace Microsoft.AspNetCore.Razor.Evolution { var sourceRangeStart = templateNode .Children - .FirstOrDefault(child => child.SourceRange != null) - ?.SourceRange; + .FirstOrDefault(child => child.Source != null) + ?.Source; if (sourceRangeStart != null) { - var contentLength = templateNode.Children.Sum(child => child.SourceRange?.ContentLength ?? 0); + var contentLength = templateNode.Children.Sum(child => child.Source?.Length ?? 0); - templateNode.SourceRange = new MappingLocation( - sourceRangeStart.AbsoluteIndex, - sourceRangeStart.LineIndex, - sourceRangeStart.CharacterIndex, - contentLength, - sourceRangeStart.FilePath ?? _codeDocument.Source.Filename); + templateNode.Source = new SourceSpan( + sourceRangeStart.Value.FilePath ?? _codeDocument.Source.Filename, + sourceRangeStart.Value.AbsoluteIndex, + sourceRangeStart.Value.LineIndex, + sourceRangeStart.Value.CharacterIndex, + contentLength); } } } @@ -161,19 +161,19 @@ namespace Microsoft.AspNetCore.Razor.Evolution { var sourceRangeStart = expressionNode .Children - .FirstOrDefault(child => child.SourceRange != null) - ?.SourceRange; + .FirstOrDefault(child => child.Source != null) + ?.Source; if (sourceRangeStart != null) { - var contentLength = expressionNode.Children.Sum(child => child.SourceRange?.ContentLength ?? 0); + var contentLength = expressionNode.Children.Sum(child => child.Source?.Length ?? 0); - expressionNode.SourceRange = new MappingLocation( - sourceRangeStart.AbsoluteIndex, - sourceRangeStart.LineIndex, - sourceRangeStart.CharacterIndex, - contentLength, - sourceRangeStart.FilePath ?? _codeDocument.Source.Filename); + expressionNode.Source = new SourceSpan( + sourceRangeStart.Value.FilePath ?? _codeDocument.Source.Filename, + sourceRangeStart.Value.AbsoluteIndex, + sourceRangeStart.Value.LineIndex, + sourceRangeStart.Value.CharacterIndex, + contentLength); } } } @@ -195,7 +195,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution Builder.Add(new CSharpTokenIRNode() { Content = span.Content, - SourceRange = BuildSourceRangeFromNode(span), + Source = BuildSourceRangeFromNode(span), }); } @@ -204,7 +204,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution Builder.Add(new CSharpStatementIRNode() { Content = span.Content, - SourceRange = BuildSourceRangeFromNode(span), + Source = BuildSourceRangeFromNode(span), }); } @@ -227,19 +227,25 @@ namespace Microsoft.AspNetCore.Razor.Evolution { var existingHtmlContent = (HtmlContentIRNode)currentChildren[currentChildren.Count - 1]; existingHtmlContent.Content = string.Concat(existingHtmlContent.Content, span.Content); - existingHtmlContent.SourceRange = new MappingLocation( - existingHtmlContent.SourceRange.AbsoluteIndex, - existingHtmlContent.SourceRange.LineIndex, - existingHtmlContent.SourceRange.CharacterIndex, - existingHtmlContent.SourceRange.ContentLength + span.Content.Length, - existingHtmlContent.SourceRange.FilePath); + + if (existingHtmlContent.Source != null) + { + var contentLength = existingHtmlContent.Source.Value.Length + span.Content.Length; + + existingHtmlContent.Source = new SourceSpan( + existingHtmlContent.Source.Value.FilePath ?? _codeDocument.Source.Filename, + existingHtmlContent.Source.Value.AbsoluteIndex, + existingHtmlContent.Source.Value.LineIndex, + existingHtmlContent.Source.Value.CharacterIndex, + contentLength); + } } else { Builder.Add(new HtmlContentIRNode() { Content = span.Content, - SourceRange = BuildSourceRangeFromNode(span), + Source = BuildSourceRangeFromNode(span), }); } } @@ -254,7 +260,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution Builder.Add(new UsingStatementIRNode() { Content = namespaceImport, - SourceRange = BuildSourceRangeFromNode(span), + Source = BuildSourceRangeFromNode(span), }); } } @@ -265,7 +271,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution { Content = span.Content, Descriptor = chunkGenerator.Descriptor, - SourceRange = BuildSourceRangeFromNode(span), + Source = BuildSourceRangeFromNode(span), }); } @@ -388,7 +394,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution TagHelperTypeName = associatedDescriptor.TypeName, Descriptor = associatedAttributeDescriptor, ValueStyle = attribute.ValueStyle, - SourceRange = BuildSourceRangeFromNode(attributeValueNode) + Source = BuildSourceRangeFromNode(attributeValueNode) }; Builder.Push(setTagHelperProperty); @@ -419,16 +425,15 @@ namespace Microsoft.AspNetCore.Razor.Evolution Builder.Add(new ExecuteTagHelpersIRNode()); } - private MappingLocation BuildSourceRangeFromNode(SyntaxTreeNode node) + private SourceSpan BuildSourceRangeFromNode(SyntaxTreeNode node) { var location = node.Start; - var sourceRange = new MappingLocation( - location.AbsoluteIndex, - location.LineIndex, - location.CharacterIndex, - node.Length, - location.FilePath ?? _codeDocument.Source.Filename); - + var sourceRange = new SourceSpan( + node.Start.FilePath ?? _codeDocument.Source.Filename, + node.Start.AbsoluteIndex, + node.Start.LineIndex, + node.Start.CharacterIndex, + node.Length); return sourceRange; } } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorRuntimeCSharpLoweringPhase.cs b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorRuntimeCSharpLoweringPhase.cs index 7c15495152..8c1f5a2150 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorRuntimeCSharpLoweringPhase.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorRuntimeCSharpLoweringPhase.cs @@ -109,10 +109,10 @@ namespace Microsoft.AspNetCore.Razor.Evolution public override void VisitCSharpExpression(CSharpExpressionIRNode node) { IDisposable linePragmaScope = null; - if (node.SourceRange != null) + if (node.Source != null) { - linePragmaScope = new LinePragmaWriter(Context.Writer, node.SourceRange); - var padding = BuildOffsetPadding(Context.RenderingConventions.StartWriteMethod.Length, node.SourceRange, Context); + linePragmaScope = new LinePragmaWriter(Context.Writer, node.Source.Value); + var padding = BuildOffsetPadding(Context.RenderingConventions.StartWriteMethod.Length, node.Source.Value, Context); Context.Writer.Write(padding); } @@ -135,8 +135,8 @@ namespace Microsoft.AspNetCore.Razor.Evolution var valuePieceCount = node .Children .Count(child => child is HtmlAttributeValueIRNode || child is CSharpAttributeValueIRNode); - var prefixLocation = node.SourceRange.AbsoluteIndex; - var suffixLocation = node.SourceRange.AbsoluteIndex + node.SourceRange.ContentLength - node.Suffix.Length; + var prefixLocation = node.Source.Value.AbsoluteIndex; + var suffixLocation = node.Source.Value.AbsoluteIndex + node.Source.Value.Length - node.Suffix.Length; Context.Writer .Write(Context.RenderingConventions.StartBeginWriteAttributeMethod) .WriteStringLiteral(node.Name) @@ -161,9 +161,9 @@ namespace Microsoft.AspNetCore.Razor.Evolution public override void VisitHtmlAttributeValue(HtmlAttributeValueIRNode node) { - var prefixLocation = node.SourceRange.AbsoluteIndex; - var valueLocation = node.SourceRange.AbsoluteIndex + node.Prefix.Length; - var valueLength = node.SourceRange.ContentLength; + var prefixLocation = node.Source.Value.AbsoluteIndex; + var valueLocation = node.Source.Value.AbsoluteIndex + node.Prefix.Length; + var valueLength = node.Source.Value.Length; Context.Writer .Write(Context.RenderingConventions.StartWriteAttributeValueMethod) .WriteStringLiteral(node.Prefix) @@ -185,10 +185,10 @@ namespace Microsoft.AspNetCore.Razor.Evolution const string ValueWriterName = "__razor_attribute_value_writer"; var expressionValue = node.Children.FirstOrDefault() as CSharpExpressionIRNode; - var linePragma = expressionValue != null ? new LinePragmaWriter(Context.Writer, node.SourceRange) : null; - var prefixLocation = node.SourceRange.AbsoluteIndex; - var valueLocation = node.SourceRange.AbsoluteIndex + node.Prefix.Length; - var valueLength = node.SourceRange.ContentLength - node.Prefix.Length; + var linePragma = expressionValue != null ? new LinePragmaWriter(Context.Writer, node.Source.Value) : null; + var prefixLocation = node.Source.Value.AbsoluteIndex; + var valueLocation = node.Source.Value.AbsoluteIndex + node.Prefix.Length; + var valueLength = node.Source.Value.Length - node.Prefix.Length; Context.Writer .Write(Context.RenderingConventions.StartWriteAttributeValueMethod) .WriteStringLiteral(node.Prefix) @@ -237,11 +237,11 @@ namespace Microsoft.AspNetCore.Razor.Evolution return; } - if (node.SourceRange != null) + if (node.Source != null) { - using (new LinePragmaWriter(Context.Writer, node.SourceRange)) + using (new LinePragmaWriter(Context.Writer, node.Source.Value)) { - var padding = BuildOffsetPadding(0, node.SourceRange, Context); + var padding = BuildOffsetPadding(0, node.Source.Value, Context); Context.Writer .Write(padding) .WriteLine(node.Content); @@ -499,7 +499,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution } else { - using (new LinePragmaWriter(Context.Writer, node.SourceRange)) + using (new LinePragmaWriter(Context.Writer, node.Source.Value)) { Context.Writer.WriteStartAssignment(propertyValueAccessor); @@ -513,7 +513,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution .Write("."); } - RenderTagHelperAttributeInline(node, node.SourceRange); + RenderTagHelperAttributeInline(node, node.Source.Value); Context.Writer.WriteLine(";"); } @@ -698,7 +698,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution private void RenderTagHelperAttributeInline( RazorIRNode node, - MappingLocation documentLocation) + SourceSpan documentLocation) { if (node is SetTagHelperPropertyIRNode || node is CSharpExpressionIRNode) { @@ -718,17 +718,17 @@ namespace Microsoft.AspNetCore.Razor.Evolution else if (node is CSharpStatementIRNode) { Context.ErrorSink.OnError( - new SourceLocation(documentLocation.AbsoluteIndex, documentLocation.CharacterIndex, documentLocation.ContentLength), + new SourceLocation(documentLocation.AbsoluteIndex, documentLocation.CharacterIndex, documentLocation.Length), LegacyResources.TagHelpers_CodeBlocks_NotSupported_InAttributes, - documentLocation.ContentLength); + documentLocation.Length); } else if (node is TemplateIRNode) { var attributeValueNode = (SetTagHelperPropertyIRNode)node.Parent; Context.ErrorSink.OnError( - new SourceLocation(documentLocation.AbsoluteIndex, documentLocation.CharacterIndex, documentLocation.ContentLength), + new SourceLocation(documentLocation.AbsoluteIndex, documentLocation.CharacterIndex, documentLocation.Length), LegacyResources.FormatTagHelpers_InlineMarkupBlocks_NotSupported_InAttributes(attributeValueNode.Descriptor.TypeName), - documentLocation.ContentLength); + documentLocation.Length); } } } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/AddPreallocatedTagHelperHtmlAttributeIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/AddPreallocatedTagHelperHtmlAttributeIRNode.cs index 99b36be4c9..f97878be0c 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/AddPreallocatedTagHelperHtmlAttributeIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/AddPreallocatedTagHelperHtmlAttributeIRNode.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string VariableName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/AddTagHelperHtmlAttributeIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/AddTagHelperHtmlAttributeIRNode.cs index 93f81258e9..1a39c0ffe2 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/AddTagHelperHtmlAttributeIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/AddTagHelperHtmlAttributeIRNode.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string Name { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpAttributeValueIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpAttributeValueIRNode.cs index dccb6e084a..367909ab3b 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpAttributeValueIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpAttributeValueIRNode.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate { @@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string Prefix { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpExpressionIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpExpressionIRNode.cs index cf3cda11a9..451ce3f79e 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpExpressionIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpExpressionIRNode.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate { @@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public override void Accept(RazorIRNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpStatementIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpStatementIRNode.cs index 49cfa2c565..24aa23e41f 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpStatementIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpStatementIRNode.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string Content { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpTokenIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpTokenIRNode.cs index 7edd26d0d9..62c6079960 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpTokenIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CSharpTokenIRNode.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate { @@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string Content { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ChecksumIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ChecksumIRNode.cs index afe63378b3..2d02b55b6c 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ChecksumIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ChecksumIRNode.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Security.Cryptography; using System.Text; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate { @@ -14,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string Bytes { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ClassDeclarationIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ClassDeclarationIRNode.cs index 1f5b112242..c580b60673 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ClassDeclarationIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ClassDeclarationIRNode.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate { @@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string AccessModifier { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CreateTagHelperIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CreateTagHelperIRNode.cs index aadb6009c3..aaf3738dc2 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CreateTagHelperIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/CreateTagHelperIRNode.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string TagHelperTypeName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DeclarePreallocatedTagHelperAttributeIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DeclarePreallocatedTagHelperAttributeIRNode.cs index d99b574e51..18cc52d991 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DeclarePreallocatedTagHelperAttributeIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DeclarePreallocatedTagHelperAttributeIRNode.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string VariableName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DeclarePreallocatedTagHelperHtmlAttributeIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DeclarePreallocatedTagHelperHtmlAttributeIRNode.cs index 109b44a32f..c4fc84bf40 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DeclarePreallocatedTagHelperHtmlAttributeIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DeclarePreallocatedTagHelperHtmlAttributeIRNode.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string VariableName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DeclareTagHelperFieldsIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DeclareTagHelperFieldsIRNode.cs index 5d869e9227..bd672cc344 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DeclareTagHelperFieldsIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DeclareTagHelperFieldsIRNode.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public ISet UsedTagHelperTypeNames { get; set; } = new HashSet(StringComparer.Ordinal); diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DirectiveIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DirectiveIRNode.cs index a9a4db3396..e8c399f9e6 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DirectiveIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DirectiveIRNode.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string Name { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DirectiveTokenIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DirectiveTokenIRNode.cs index 7dfdc8e461..e00fbed418 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DirectiveTokenIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DirectiveTokenIRNode.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string Content { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DocumentIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DocumentIRNode.cs index 1ca50c814f..86708cad08 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DocumentIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/DocumentIRNode.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public override void Accept(RazorIRNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ExecuteTagHelpersIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ExecuteTagHelpersIRNode.cs index cd0303c119..74954cd295 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ExecuteTagHelpersIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/ExecuteTagHelpersIRNode.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate { @@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public override void Accept(RazorIRNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/HtmlAttributeIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/HtmlAttributeIRNode.cs index 16bf50b686..9100f43732 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/HtmlAttributeIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/HtmlAttributeIRNode.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate { @@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string Name { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/HtmlAttributeValueIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/HtmlAttributeValueIRNode.cs index fb4ccb18c4..dffb3be22d 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/HtmlAttributeValueIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/HtmlAttributeValueIRNode.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate { @@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string Prefix { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/HtmlContentIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/HtmlContentIRNode.cs index a1797912a8..174a485f02 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/HtmlContentIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/HtmlContentIRNode.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate { @@ -15,7 +14,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public override void Accept(RazorIRNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/InitializeTagHelperStructureIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/InitializeTagHelperStructureIRNode.cs index a1ce6beb9a..faa07e7825 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/InitializeTagHelperStructureIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/InitializeTagHelperStructureIRNode.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string TagName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/NamespaceDeclarationIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/NamespaceDeclarationIRNode.cs index fe6cfad48d..edcaec9402 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/NamespaceDeclarationIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/NamespaceDeclarationIRNode.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate { @@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string Content { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/RazorIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/RazorIRNode.cs index 12458b6d1d..70273510c5 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/RazorIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/RazorIRNode.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate { @@ -14,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public abstract RazorIRNode Parent { get; set; } - internal abstract MappingLocation SourceRange { get; set; } + public abstract SourceSpan? Source { get; set; } public abstract void Accept(RazorIRNodeVisitor visitor); diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/RazorMethodDeclarationIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/RazorMethodDeclarationIRNode.cs index 929fe3a238..61f9e0d6a9 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/RazorMethodDeclarationIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/RazorMethodDeclarationIRNode.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate { @@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string AccessModifier { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/SetPreallocatedTagHelperPropertyIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/SetPreallocatedTagHelperPropertyIRNode.cs index 08c121470e..654e44227a 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/SetPreallocatedTagHelperPropertyIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/SetPreallocatedTagHelperPropertyIRNode.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string VariableName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/SetTagHelperPropertyIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/SetTagHelperPropertyIRNode.cs index 764928543f..c5904d1aac 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/SetTagHelperPropertyIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/SetTagHelperPropertyIRNode.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string TagHelperTypeName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/TagHelperIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/TagHelperIRNode.cs index 933825e23c..67b5e8611f 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/TagHelperIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/TagHelperIRNode.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public override void Accept(RazorIRNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/TemplateIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/TemplateIRNode.cs index 7ade5a9a71..9d2a653cc3 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/TemplateIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/TemplateIRNode.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate { @@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public override void Accept(RazorIRNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/UsingStatementIRNode.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/UsingStatementIRNode.cs index a316ecbb07..fddd53f5fd 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/UsingStatementIRNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Intermediate/UsingStatementIRNode.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate { @@ -13,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public string Content { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/CSharpCodeWriter.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/CSharpCodeWriter.cs index a508043c4b..e136f15375 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/CSharpCodeWriter.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/CSharpCodeWriter.cs @@ -191,7 +191,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy /// The location to generate the line pragma for. /// The file to generate the line pragma for. /// The current instance of . - public CSharpCodeWriter WriteLineNumberDirective(MappingLocation location, string file) + public CSharpCodeWriter WriteLineNumberDirective(SourceSpan location, string file) { if (location.FilePath != null) { diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/LineMapping.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/LineMapping.cs index 3042010f9a..6609eecc12 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/LineMapping.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/LineMapping.cs @@ -8,15 +8,15 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy { internal class LineMapping { - public LineMapping(MappingLocation documentLocation, MappingLocation generatedLocation) + public LineMapping(SourceSpan documentLocation, SourceSpan generatedLocation) { DocumentLocation = documentLocation; GeneratedLocation = generatedLocation; } - public MappingLocation DocumentLocation { get; } + public SourceSpan DocumentLocation { get; } - public MappingLocation GeneratedLocation { get; } + public SourceSpan GeneratedLocation { get; } public override bool Equals(object obj) { diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/RazorCSharpLoweringPhaseBase.cs b/src/Microsoft.AspNetCore.Razor.Evolution/RazorCSharpLoweringPhaseBase.cs index 2cb21a697b..9889f36f3f 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/RazorCSharpLoweringPhaseBase.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/RazorCSharpLoweringPhaseBase.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution } } - protected static int CalculateExpressionPadding(MappingLocation sourceRange, CSharpRenderingContext context) + protected static int CalculateExpressionPadding(SourceSpan sourceRange, CSharpRenderingContext context) { var spaceCount = 0; for (var i = sourceRange.AbsoluteIndex - 1; i >= 0; i--) @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution return spaceCount; } - protected static string BuildOffsetPadding(int generatedOffset, MappingLocation sourceRange, CSharpRenderingContext context) + protected static string BuildOffsetPadding(int generatedOffset, SourceSpan sourceRange, CSharpRenderingContext context) { var basePadding = CalculateExpressionPadding(sourceRange, context); var resolvedPadding = Math.Max(basePadding - generatedOffset, 0); @@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution private readonly CSharpCodeWriter _writer; private readonly int _startIndent; - public LinePragmaWriter(CSharpCodeWriter writer, MappingLocation documentLocation) + public LinePragmaWriter(CSharpCodeWriter writer, SourceSpan documentLocation) { if (writer == null) { diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/RazorDesignTimeIRPass.cs b/src/Microsoft.AspNetCore.Razor.Evolution/RazorDesignTimeIRPass.cs index ab14217498..c1331bfcb6 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/RazorDesignTimeIRPass.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/RazorDesignTimeIRPass.cs @@ -1,10 +1,8 @@ -using System; -using System.Collections.Generic; -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Collections.Generic; using Microsoft.AspNetCore.Razor.Evolution.Intermediate; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution { @@ -84,7 +82,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public void AddToMethodBody(RazorIRNode node) { diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/MappingLocation.cs b/src/Microsoft.AspNetCore.Razor.Evolution/SourceSpan.cs similarity index 59% rename from src/Microsoft.AspNetCore.Razor.Evolution/Legacy/MappingLocation.cs rename to src/Microsoft.AspNetCore.Razor.Evolution/SourceSpan.cs index 15e1d62f24..f8ae0c346f 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/MappingLocation.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/SourceSpan.cs @@ -5,29 +5,25 @@ using System; using System.Globalization; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Razor.Evolution.Legacy +namespace Microsoft.AspNetCore.Razor.Evolution { - internal class MappingLocation + public struct SourceSpan : IEquatable { - public MappingLocation() + public SourceSpan(SourceLocation location, int contentLength) + : this(location.FilePath, location.AbsoluteIndex, location.LineIndex, location.CharacterIndex, contentLength) { } - public MappingLocation(SourceLocation location, int contentLength) - : this (location.AbsoluteIndex, location.LineIndex, location.CharacterIndex, contentLength, location.FilePath) - { - } - - public MappingLocation(int absoluteIndex, int lineIndex, int characterIndex, int contentLength, string filePath) + public SourceSpan(string filePath, int absoluteIndex, int lineIndex, int characterIndex, int length) { AbsoluteIndex = absoluteIndex; LineIndex = lineIndex; CharacterIndex = characterIndex; - ContentLength = contentLength; + Length = length; FilePath = filePath; } - public int ContentLength { get; } + public int Length { get; } public int AbsoluteIndex { get; } @@ -37,31 +33,37 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy public string FilePath { get; } + public bool Equals(SourceSpan other) + { + return + string.Equals(FilePath, other.FilePath, StringComparison.Ordinal) && + AbsoluteIndex == other.AbsoluteIndex && + LineIndex == other.LineIndex && + CharacterIndex == other.CharacterIndex && + Length == other.Length; + } + public override bool Equals(object obj) { - var other = obj as MappingLocation; + var other = obj as SourceSpan?; if (ReferenceEquals(other, null)) { return false; } - return string.Equals(FilePath, other.FilePath, StringComparison.Ordinal) && - AbsoluteIndex == other.AbsoluteIndex && - ContentLength == other.ContentLength && - LineIndex == other.LineIndex && - CharacterIndex == other.CharacterIndex; + return Equals(other.Value); } public override int GetHashCode() { - var hashCodeCombiner = HashCodeCombiner.Start(); - hashCodeCombiner.Add(FilePath, StringComparer.Ordinal); - hashCodeCombiner.Add(AbsoluteIndex); - hashCodeCombiner.Add(ContentLength); - hashCodeCombiner.Add(LineIndex); - hashCodeCombiner.Add(CharacterIndex); + var hash = HashCodeCombiner.Start(); + hash.Add(FilePath, StringComparer.Ordinal); + hash.Add(AbsoluteIndex); + hash.Add(LineIndex); + hash.Add(CharacterIndex); + hash.Add(Length); - return hashCodeCombiner; + return hash; } public override string ToString() @@ -71,11 +73,11 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy AbsoluteIndex, LineIndex, CharacterIndex, - ContentLength, + Length, FilePath); } - public static bool operator ==(MappingLocation left, MappingLocation right) + public static bool operator ==(SourceSpan left, SourceSpan right) { if (ReferenceEquals(left, right)) { @@ -91,7 +93,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy return left.Equals(right); } - public static bool operator !=(MappingLocation left, MappingLocation right) + public static bool operator !=(SourceSpan left, SourceSpan right) { if (ReferenceEquals(left, right)) { diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/LineMappingsSerializer.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/LineMappingsSerializer.cs index 5e70d58498..38754fc75e 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/LineMappingsSerializer.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/LineMappingsSerializer.cs @@ -31,13 +31,13 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests return builder.ToString(); } - private static void AppendMappingLocation(StringBuilder builder, MappingLocation location, string content) + private static void AppendMappingLocation(StringBuilder builder, SourceSpan location, string content) { builder .AppendLine(location.ToString()) .Append("|"); - for (var i = 0; i < location.ContentLength; i++) + for (var i = 0; i < location.Length; i++) { builder.Append(content[location.AbsoluteIndex + i]); } diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/RazorIRNodeWriter.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/RazorIRNodeWriter.cs index 8169ac1ca5..01174cf97e 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/RazorIRNodeWriter.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/RazorIRNodeWriter.cs @@ -190,9 +190,9 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests protected void WriteSourceRange(RazorIRNode node) { - if (node.SourceRange != null) + if (node.Source != null) { - var sourceRange = node.SourceRange; + var sourceRange = node.Source.Value; _writer.Write("("); _writer.Write(sourceRange.AbsoluteIndex); _writer.Write(":"); @@ -200,7 +200,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests _writer.Write(","); _writer.Write(sourceRange.CharacterIndex); _writer.Write(" ["); - _writer.Write(sourceRange.ContentLength); + _writer.Write(sourceRange.Length); _writer.Write("] "); var fileName = sourceRange.FilePath.Substring(sourceRange.FilePath.LastIndexOf('/') + 1); diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Intermediate/DefaultRazorIRBuilderTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Intermediate/DefaultRazorIRBuilderTest.cs index 626a15557d..c6caea00d6 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Intermediate/DefaultRazorIRBuilderTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Intermediate/DefaultRazorIRBuilderTest.cs @@ -218,7 +218,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public override void Accept(RazorIRNodeVisitor visitor) { diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Intermediate/RazorIRBuilderExtensionsTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Intermediate/RazorIRBuilderExtensionsTest.cs index 617c5d96ab..ed9fc86802 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Intermediate/RazorIRBuilderExtensionsTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Intermediate/RazorIRBuilderExtensionsTest.cs @@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public override void Accept(RazorIRNodeVisitor visitor) { @@ -97,7 +97,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public override void Accept(RazorIRNodeVisitor visitor) { @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public override void Accept(RazorIRNodeVisitor visitor) { diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Intermediate/RazorIRNodeWalkerTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Intermediate/RazorIRNodeWalkerTest.cs index 07234da8b8..87c68e194b 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Intermediate/RazorIRNodeWalkerTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Intermediate/RazorIRNodeWalkerTest.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; using Xunit; namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate @@ -75,7 +74,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate public override RazorIRNode Parent { get; set; } - internal override MappingLocation SourceRange { get; set; } + public override SourceSpan? Source { get; set; } public override void Accept(RazorIRNodeVisitor visitor) { diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/CSharpCodeWriterTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/CSharpCodeWriterTest.cs index 5dbf4b9221..bd3e8f507f 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/CSharpCodeWriterTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/CSharpCodeWriterTest.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy var writer = new CSharpCodeWriter(); var expected = $"#line 5 \"{filePath}\"" + writer.NewLine; var sourceLocation = new SourceLocation(10, 4, 3); - var mappingLocation = new MappingLocation(sourceLocation, 9); + var mappingLocation = new SourceSpan(sourceLocation, 9); // Act writer.WriteLineNumberDirective(mappingLocation, filePath); @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy var writer = new CSharpCodeWriter(); var expected = $"#line 5 \"{sourceLocationFilePath}\"" + writer.NewLine; var sourceLocation = new SourceLocation(sourceLocationFilePath, 10, 4, 3); - var mappingLocation = new MappingLocation(sourceLocation, 9); + var mappingLocation = new SourceSpan(sourceLocation, 9); // Act writer.WriteLineNumberDirective(mappingLocation, filePath); diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/LineMappingTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/SourceSpanTest.cs similarity index 54% rename from test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/LineMappingTest.cs rename to test/Microsoft.AspNetCore.Razor.Evolution.Test/SourceSpanTest.cs index e293e6064b..fe2c967a2c 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/LineMappingTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/SourceSpanTest.cs @@ -2,23 +2,23 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Xunit; +using Microsoft.AspNetCore.Razor.Evolution.Legacy; -namespace Microsoft.AspNetCore.Razor.Evolution.Legacy +namespace Microsoft.AspNetCore.Razor.Evolution { - public class LineMappingTest + public class SourceSpanTest { [Fact] public void GeneratedCodeMappingsAreEqualIfDataIsEqual() { // Arrange var left = new LineMapping( - new MappingLocation(new SourceLocation(1, 2, 3), 4), - new MappingLocation(new SourceLocation(5, 6, 7), 8) - ); + new SourceSpan(new SourceLocation(1, 2, 3), 4), + new SourceSpan(new SourceLocation(5, 6, 7), 8)); + var right = new LineMapping( - new MappingLocation(new SourceLocation(1, 2, 3), 4), - new MappingLocation(new SourceLocation(5, 6, 7), 8) - ); + new SourceSpan(new SourceLocation(1, 2, 3), 4), + new SourceSpan(new SourceLocation(5, 6, 7), 8)); // Assert Assert.True(left == right); @@ -32,13 +32,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy { // Arrange var left = new LineMapping( - new MappingLocation(new SourceLocation(1, 2, 3), 4), - new MappingLocation(new SourceLocation(5, 6, 7), 8) - ); + new SourceSpan(new SourceLocation(1, 2, 3), 4), + new SourceSpan(new SourceLocation(5, 6, 7), 8)); + var right = new LineMapping( - new MappingLocation(new SourceLocation(1, 2, 3), 5), - new MappingLocation(new SourceLocation(5, 6, 7), 9) - ); + new SourceSpan(new SourceLocation(1, 2, 3), 5), + new SourceSpan(new SourceLocation(5, 6, 7), 9)); // Assert AssertNotEqual(left, right); @@ -49,13 +48,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy { // Arrange var left = new LineMapping( - new MappingLocation(new SourceLocation(1, 2, 3), 4), - new MappingLocation(new SourceLocation(5, 6, 7), 8) - ); + new SourceSpan(new SourceLocation(1, 2, 3), 4), + new SourceSpan(new SourceLocation(5, 6, 7), 8)); + var right = new LineMapping( - new MappingLocation(new SourceLocation(1, 2, 3), 4), - new MappingLocation(new SourceLocation(5, 6, 8), 8) - ); + new SourceSpan(new SourceLocation(1, 2, 3), 4), + new SourceSpan(new SourceLocation(5, 6, 8), 8)); // Assert AssertNotEqual(left, right); @@ -66,13 +64,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy { // Arrange var left = new LineMapping( - new MappingLocation(new SourceLocation(1, 2, 3), 4), - new MappingLocation(new SourceLocation(5, 6, 8), 8) - ); + new SourceSpan(new SourceLocation(1, 2, 3), 4), + new SourceSpan(new SourceLocation(5, 6, 8), 8)); + var right = new LineMapping( - new MappingLocation(new SourceLocation(1, 2, 3), 4), - new MappingLocation(new SourceLocation(5, 6, 7), 8) - ); + new SourceSpan(new SourceLocation(1, 2, 3), 4), + new SourceSpan(new SourceLocation(5, 6, 7), 8)); // Assert AssertNotEqual(left, right); @@ -83,13 +80,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy { // Arrange var left = new LineMapping( - new MappingLocation(new SourceLocation(1, 2, 3), 4), - new MappingLocation(new SourceLocation(5, 5, 7), 8) - ); + new SourceSpan(new SourceLocation(1, 2, 3), 4), + new SourceSpan(new SourceLocation(5, 5, 7), 8)); + var right = new LineMapping( - new MappingLocation(new SourceLocation(1, 1, 3), 4), - new MappingLocation(new SourceLocation(5, 6, 7), 8) - ); + new SourceSpan(new SourceLocation(1, 1, 3), 4), + new SourceSpan(new SourceLocation(5, 6, 7), 8)); // Assert AssertNotEqual(left, right); @@ -100,13 +96,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy { // Arrange var left = new LineMapping( - new MappingLocation(new SourceLocation(1, 2, 3), 4), - new MappingLocation(new SourceLocation(4, 6, 7), 8) - ); + new SourceSpan(new SourceLocation(1, 2, 3), 4), + new SourceSpan(new SourceLocation(4, 6, 7), 8)); + var right = new LineMapping( - new MappingLocation(new SourceLocation(1, 2, 3), 4), - new MappingLocation(new SourceLocation(5, 6, 7), 9) - ); + new SourceSpan(new SourceLocation(1, 2, 3), 4), + new SourceSpan(new SourceLocation(5, 6, 7), 9)); // Assert AssertNotEqual(left, right);