Skip to content

Commit 5351378

Browse files
authored
Fix hover expansion for aliased default function exports (#3523)
1 parent ef57f3f commit 5351378

3 files changed

Lines changed: 111 additions & 1 deletion

File tree

internal/checker/nodebuilder_hover.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ func (b *NodeBuilderImpl) expandModuleDecl(symbol *ast.Symbol) *ast.Node {
451451

452452
// Handle alias/re-export symbols
453453
if m.Flags&ast.SymbolFlagsAlias != 0 {
454-
aliasDecl := core.FirstOrNil(m.Declarations)
454+
aliasDecl := b.ch.getDeclarationOfAliasSymbol(m)
455455
target := b.ch.getMergedSymbol(b.ch.getTargetOfAliasDeclaration(aliasDecl))
456456
if target != nil {
457457
// If the alias target is a local symbol (not itself an export), emit its declaration first
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 TestQuickInfoVerbosityNamespaceBindingWithDefaultExportedFunction1(t *testing.T) {
11+
t.Parallel()
12+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
13+
const content = `// @module: esnext
14+
// @filename: /a.ts
15+
export default function fn() {}
16+
export { fn as default };
17+
// @filename: /b.ts
18+
import * as ns from "./a";
19+
20+
ns/*1*/;`
21+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
22+
defer done()
23+
f.VerifyBaselineHoverWithVerbosity(t, map[string][]int{"1": {0, 1}})
24+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// === QuickInfo ===
2+
=== /b.ts ===
3+
// import * as ns from "./a";
4+
//
5+
// ns;
6+
// ^^
7+
// | ----------------------------------------------------------------------
8+
// | ```typescript
9+
// | (alias) module "/a" {
10+
// | export { default };
11+
// | }
12+
// | ```
13+
// |
14+
// | (verbosity level: 1)
15+
// | ----------------------------------------------------------------------
16+
// ^^
17+
// | ----------------------------------------------------------------------
18+
// | ```typescript
19+
// | (alias) module "./a"
20+
// | ```
21+
// |
22+
// | (verbosity level: 0)
23+
// | ----------------------------------------------------------------------
24+
[
25+
{
26+
"marker": {
27+
"Position": 30,
28+
"LSPosition": {
29+
"line": 2,
30+
"character": 2
31+
},
32+
"Name": "1",
33+
"Data": {}
34+
},
35+
"item": {
36+
"hover": {
37+
"contents": {
38+
"kind": "markdown",
39+
"value": "```typescript\n(alias) module \"./a\"\n```\n"
40+
},
41+
"range": {
42+
"start": {
43+
"line": 2,
44+
"character": 0
45+
},
46+
"end": {
47+
"line": 2,
48+
"character": 2
49+
}
50+
},
51+
"canIncreaseVerbosity": true
52+
},
53+
"verbosityLevel": 0
54+
}
55+
},
56+
{
57+
"marker": {
58+
"Position": 30,
59+
"LSPosition": {
60+
"line": 2,
61+
"character": 2
62+
},
63+
"Name": "1",
64+
"Data": {}
65+
},
66+
"item": {
67+
"hover": {
68+
"contents": {
69+
"kind": "markdown",
70+
"value": "```typescript\n(alias) module \"/a\" {\n export { default };\n}\n```\n"
71+
},
72+
"range": {
73+
"start": {
74+
"line": 2,
75+
"character": 0
76+
},
77+
"end": {
78+
"line": 2,
79+
"character": 2
80+
}
81+
}
82+
},
83+
"verbosityLevel": 1
84+
}
85+
}
86+
]

0 commit comments

Comments
 (0)