Skip to content

fix: skip reparsed JSDoc nodes in GetChildren to prevent token cache panic#508

Merged
fansenze merged 1 commit intomainfrom
fix/skip-reparsed-nodes-in-get-children-20260317
Mar 17, 2026
Merged

fix: skip reparsed JSDoc nodes in GetChildren to prevent token cache panic#508
fansenze merged 1 commit intomainfrom
fix/skip-reparsed-nodes-in-get-children-20260317

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

Summary

  • Fix crash (panic) when linting JavaScript files that contain JSDoc type annotations (@type, @satisfies, @param, @typedef, @callback, @overload, etc.)
  • Root cause: GetChildren did not filter out NodeFlagsReparsed nodes created by the parser's JSDoc reparsing. These reparsed nodes have positions pointing into the JSDoc comment range rather than the actual code range, causing the gap-filling scanner to produce overlapping tokens with different parents, which triggers a Token cache mismatch: parent panic in GetOrCreateToken
  • Fix: skip children with NodeFlagsReparsed flag in GetChildren, consistent with how upstream typescript-go handles them in astnav/tokens.go and ls/lsutil/children.go

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug causing a panic in the linter when processing JavaScript files that utilize JSDoc type annotations. The core issue stemmed from the GetChildren utility function incorrectly handling reparsed JSDoc nodes, leading to inconsistencies in the token cache. The solution involves modifying GetChildren to properly ignore these specific nodes, thereby preventing the crash and ensuring stable linting for JSDoc-annotated code.

Highlights

  • Crash Fix for JSDoc Linting: Resolved a panic that occurred when linting JavaScript files containing various JSDoc type annotations (e.g., @type, @Satisfies, @param).
  • Root Cause Identification: Identified the panic's root cause as GetChildren not filtering NodeFlagsReparsed nodes, which led to overlapping tokens and a "Token cache mismatch: parent" error.
  • Reparsed Node Filtering: Implemented a fix in GetChildren to explicitly skip children with the NodeFlagsReparsed flag, aligning with upstream typescript-go's handling of such nodes.
Changelog
  • internal/utils/get_children_test.go
  • internal/utils/ts_api_utils.go
    • Modified the GetChildren function to introduce a check for NodeFlagsReparsed.
    • Ensured that children with the NodeFlagsReparsed flag are skipped to prevent token cache mismatches.
Activity
  • No specific review comments or additional activity have been recorded for this pull request beyond its initial creation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a panic that occurs when linting JavaScript files containing JSDoc type annotations. The fix correctly skips reparsed JSDoc nodes within the GetChildren function by checking for the NodeFlagsReparsed flag, which prevents token cache mismatches. The change is minimal, well-targeted, and is accompanied by a comprehensive new test suite that covers a wide variety of JSDoc use cases, ensuring the fix is robust. The implementation appears correct and effectively resolves the reported issue.

@fansenze fansenze force-pushed the fix/skip-reparsed-nodes-in-get-children-20260317 branch from 09af6fe to a56eb67 Compare March 17, 2026 05:17
@fansenze fansenze requested a review from hardfist March 17, 2026 05:21
…panic (#364)

GetChildren did not filter out NodeFlagsReparsed nodes when collecting
children via ForEachChild. JSDoc annotations (@type, @Satisfies, etc.)
create reparsed nodes whose positions point into JSDoc comment ranges
rather than the actual code range. This caused the gap-filling scanner
to produce tokens overlapping with real code tokens, triggering a
"Token cache mismatch: parent" panic in GetOrCreateToken.

The fix skips reparsed children in GetChildren, consistent with how
the upstream typescript-go handles them in astnav and ls/lsutil.
@fansenze fansenze force-pushed the fix/skip-reparsed-nodes-in-get-children-20260317 branch from a56eb67 to 5070826 Compare March 17, 2026 05:29
@fansenze fansenze merged commit 849a6b3 into main Mar 17, 2026
14 checks passed
@fansenze fansenze deleted the fix/skip-reparsed-nodes-in-get-children-20260317 branch March 17, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crashes on lint after fresh install

2 participants