mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Merge pull request #30383 from Microsoft/fixFindAllRefsOfDefaultExport
Fix find all refs of default export
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
18
tests/cases/fourslash/findAllRefsImportDefault.ts
Normal file
18
tests/cases/fourslash/findAllRefsImportDefault.ts
Normal file
@@ -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
tests/cases/fourslash/findAllRefsImportNamed.ts
Normal file
15
tests/cases/fourslash/findAllRefsImportNamed.ts
Normal file
@@ -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]);
|
||||
Reference in New Issue
Block a user