Skip to content

Commit 05f4d69

Browse files
authored
Fix hover on module.exports (#2098)
1 parent dd043f4 commit 05f4d69

File tree

267 files changed

+518
-491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

267 files changed

+518
-491
lines changed

internal/checker/checker.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30749,6 +30749,9 @@ func (c *Checker) getSymbolOfNameOrPropertyAccessExpression(name *ast.Node) *ast
3074930749
}
3075030750
meaning := core.IfElse(isJSDoc, ast.SymbolFlagsValue|ast.SymbolFlagsType|ast.SymbolFlagsNamespace, ast.SymbolFlagsValue)
3075130751
result := c.resolveEntityName(name, meaning, true /*ignoreErrors*/, true /*dontResolveAlias*/, nil /*location*/)
30752+
if result != nil && result.Flags&ast.SymbolFlagsModuleExports != 0 {
30753+
result = result.ValueDeclaration.Symbol() // Symbol of the module source file
30754+
}
3075230755
if result == nil && isJSDoc {
3075330756
if container := ast.FindAncestor(name, ast.IsClassOrInterfaceLike); container != nil {
3075430757
symbol := c.getSymbolOfDeclaration(container)

internal/fourslash/_scripts/failingTests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ TestDoubleUnderscoreCompletions
231231
TestEditJsdocType
232232
TestExportDefaultClass
233233
TestExportDefaultFunction
234-
TestFindAllRefsModuleDotExports
235234
TestFindReferencesBindingPatternInJsdocNoCrash1
236235
TestFindReferencesBindingPatternInJsdocNoCrash2
237236
TestGenericCombinatorWithConstraints1

internal/fourslash/tests/gen/findAllRefsModuleDotExports_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func TestFindAllRefsModuleDotExports(t *testing.T) {
1111
t.Parallel()
12-
t.Skip()
12+
1313
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1414
const content = `// @allowJs: true
1515
// @Filename: /a.js

internal/ls/findallreferences.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ func (l *LanguageService) getReferencedSymbolsForModuleIfDeclaredBySourceFile(ct
753753
exportEquals := symbol.Exports[ast.InternalSymbolNameExportEquals]
754754
// If exportEquals != nil, we're about to add references to `import("mod")` anyway, so don't double-count them.
755755
moduleReferences := l.getReferencedSymbolsForModule(ctx, program, symbol, exportEquals != nil, sourceFiles, sourceFilesSet)
756-
if exportEquals == nil || !sourceFilesSet.Has(moduleSourceFileName) {
756+
if exportEquals == nil || exportEquals.Flags&ast.SymbolFlagsAlias == 0 || !sourceFilesSet.Has(moduleSourceFileName) {
757757
return moduleReferences
758758
}
759759
symbol, _ = checker.ResolveAlias(exportEquals)

internal/ls/hover.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
189189
}
190190
}
191191
}
192-
b.WriteString(c.SymbolToStringEx(symbol, container, ast.SymbolFlagsNone, symbolFormatFlags))
192+
if symbol.Name == ast.InternalSymbolNameExportEquals && symbol.Parent != nil && symbol.Parent.Flags&ast.SymbolFlagsModule != 0 {
193+
b.WriteString("exports")
194+
} else {
195+
b.WriteString(c.SymbolToStringEx(symbol, container, ast.SymbolFlagsNone, symbolFormatFlags))
196+
}
193197
b.WriteString(": ")
194198
if callNode := getCallOrNewExpression(node); callNode != nil {
195199
b.WriteString(c.SignatureToStringEx(c.GetResolvedSignature(callNode), container, typeFormatFlags|checker.TypeFormatFlagsWriteCallStyleSignature|checker.TypeFormatFlagsWriteTypeArgumentsOfSignature|checker.TypeFormatFlagsWriteArrowStyleSignature))

testdata/baselines/reference/compiler/erasableSyntaxOnlyJS.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import foo = require("./foo.js");
1111
=== bar.cjs ===
1212
module.exports = {
1313
>module.exports : Symbol(export=, Decl(bar.cjs, 0, 0))
14-
>module : Symbol(module.exports)
14+
>module : Symbol("bar", Decl(bar.cjs, 0, 0))
1515
>exports : Symbol(export=, Decl(bar.cjs, 0, 0))
1616

1717
a: 1,
@@ -21,7 +21,7 @@ module.exports = {
2121
=== foo.js ===
2222
module.exports = {
2323
>module.exports : Symbol(export=, Decl(foo.js, 0, 0))
24-
>module : Symbol(module.exports)
24+
>module : Symbol("foo", Decl(foo.js, 0, 0))
2525
>exports : Symbol(export=, Decl(foo.js, 0, 0))
2626

2727
b: 2,

testdata/baselines/reference/compiler/panicSatisfiesOnExportEqualsDeclaration.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
*/
77
module.exports = {};
88
>module.exports : Symbol(export=, Decl(panicSatisfiesOnExportEqualsDeclaration.js, 0, 0))
9-
>module : Symbol(module.exports)
9+
>module : Symbol("panicSatisfiesOnExportEqualsDeclaration", Decl(panicSatisfiesOnExportEqualsDeclaration.js, 0, 0))
1010
>exports : Symbol(export=, Decl(panicSatisfiesOnExportEqualsDeclaration.js, 0, 0))
1111

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// === documentHighlights ===
22
// === /Foo.js ===
3-
// /*HIGHLIGHTS*/module.exports = {
3+
// /*HIGHLIGHTS*/[|module.exports = {
44
//
5-
// }
5+
// }|]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// === findAllReferences ===
2+
// === /a.js ===
3+
// /*FIND ALL REFS*/const [|b|] = require("./b");
4+
5+
6+
7+
// === findAllReferences ===
8+
// === /a.js ===
9+
// const b = require("/*FIND ALL REFS*/[|./b|]");
10+
11+
// === /b.js ===
12+
// [|module.exports = 0|];
13+
14+
15+
16+
// === findAllReferences ===
17+
// === /a.js ===
18+
// const b = require("[|./b|]");
19+
20+
// === /b.js ===
21+
// /*FIND ALL REFS*/[|module.exports = 0|];

testdata/baselines/reference/submodule/compiler/checkJsTypeDefNoUnusedLocalMarked.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ export = Foo;
2525

2626
module.exports = /** @type {FooFun} */(void 0);
2727
>module.exports : Symbol(export=, Decl(something.js, 0, 0))
28-
>module : Symbol(module.exports)
28+
>module : Symbol("something", Decl(something.js, 0, 0))
2929
>exports : Symbol(export=, Decl(something.js, 0, 0))
3030

0 commit comments

Comments
 (0)