Skip to content

Fix panic when @this JSDoc tag is combined with a literal this parameter#3925

Merged
DanielRosenwasser merged 2 commits into
mainfrom
copilot/fix-tsgo-panics-javadoc-this-tag
May 18, 2026
Merged

Fix panic when @this JSDoc tag is combined with a literal this parameter#3925
DanielRosenwasser merged 2 commits into
mainfrom
copilot/fix-tsgo-panics-javadoc-this-tag

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 16, 2026

tsgo panics on /** @this {object} */ function f(this) {} because the reparser fails to detect the existing this parameter and prepends a duplicate synthetic one, producing a diagnostic with position -1.

The check params[0].Name().Kind != ast.KindThisKeyword misses the case where the parser creates the this parameter name as a KindIdentifier with text "this" (via createIdentifier), not as a KindThisKeyword node.

  • Added ast.IsThisIdentifier() check to the existing condition in reparseHosted to cover both node kinds
  • Added compiler test case jsdocThisTagWithThisParameter

The reparser checks if the first parameter is already a 'this' parameter
before prepending a synthetic one from the @this JSDoc tag. The check
only looked for KindThisKeyword, but the parser creates an Identifier
node with text "this". Added IsThisIdentifier check to cover both cases.

Fixes #1325

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/46167b5d-5160-44fe-ae7f-01e2f77e8438

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix tsgo panics with @this JSDoc tag and literal this parameter Fix panic when @this JSDoc tag is combined with a literal this parameter May 16, 2026
Copilot AI requested a review from jakebailey May 16, 2026 20:13
@jakebailey jakebailey marked this pull request as ready for review May 16, 2026 20:43
Copilot AI review requested due to automatic review settings May 16, 2026 20:43
Copy link
Copy Markdown
Contributor

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

Prevents a tsgo panic when a @this JSDoc tag appears on a function that already has a literal this parameter whose name node is represented as an Identifier("this") rather than a ThisKeyword, by ensuring the reparser recognizes both forms and avoids prepending a duplicate synthetic this parameter. Adds a compiler regression test and reference baselines to lock in the non-crashing behavior and diagnostics.

Changes:

  • Teach Parser.reparseHosted’s JSDocThisTag handling to treat Identifier("this") as an existing this parameter (via ast.IsThisIdentifier), not just KindThisKeyword.
  • Add a new compiler test case covering /** @this {object} */ function f(this) {} under checkJs.
  • Add reference baselines (.types, .symbols, .errors.txt) for the new test.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/parser/reparser.go Avoids inserting a duplicate synthetic this parameter by also recognizing Identifier("this") names.
testdata/tests/cases/compiler/jsdocThisTagWithThisParameter.ts New regression test reproducing the crash scenario in a JS file under checkJs.
testdata/baselines/reference/compiler/jsdocThisTagWithThisParameter.types Records expected type output for the new test.
testdata/baselines/reference/compiler/jsdocThisTagWithThisParameter.symbols Records expected symbol output for the new test.
testdata/baselines/reference/compiler/jsdocThisTagWithThisParameter.errors.txt Records expected diagnostic output for the new test.

@DanielRosenwasser DanielRosenwasser added this pull request to the merge queue May 18, 2026
Merged via the queue into main with commit f3911d2 May 18, 2026
25 checks passed
@DanielRosenwasser DanielRosenwasser deleted the copilot/fix-tsgo-panics-javadoc-this-tag branch May 18, 2026 05:24
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.

tsgo panics when a @this JSDoc tag is combined with a literal this parameter

4 participants