Skip to content

Commit

Permalink
findAllRefs: Support anonymous default export
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Hanson committed Oct 18, 2017
1 parent 3220ebc commit 83162f0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
27 changes: 17 additions & 10 deletions src/services/findAllReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,19 +377,26 @@ namespace ts.FindAllReferences.Core {

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

// Try to get the smallest valid scope that we can limit our search to;
// otherwise we'll need to search globally (i.e. include each file).
const scope = getSymbolScope(symbol);
if (scope) {
getReferencesInContainer(scope, scope.getSourceFile(), search, state);
if (node.kind === SyntaxKind.DefaultKeyword) {
addReference(node, symbol, node, state);
searchForImportsOfExport(node, symbol, { exportingModuleSymbol: symbol.parent, exportKind: ExportKind.Default }, state);
}
else {
// Global search
for (const sourceFile of state.sourceFiles) {
state.cancellationToken.throwIfCancellationRequested();
searchForName(sourceFile, search, state);
const search = state.createSearch(node, symbol, /*comingFrom*/ undefined, { allSearchSymbols: populateSearchSymbolSet(symbol, node, checker, options.implementations) });

// Try to get the smallest valid scope that we can limit our search to;
// otherwise we'll need to search globally (i.e. include each file).
const scope = getSymbolScope(symbol);
if (scope) {
getReferencesInContainer(scope, scope.getSourceFile(), search, state);
}
else {
// Global search
for (const sourceFile of state.sourceFiles) {
state.cancellationToken.throwIfCancellationRequested();
searchForName(sourceFile, search, state);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

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

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

Expand Down
13 changes: 13 additions & 0 deletions tests/cases/fourslash/findAllRefsForDefaultExport_anonymous.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// <reference path='fourslash.ts' />

// @Filename: /a.ts
////export [|{| "isDefinition": true, "isWriteAccess": true |}default|] 1;

// @Filename: /b.ts
////import [|{| "isDefinition": true, "isWriteAccess": true |}a|] from "./a";

const [r0, r1] = test.ranges();
verify.referenceGroups(r0, [
{ definition: "(property) default: 1", ranges: [r0] },
{ definition: "import a", ranges: [r1] },
]);
2 changes: 0 additions & 2 deletions tests/cases/fourslash/findAllRefsForDefaultExport_reExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
// @Filename: /re-export-dep.ts
////import [|{| "isWriteAccess": true, "isDefinition": true |}fooDefault|] from "./re-export";

verify.noErrors();

const [r0, r1, r2, r3] = test.ranges();
verify.referenceGroups([r0, r1], [
{ definition: "const foo: 1", ranges: [r0, r1] },
Expand Down

0 comments on commit 83162f0

Please sign in to comment.