Skip to content

Commit 9799455

Browse files
authored
fix(2536): avoid unsafe cast in documentHighlight parent function lookup (#2538)
1 parent ebba558 commit 9799455

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/testutil"
8+
)
9+
10+
func TestDocumentHighlightYield(t *testing.T) {
11+
t.Parallel()
12+
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `
15+
// @Filename: /a.ts
16+
class C {
17+
async *[Symbol.asyncIterator]() {
18+
[|yield|] {
19+
type: 'type',
20+
};
21+
}
22+
}
23+
`
24+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
25+
defer done()
26+
f.VerifyBaselineDocumentHighlights(t, nil /*preferences*/, f.Ranges()[0])
27+
}

internal/ls/documenthighlights.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ func getAsyncAndAwaitOccurrences(node *ast.Node, sourceFile *ast.SourceFile) []*
577577
}
578578

579579
func getYieldOccurrences(node *ast.Node, sourceFile *ast.SourceFile) []*ast.Node {
580-
parentFunc := ast.FindAncestor(node.Parent, ast.IsFunctionLike).AsFunctionDeclaration()
580+
parentFunc := ast.FindAncestor(node.Parent, ast.IsFunctionLike)
581581
if parentFunc == nil {
582582
return nil
583583
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// === documentHighlights ===
2+
// === /a.ts ===
3+
// class C {
4+
// async *[Symbol.asyncIterator]() {
5+
// /*HIGHLIGHTS*/[|yield|] {
6+
// type: 'type',
7+
// };
8+
// }
9+
// }
10+
//

0 commit comments

Comments
 (0)