Skip to content

Fix misported emitCommentsBeforeToken #1562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

jakebailey
Copy link
Member

This PR's order of operations differed from the original Strada code. Fixing it stops the crashes.

I'm not really happy about the fix because it feels like I'm papering over another problem where we are setting positions on a node incorrectly. But this is simply porting the code as it was.

Fixes #1314

@Copilot Copilot AI review requested due to automatic review settings August 11, 2025 23:26
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in the emitCommentsBeforeToken function by reordering operations to match the original TypeScript reference implementation. The fix prevents crashes by ensuring proper order of operations when checking node similarity and skipping trivia.

  • Moved node similarity check before trivia skipping operation
  • Added conditional check to only skip trivia when dealing with similar nodes

startPos := pos
if p.currentSourceFile != nil {
if isSimilarNode && p.currentSourceFile != nil {
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition combines isSimilarNode with the null check for p.currentSourceFile, but this changes the logic from the original code. The original code would skip trivia whenever p.currentSourceFile != nil, regardless of node similarity. This change might cause trivia to not be skipped in cases where it should be, potentially affecting comment positioning.

Suggested change
if isSimilarNode && p.currentSourceFile != nil {
if p.currentSourceFile != nil {

Copilot uses AI. Check for mistakes.

@jakebailey jakebailey marked this pull request as draft August 11, 2025 23:29
@jakebailey
Copy link
Member Author

jakebailey commented Aug 11, 2025

Ugh, no, this doesn't fix it. I must have had an old binary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

panic: runtime error: slice bounds out of range
1 participant