Fix panic when @this JSDoc tag is combined with a literal this parameter#3925
Merged
DanielRosenwasser merged 2 commits intoMay 18, 2026
Merged
Conversation
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
jakebailey
approved these changes
May 16, 2026
Contributor
There was a problem hiding this comment.
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’sJSDocThisTaghandling to treatIdentifier("this")as an existingthisparameter (viaast.IsThisIdentifier), not justKindThisKeyword. - Add a new compiler test case covering
/** @this {object} */ function f(this) {}undercheckJs. - 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
approved these changes
May 18, 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.
tsgopanics on/** @this {object} */ function f(this) {}because the reparser fails to detect the existingthisparameter and prepends a duplicate synthetic one, producing a diagnostic with position -1.The check
params[0].Name().Kind != ast.KindThisKeywordmisses the case where the parser creates thethisparameter name as aKindIdentifierwith text"this"(viacreateIdentifier), not as aKindThisKeywordnode.ast.IsThisIdentifier()check to the existing condition inreparseHostedto cover both node kindsjsdocThisTagWithThisParameter