Skip to content

Fix find all refs of default export #30383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 14, 2019
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
4 changes: 3 additions & 1 deletion src/services/findAllReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,9 @@ namespace ts.FindAllReferences.Core {

// For `export { foo as bar }`, rename `foo`, but not `bar`.
if (!isForRenameWithPrefixAndSuffixText(state.options) || alwaysGetReferences) {
const exportKind = referenceLocation.originalKeywordKind === SyntaxKind.DefaultKeyword ? ExportKind.Default : ExportKind.Named;
const isDefaultExport = referenceLocation.originalKeywordKind === SyntaxKind.DefaultKeyword
|| exportSpecifier.name.originalKeywordKind === SyntaxKind.DefaultKeyword;
const exportKind = isDefaultExport ? ExportKind.Default : ExportKind.Named;
const exportSymbol = Debug.assertDefined(exportSpecifier.symbol);
const exportInfo = Debug.assertDefined(getExportInfo(exportSymbol, exportKind, state.checker));
searchForImportsOfExport(referenceLocation, exportSymbol, exportInfo, state);
Expand Down
2 changes: 1 addition & 1 deletion src/services/importTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ namespace ts.FindAllReferences {
}

/**
* `import x = require("./x") or `import * as x from "./x"`.
* `import x = require("./x")` or `import * as x from "./x"`.
* An `export =` may be imported by this syntax, so it may be a direct import.
* If it's not a direct import, it will be in `indirectUsers`, so we don't have to do anything here.
*/
Expand Down
18 changes: 18 additions & 0 deletions tests/cases/fourslash/findAllRefsImportDefault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// <reference path='fourslash.ts' />

// @Filename: f.ts
////export { [|foo|] as [|{| "isWriteAccess": true, "isDefinition": true |}default|] };
////function /*start*/[|{| "isWriteAccess": true, "isDefinition": true |}foo|](a: number, b: number) {
//// return a + b;
////}

// @Filename: b.ts
////import [|{| "isWriteAccess": true, "isDefinition": true |}bar|] from "./f";
////[|bar|](1, 2);

verify.noErrors();
const [ foo0, foo1, foo2, bar0, bar1 ] = test.ranges();
const fooGroup = { definition: "function foo(a: number, b: number): number", ranges: [foo0, foo2] };
const exportDefaultGroup = { definition: "(alias) function foo(a: number, b: number): number\nexport default", ranges: [foo1] };
const barGroup = { definition: "(alias) function bar(a: number, b: number): number\nimport bar", ranges: [bar0, bar1]};
verify.referenceGroups("start", [fooGroup, exportDefaultGroup, barGroup]);
15 changes: 15 additions & 0 deletions tests/cases/fourslash/findAllRefsImportNamed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />

// @Filename: f.ts
////export { [|foo|] as [|{| "isWriteAccess": true, "isDefinition": true |}foo|] }
////function /*start*/[|{| "isWriteAccess": true, "isDefinition": true |}foo|](a: number, b: number) { }

// @Filename: b.ts
////import x = require("./f");
////x.[|foo|](1, 2);

verify.noErrors();
const [ foo0, foo1, foo2, foo3 ] = test.ranges();
const fooGroup = { definition: "function foo(a: number, b: number): void", ranges: [foo0, foo2] };
const exportFooGroup = { definition: "(alias) function foo(a: number, b: number): void\nexport foo", ranges: [foo1, foo3] };
verify.referenceGroups("start", [fooGroup, exportFooGroup]);