Skip to content

Commit b2ff5bf

Browse files
authored
fix(2674): fix identifier name lookup in variable declaration lists (#2677)
1 parent 0da6896 commit b2ff5bf

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 TestFindAllRefsConst(t *testing.T) {
11+
t.Parallel()
12+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
13+
const content = `// @Filename: a.ts
14+
/**/const const
15+
`
16+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
17+
defer done()
18+
f.VerifyBaselineFindAllReferences(t, "")
19+
}

internal/ls/utilities.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,11 +680,12 @@ func getAdjustedLocation(node *ast.Node, forRename bool, sourceFile *ast.SourceF
680680
}
681681
}
682682

683-
// /**/<var|let| [|n:ame|] ...
684-
if node.Kind == ast.KindVarKeyword || node.Kind == ast.KindConstKeyword || node.Kind == ast.KindLetKeyword &&
683+
// /**/<var|let|const> [|name|] ...
684+
if (node.Kind == ast.KindVarKeyword || node.Kind == ast.KindConstKeyword || node.Kind == ast.KindLetKeyword) &&
685685
ast.IsVariableDeclarationList(parent) && len(parent.AsVariableDeclarationList().Declarations.Nodes) == 1 {
686-
if decl := parent.AsVariableDeclarationList().Declarations.Nodes[0].AsVariableDeclaration(); ast.IsIdentifier(decl.Name()) {
687-
return decl.Name()
686+
declaration := parent.AsVariableDeclarationList().Declarations.Nodes[0].AsVariableDeclaration()
687+
if ast.IsIdentifier(declaration.Name()) {
688+
return declaration.Name()
688689
}
689690
}
690691

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// === findAllReferences ===
2+
// === /a.ts ===
3+
// /*FIND ALL REFS*/const const
4+
//

0 commit comments

Comments
 (0)