Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -30749,6 +30749,9 @@ func (c *Checker) getSymbolOfNameOrPropertyAccessExpression(name *ast.Node) *ast
}
meaning := core.IfElse(isJSDoc, ast.SymbolFlagsValue|ast.SymbolFlagsType|ast.SymbolFlagsNamespace, ast.SymbolFlagsValue)
result := c.resolveEntityName(name, meaning, true /*ignoreErrors*/, true /*dontResolveAlias*/, nil /*location*/)
if result != nil && result.Flags&ast.SymbolFlagsModuleExports != 0 {
result = result.ValueDeclaration.Symbol() // Symbol of the module source file
}
if result == nil && isJSDoc {
if container := ast.FindAncestor(name, ast.IsClassOrInterfaceLike); container != nil {
symbol := c.getSymbolOfDeclaration(container)
Expand Down
1 change: 0 additions & 1 deletion internal/fourslash/_scripts/failingTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ TestDoubleUnderscoreCompletions
TestEditJsdocType
TestExportDefaultClass
TestExportDefaultFunction
TestFindAllRefsModuleDotExports
TestFindReferencesBindingPatternInJsdocNoCrash1
TestFindReferencesBindingPatternInJsdocNoCrash2
TestGenericCombinatorWithConstraints1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestFindAllRefsModuleDotExports(t *testing.T) {
t.Parallel()
t.Skip()

defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @allowJs: true
// @Filename: /a.js
Expand Down
2 changes: 1 addition & 1 deletion internal/ls/findallreferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ func (l *LanguageService) getReferencedSymbolsForModuleIfDeclaredBySourceFile(ct
exportEquals := symbol.Exports[ast.InternalSymbolNameExportEquals]
// If exportEquals != nil, we're about to add references to `import("mod")` anyway, so don't double-count them.
moduleReferences := l.getReferencedSymbolsForModule(ctx, program, symbol, exportEquals != nil, sourceFiles, sourceFilesSet)
if exportEquals == nil || !sourceFilesSet.Has(moduleSourceFileName) {
if exportEquals == nil || exportEquals.Flags&ast.SymbolFlagsAlias == 0 || !sourceFilesSet.Has(moduleSourceFileName) {
return moduleReferences
}
symbol, _ = checker.ResolveAlias(exportEquals)
Expand Down
6 changes: 5 additions & 1 deletion internal/ls/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
}
}
}
b.WriteString(c.SymbolToStringEx(symbol, container, ast.SymbolFlagsNone, symbolFormatFlags))
if symbol.Name == ast.InternalSymbolNameExportEquals && symbol.Parent != nil && symbol.Parent.Flags&ast.SymbolFlagsModule != 0 {
b.WriteString("exports")
} else {
b.WriteString(c.SymbolToStringEx(symbol, container, ast.SymbolFlagsNone, symbolFormatFlags))
}
b.WriteString(": ")
if callNode := getCallOrNewExpression(node); callNode != nil {
b.WriteString(c.SignatureToStringEx(c.GetResolvedSignature(callNode), container, typeFormatFlags|checker.TypeFormatFlagsWriteCallStyleSignature|checker.TypeFormatFlagsWriteTypeArgumentsOfSignature|checker.TypeFormatFlagsWriteArrowStyleSignature))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import foo = require("./foo.js");
=== bar.cjs ===
module.exports = {
>module.exports : Symbol(export=, Decl(bar.cjs, 0, 0))
>module : Symbol(module.exports)
>module : Symbol("bar", Decl(bar.cjs, 0, 0))
>exports : Symbol(export=, Decl(bar.cjs, 0, 0))

a: 1,
Expand All @@ -21,7 +21,7 @@ module.exports = {
=== foo.js ===
module.exports = {
>module.exports : Symbol(export=, Decl(foo.js, 0, 0))
>module : Symbol(module.exports)
>module : Symbol("foo", Decl(foo.js, 0, 0))
>exports : Symbol(export=, Decl(foo.js, 0, 0))

b: 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
*/
module.exports = {};
>module.exports : Symbol(export=, Decl(panicSatisfiesOnExportEqualsDeclaration.js, 0, 0))
>module : Symbol(module.exports)
>module : Symbol("panicSatisfiesOnExportEqualsDeclaration", Decl(panicSatisfiesOnExportEqualsDeclaration.js, 0, 0))
>exports : Symbol(export=, Decl(panicSatisfiesOnExportEqualsDeclaration.js, 0, 0))

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// === documentHighlights ===
// === /Foo.js ===
// /*HIGHLIGHTS*/module.exports = {
// /*HIGHLIGHTS*/[|module.exports = {
//
// }
// }|]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// === findAllReferences ===
// === /a.js ===
// /*FIND ALL REFS*/const [|b|] = require("./b");



// === findAllReferences ===
// === /a.js ===
// const b = require("/*FIND ALL REFS*/[|./b|]");

// === /b.js ===
// [|module.exports = 0|];



// === findAllReferences ===
// === /a.js ===
// const b = require("[|./b|]");

// === /b.js ===
// /*FIND ALL REFS*/[|module.exports = 0|];
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export = Foo;

module.exports = /** @type {FooFun} */(void 0);
>module.exports : Symbol(export=, Decl(something.js, 0, 0))
>module : Symbol(module.exports)
>module : Symbol("something", Decl(something.js, 0, 0))
>exports : Symbol(export=, Decl(something.js, 0, 0))

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
->module.exports : Symbol(module.exports, Decl(something.js, 0, 0))
->module : Symbol(export=, Decl(something.js, 0, 0))
+>module.exports : Symbol(export=, Decl(something.js, 0, 0))
+>module : Symbol(module.exports)
+>module : Symbol("something", Decl(something.js, 0, 0))
Comment on lines 7 to +10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of funky that before, module.exports was module.exports and module was export=, but now module.exports is export= and module is module name...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new behavior is defensible. The old one--not so much.

>exports : Symbol(export=, Decl(something.js, 0, 0))
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
=== test.js ===
module.exports = {
>module.exports : Symbol(export=, Decl(test.js, 0, 0))
>module : Symbol(module.exports)
>module : Symbol("test", Decl(test.js, 0, 0))
>exports : Symbol(export=, Decl(test.js, 0, 0))

message: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
->module.exports : Symbol(module.exports, Decl(test.js, 0, 0))
->module : Symbol(export=, Decl(test.js, 0, 0))
+>module.exports : Symbol(export=, Decl(test.js, 0, 0))
+>module : Symbol(module.exports)
+>module : Symbol("test", Decl(test.js, 0, 0))
>exports : Symbol(export=, Decl(test.js, 0, 0))

message: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
=== index.js ===
module.exports = {}
>module.exports : Symbol(export=, Decl(index.js, 0, 0))
>module : Symbol(module.exports)
>module : Symbol("index", Decl(index.js, 0, 0))
>exports : Symbol(export=, Decl(index.js, 0, 0))

var x = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
->module : Symbol(module, Decl(index.js, 0, 0))
->exports : Symbol(module.exports, Decl(index.js, 0, 0))
+>module.exports : Symbol(export=, Decl(index.js, 0, 0))
+>module : Symbol(module.exports)
+>module : Symbol("index", Decl(index.js, 0, 0))
+>exports : Symbol(export=, Decl(index.js, 0, 0))

var x = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const _item = require("./namespacer");

module.exports = 12;
>module.exports : Symbol(export=, Decl(index.js, 0, 38))
>module : Symbol(module.exports)
>module : Symbol("index", Decl(index.js, 0, 0))
>exports : Symbol(export=, Decl(index.js, 0, 38))

Object.defineProperty(module, "exports", { value: "oh no" });
Expand All @@ -29,7 +29,7 @@ A.bar = class Q {}

module.exports = A;
>module.exports : Symbol(A, Decl(namespacey.js, 0, 5))
>module : Symbol(module.exports)
>module : Symbol("namespacey", Decl(namespacey.js, 0, 0))
>exports : Symbol(A, Decl(namespacey.js, 0, 5))
>A : Symbol(A, Decl(namespacey.js, 0, 5))

Expand All @@ -53,7 +53,7 @@ Object.defineProperty(B, "NS", { value: "why though", writable: true });

module.exports = B;
>module.exports : Symbol(B, Decl(namespacer.js, 0, 5))
>module : Symbol(module.exports)
>module : Symbol("namespacer", Decl(namespacer.js, 0, 0))
>exports : Symbol(B, Decl(namespacer.js, 0, 5))
>B : Symbol(B, Decl(namespacer.js, 0, 5))

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
->module.exports : Symbol(module.exports, Decl(index.js, 0, 0))
->module : Symbol(export=, Decl(index.js, 0, 38))
+>module.exports : Symbol(export=, Decl(index.js, 0, 38))
+>module : Symbol(module.exports)
+>module : Symbol("index", Decl(index.js, 0, 0))
>exports : Symbol(export=, Decl(index.js, 0, 38))

Object.defineProperty(module, "exports", { value: "oh no" });
Expand Down Expand Up @@ -38,7 +38,7 @@
->exports : Symbol(export=, Decl(namespacey.js, 1, 18))
->A : Symbol(A, Decl(namespacey.js, 0, 5), Decl(namespacey.js, 0, 12))
+>module.exports : Symbol(A, Decl(namespacey.js, 0, 5))
+>module : Symbol(module.exports)
+>module : Symbol("namespacey", Decl(namespacey.js, 0, 0))
+>exports : Symbol(A, Decl(namespacey.js, 0, 5))
+>A : Symbol(A, Decl(namespacey.js, 0, 5))

Expand Down Expand Up @@ -73,6 +73,6 @@
->exports : Symbol(export=, Decl(namespacer.js, 2, 72))
->B : Symbol(B, Decl(namespacer.js, 0, 5), Decl(namespacer.js, 0, 12), Decl(namespacer.js, 2, 22))
+>module.exports : Symbol(B, Decl(namespacer.js, 0, 5))
+>module : Symbol(module.exports)
+>module : Symbol("namespacer", Decl(namespacer.js, 0, 0))
+>exports : Symbol(B, Decl(namespacer.js, 0, 5))
+>B : Symbol(B, Decl(namespacer.js, 0, 5))
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function foo() {
*/
module.exports = {
>module.exports : Symbol(export=, Decl(input.js, 42, 1))
>module : Symbol(module.exports)
>module : Symbol("input", Decl(input.js, 0, 0))
>exports : Symbol(export=, Decl(input.js, 42, 1))

color: "red"
Expand All @@ -82,6 +82,6 @@ expectLiteral({ props: module.exports });
>expectLiteral : Symbol(expectLiteral, Decl(input.js, 27, 27))
>props : Symbol(props, Decl(input.js, 51, 15))
>module.exports : Symbol(export=, Decl(input.js, 42, 1))
>module : Symbol(module.exports)
>module : Symbol("input", Decl(input.js, 0, 0))
>exports : Symbol(export=, Decl(input.js, 42, 1))

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
->module.exports : Symbol(module.exports, Decl(input.js, 0, 0))
->module : Symbol(export=, Decl(input.js, 42, 1))
+>module.exports : Symbol(export=, Decl(input.js, 42, 1))
+>module : Symbol(module.exports)
+>module : Symbol("input", Decl(input.js, 0, 0))
>exports : Symbol(export=, Decl(input.js, 42, 1))

color: "red"
Expand All @@ -73,5 +73,5 @@
->module : Symbol(module, Decl(input.js, 42, 1), Decl(input.js, 51, 22))
->exports : Symbol(module.exports, Decl(input.js, 0, 0))
+>module.exports : Symbol(export=, Decl(input.js, 42, 1))
+>module : Symbol(module.exports)
+>module : Symbol("input", Decl(input.js, 0, 0))
+>exports : Symbol(export=, Decl(input.js, 42, 1))
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Bar extends Foo {}

module.exports = Bar;
>module.exports : Symbol(Bar, Decl(index.js, 0, 12))
>module : Symbol(module.exports)
>module : Symbol("/index", Decl(index.js, 0, 0))
>exports : Symbol(Bar, Decl(index.js, 0, 12))
>Bar : Symbol(Bar, Decl(index.js, 0, 12))

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
->module : Symbol(export=, Decl(index.js, 2, 24))
->exports : Symbol(export=, Decl(index.js, 2, 24))
+>module.exports : Symbol(Bar, Decl(index.js, 0, 12))
+>module : Symbol(module.exports)
+>module : Symbol("/index", Decl(index.js, 0, 0))
+>exports : Symbol(Bar, Decl(index.js, 0, 12))
>Bar : Symbol(Bar, Decl(index.js, 0, 12))
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Bar extends Foo {}

module.exports = Bar;
>module.exports : Symbol(Bar, Decl(index.js, 0, 12))
>module : Symbol(module.exports)
>module : Symbol("/index", Decl(index.js, 0, 0))
>exports : Symbol(Bar, Decl(index.js, 0, 12))
>Bar : Symbol(Bar, Decl(index.js, 0, 12))

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
->module : Symbol(export=, Decl(index.js, 2, 24))
->exports : Symbol(export=, Decl(index.js, 2, 24))
+>module.exports : Symbol(Bar, Decl(index.js, 0, 12))
+>module : Symbol(module.exports)
+>module : Symbol("/index", Decl(index.js, 0, 0))
+>exports : Symbol(Bar, Decl(index.js, 0, 12))
>Bar : Symbol(Bar, Decl(index.js, 0, 12))
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
=== /node_modules/foo/src/index.js ===
module.exports = 1;
>module.exports : Symbol(export=, Decl(index.js, 0, 0))
>module : Symbol(module.exports)
>module : Symbol("/node_modules/foo/src/index", Decl(index.js, 0, 0))
>exports : Symbol(export=, Decl(index.js, 0, 0))

=== /a.js ===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
->module.exports : Symbol(module.exports, Decl(index.js, 0, 0))
->module : Symbol(export=, Decl(index.js, 0, 0))
+>module.exports : Symbol(export=, Decl(index.js, 0, 0))
+>module : Symbol(module.exports)
+>module : Symbol("/node_modules/foo/src/index", Decl(index.js, 0, 0))
>exports : Symbol(export=, Decl(index.js, 0, 0))

=== /a.js ===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Bar extends Foo {}

module.exports = Bar;
>module.exports : Symbol(Bar, Decl(index.js, 0, 12))
>module : Symbol(module.exports)
>module : Symbol("index", Decl(index.js, 0, 0))
>exports : Symbol(Bar, Decl(index.js, 0, 12))
>Bar : Symbol(Bar, Decl(index.js, 0, 12))

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
->module : Symbol(export=, Decl(index.js, 2, 24))
->exports : Symbol(export=, Decl(index.js, 2, 24))
+>module.exports : Symbol(Bar, Decl(index.js, 0, 12))
+>module : Symbol(module.exports)
+>module : Symbol("index", Decl(index.js, 0, 0))
+>exports : Symbol(Bar, Decl(index.js, 0, 12))
>Bar : Symbol(Bar, Decl(index.js, 0, 12))
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const alias = {};

module.exports = alias;
>module.exports : Symbol(alias, Decl(a.js, 0, 5))
>module : Symbol(module.exports)
>module : Symbol("/a", Decl(a.js, 0, 0))
>exports : Symbol(alias, Decl(a.js, 0, 5))
>alias : Symbol(alias, Decl(a.js, 0, 5))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
->module : Symbol(export=, Decl(a.js, 0, 17))
->exports : Symbol(export=, Decl(a.js, 0, 17))
+>module.exports : Symbol(alias, Decl(a.js, 0, 5))
+>module : Symbol(module.exports)
+>module : Symbol("/a", Decl(a.js, 0, 0))
+>exports : Symbol(alias, Decl(a.js, 0, 5))
>alias : Symbol(alias, Decl(a.js, 0, 5))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
=== file.js ===
module.exports = [{ name: 'other', displayName: 'Other', defaultEnabled: true }];
>module.exports : Symbol(export=, Decl(file.js, 0, 0))
>module : Symbol(module.exports)
>module : Symbol("file", Decl(file.js, 0, 0))
>exports : Symbol(export=, Decl(file.js, 0, 0))
>name : Symbol(name, Decl(file.js, 0, 19))
>displayName : Symbol(displayName, Decl(file.js, 0, 34))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
->module.exports : Symbol(module.exports, Decl(file.js, 0, 0))
->module : Symbol(export=, Decl(file.js, 0, 0))
+>module.exports : Symbol(export=, Decl(file.js, 0, 0))
+>module : Symbol(module.exports)
+>module : Symbol("file", Decl(file.js, 0, 0))
>exports : Symbol(export=, Decl(file.js, 0, 0))
>name : Symbol(name, Decl(file.js, 0, 19))
>displayName : Symbol(displayName, Decl(file.js, 0, 34))
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
module.exports = function loader(options) {}
>module.exports : Symbol(export=, Decl(index.js, 0, 0))
>module : Symbol(module.exports)
>module : Symbol("index", Decl(index.js, 0, 0))
>exports : Symbol(export=, Decl(index.js, 0, 0))
>loader : Symbol(loader, Decl(index.js, 8, 16))
>options : Symbol(options, Decl(index.js, 8, 33))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
->module.exports : Symbol(module.exports, Decl(index.js, 0, 0))
->module : Symbol(export=, Decl(index.js, 0, 0))
+>module.exports : Symbol(export=, Decl(index.js, 0, 0))
+>module : Symbol(module.exports)
+>module : Symbol("index", Decl(index.js, 0, 0))
>exports : Symbol(export=, Decl(index.js, 0, 0))
>loader : Symbol(loader, Decl(index.js, 8, 16))
>options : Symbol(options, Decl(index.js, 8, 33))
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const customSymbol = Symbol("custom");
// This is a common pattern in Node’s built-in modules:
module.exports = {
>module.exports : Symbol(export=, Decl(file.js, 0, 38))
>module : Symbol(module.exports)
>module : Symbol("file", Decl(file.js, 0, 0))
>exports : Symbol(export=, Decl(file.js, 0, 38))

customSymbol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
->module : Symbol(module, Decl(file.js, 0, 38))
->exports : Symbol(module.exports, Decl(file.js, 0, 0))
+>module.exports : Symbol(export=, Decl(file.js, 0, 38))
+>module : Symbol(module.exports)
+>module : Symbol("file", Decl(file.js, 0, 0))
+>exports : Symbol(export=, Decl(file.js, 0, 38))

customSymbol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Abcde {

module.exports = {
>module.exports : Symbol(export=, Decl(test.js, 3, 1))
>module : Symbol(module.exports)
>module : Symbol("/test", Decl(test.js, 0, 0))
>exports : Symbol(export=, Decl(test.js, 3, 1))

Abcde
Expand Down
Loading