findAllRefs: Support anonymous default export (#19302)

This commit is contained in:
Andy 2017-10-18 15:46:39 -07:00 committed by Mohamed Hegazy
parent 5fa8db55b2
commit e5f8287e5c
4 changed files with 31 additions and 13 deletions

View file

@ -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);
}
}
}

View file

@ -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]);

View file

@ -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] },
]);

View file

@ -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] },