Skip to content

Commit 83162f0

Browse files
author
Andy Hanson
committed
findAllRefs: Support anonymous default export
1 parent 3220ebc commit 83162f0

4 files changed

+31
-13
lines changed

src/services/findAllReferences.ts

+17-10
Original file line numberDiff line numberDiff line change
@@ -377,19 +377,26 @@ namespace ts.FindAllReferences.Core {
377377

378378
const result: SymbolAndEntries[] = [];
379379
const state = new State(sourceFiles, /*isForConstructor*/ node.kind === SyntaxKind.ConstructorKeyword, checker, cancellationToken, searchMeaning, options, result);
380-
const search = state.createSearch(node, symbol, /*comingFrom*/ undefined, { allSearchSymbols: populateSearchSymbolSet(symbol, node, checker, options.implementations) });
381380

382-
// Try to get the smallest valid scope that we can limit our search to;
383-
// otherwise we'll need to search globally (i.e. include each file).
384-
const scope = getSymbolScope(symbol);
385-
if (scope) {
386-
getReferencesInContainer(scope, scope.getSourceFile(), search, state);
381+
if (node.kind === SyntaxKind.DefaultKeyword) {
382+
addReference(node, symbol, node, state);
383+
searchForImportsOfExport(node, symbol, { exportingModuleSymbol: symbol.parent, exportKind: ExportKind.Default }, state);
387384
}
388385
else {
389-
// Global search
390-
for (const sourceFile of state.sourceFiles) {
391-
state.cancellationToken.throwIfCancellationRequested();
392-
searchForName(sourceFile, search, state);
386+
const search = state.createSearch(node, symbol, /*comingFrom*/ undefined, { allSearchSymbols: populateSearchSymbolSet(symbol, node, checker, options.implementations) });
387+
388+
// Try to get the smallest valid scope that we can limit our search to;
389+
// otherwise we'll need to search globally (i.e. include each file).
390+
const scope = getSymbolScope(symbol);
391+
if (scope) {
392+
getReferencesInContainer(scope, scope.getSourceFile(), search, state);
393+
}
394+
else {
395+
// Global search
396+
for (const sourceFile of state.sourceFiles) {
397+
state.cancellationToken.throwIfCancellationRequested();
398+
searchForName(sourceFile, search, state);
399+
}
393400
}
394401
}
395402

tests/cases/fourslash/findAllRefsDefaultImportThroughNamespace.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
const [r0, r1, r2, r3, r4] = test.ranges();
1717

18-
verify.referenceGroups([r0], [{ definition: "function f(): void", ranges: [r1, r2] }]);
18+
verify.referenceGroups([r0], [{ definition: "function f(): void", ranges: [r0, r2] }]);
1919
verify.singleReferenceGroup("function f(): void", [r1, r2]);
2020
verify.singleReferenceGroup("(property) default: number", [r3, r4]);
2121

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /a.ts
4+
////export [|{| "isDefinition": true, "isWriteAccess": true |}default|] 1;
5+
6+
// @Filename: /b.ts
7+
////import [|{| "isDefinition": true, "isWriteAccess": true |}a|] from "./a";
8+
9+
const [r0, r1] = test.ranges();
10+
verify.referenceGroups(r0, [
11+
{ definition: "(property) default: 1", ranges: [r0] },
12+
{ definition: "import a", ranges: [r1] },
13+
]);

tests/cases/fourslash/findAllRefsForDefaultExport_reExport.ts

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
// @Filename: /re-export-dep.ts
1111
////import [|{| "isWriteAccess": true, "isDefinition": true |}fooDefault|] from "./re-export";
1212

13-
verify.noErrors();
14-
1513
const [r0, r1, r2, r3] = test.ranges();
1614
verify.referenceGroups([r0, r1], [
1715
{ definition: "const foo: 1", ranges: [r0, r1] },

0 commit comments

Comments
 (0)