Conversation
Agent-Logs-Url: https://github.com/dotnet/razor/sessions/12930d00-85fa-458f-8e7b-720aa26f3454 Co-authored-by: chsienki <16246502+chsienki@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Extract shared helpers for source span merging and duplicated resolution logic
Extract MergeSourceSpans helper and deduplicate condition branches in tag helper resolution phase
Apr 3, 2026
Agent-Logs-Url: https://github.com/dotnet/razor/sessions/25acbb13-48b6-4614-a78d-69886fbbc90b Co-authored-by: chsienki <16246502+chsienki@users.noreply.github.com>
davidwengier
approved these changes
Apr 13, 2026
This was referenced Apr 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
DefaultTagHelperResolutionPhaseand its partial-class companions (ComponentTagHelperResolver,LegacyTagHelperResolver) each had several places that manually constructed a mergedSourceSpanby inlining the same arithmetic — computing an end absolute index, subtracting the start, etc. This duplication was:lineCountformula (last.LineIndex - first.LineIndex + 1vs.last.LineIndex + last.LineCount - first.LineIndex), making it hard to know which was correct.firstmust start at or beforelast.Similarly,
ConvertPureCSharpExpressionValueandComputeValueSourceeach had duplicate condition arms calling the sameUnwrapValueChildrenToTokensfallback, andGetAttributeSourcehad two identical loops over token children forHtmlAttributeValueIntermediateNodeandCSharpExpressionAttributeValueIntermediateNode.What
MergeSourceSpans(first, last): a single, documentedinternal statichelper that merges two orderedSourceSpanvalues into one covering span, using the correct formula forlength,lineCount, andendCharacterIndex. Replaces all six inline span-merge expressions across the three resolver files.Debug.Assert: enforces the precondition thatfirst.AbsoluteIndex <= last.AbsoluteIndex, catching ordering bugs immediately in debug builds.UnwrapValueChildrenToTokensfallback arms inComputeValueSource(bound-string + dynamic vs. complex/non-dynamic) into a singleelsebranch.elsechains inConvertPureCSharpExpressionValue, using an earlyreturnso theUnwrapValueChildrenToTokensfallback only appears once.GetAttributeSourceforHtmlAttributeValueIntermediateNodeandCSharpExpressionAttributeValueIntermediateNodeinto a single pattern-match branch.DefaultTagHelperResolutionPhaseTest.cs): 5 tests covering theMergeSourceSpanshelper — same-line merge, multi-line merge, adjacent spans, identical span passed for both arguments, and null file path preservation.