Skip to content

Commit 6a088fb

Browse files
Copilotjakebailey
andauthored
Fix panic when @this tag appears inside @typedef JSDoc comment (#3921)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
1 parent d0382ab commit 6a088fb

5 files changed

Lines changed: 28 additions & 0 deletions

File tree

internal/checker/nodecopy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ func getExistingNodeTreeVisitor(b *NodeBuilderImpl, bound *recoveryBoundary) *as
482482
if node.Kind == ast.KindJSDocTypeLiteral {
483483
var members []*ast.Node
484484
for _, t := range node.AsJSDocTypeLiteral().JSDocPropertyTags {
485+
if t.Kind != ast.KindJSDocPropertyTag && t.Kind != ast.KindJSDocParameterTag {
486+
continue
487+
}
485488
n := t.Name()
486489
var targetName *ast.Node
487490
if ast.IsIdentifier(n) {

internal/parser/reparser.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ func (p *Parser) reparseJSDocTypeLiteral(t *ast.TypeNode) *ast.Node {
179179
isArrayType := jstypeliteral.IsArrayType
180180
properties := p.nodeSliceArena.NewSlice(0)
181181
for _, prop := range jstypeliteral.JSDocPropertyTags {
182+
if prop.Kind != ast.KindJSDocPropertyTag && prop.Kind != ast.KindJSDocParameterTag {
183+
continue
184+
}
182185
jsprop := prop.AsJSDocParameterOrPropertyTag()
183186
name := prop.Name()
184187
if name.Kind == ast.KindQualifiedName {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [tests/cases/compiler/jsDocTypedefWithThisTag.ts] ////
2+
3+
=== bug.js ===
4+
/** @typedef T @this {object} */
5+
const x = 1;
6+
>x : Symbol(x, Decl(bug.js, 1, 5))
7+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/jsDocTypedefWithThisTag.ts] ////
2+
3+
=== bug.js ===
4+
/** @typedef T @this {object} */
5+
const x = 1;
6+
>x : 1
7+
>1 : 1
8+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
5+
// @filename: bug.js
6+
/** @typedef T @this {object} */
7+
const x = 1;

0 commit comments

Comments
 (0)