fix: twoslash @link comments skipped when multiple appear consecutively#52
Open
tsushanth wants to merge 1 commit into
Open
fix: twoslash @link comments skipped when multiple appear consecutively#52tsushanth wants to merge 1 commit into
tsushanth wants to merge 1 commit into
Conversation
…comments When multiple consecutive // @link comment lines appear in a twoslash code block, the previous loop used splice(i, 1) while iterating with .entries(). After each removal, subsequent elements shift down by one index, so the iterator skips the next element. This causes alternating @link lines to be silently ignored — neither removed from the rendered code nor registered in the linkMap. Replace the mutate-in-place loop with a single filter pass that collects links and strips comment lines in one traversal.
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.
Problem
In
rehypeSyntaxHighlighting.ts, the loop that strips// @linkcomment lines from twoslash code blocks mutates the array while iterating over it with.entries():After
splice(i, 1), the element that was at indexi+1shifts toi, but the iterator advances toi+1on the next tick — skipping it. The result: when two or more consecutive lines are// @linkcomments, every second one is silently dropped. The skipped line stays in the rendered code output as a visible comment and its link is never added tolinkMap, so the hover popup won't contain a link for that token.Example that triggers the bug — the second
@linkis silently ignored:Fix
Replace the mutate-in-place loop with a single
filterpass that collects links and strips comment lines in one traversal, avoiding the off-by-one from in-place removal.