mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix bug: Don't rename 'default' in export { default as x } from "m"; (#23434)
* Fix bug: Don't rename 'default' in `export { default as x } from "m";`
* Rename `foo` in `{ default as foo }` if that's the original export name
This commit is contained in:
@@ -555,7 +555,10 @@ namespace ts.FindAllReferences.Core {
|
||||
if (singleReferences.length) {
|
||||
const addRef = state.referenceAdder(exportSymbol);
|
||||
for (const singleRef of singleReferences) {
|
||||
addRef(singleRef);
|
||||
// At `default` in `import { default as x }` or `export { default as x }`, do add a reference, but do not rename.
|
||||
if (!(state.options.isForRename && (isExportSpecifier(singleRef.parent) || isImportSpecifier(singleRef.parent)) && singleRef.escapedText === InternalSymbolName.Default)) {
|
||||
addRef(singleRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -887,7 +890,10 @@ namespace ts.FindAllReferences.Core {
|
||||
}
|
||||
|
||||
if (!propertyName) {
|
||||
addRef();
|
||||
// Don't rename at `export { default } from "m";`. (but do continue to search for imports of the re-export)
|
||||
if (!(state.options.isForRename && name.escapedText === InternalSymbolName.Default)) {
|
||||
addRef();
|
||||
}
|
||||
}
|
||||
else if (referenceLocation === propertyName) {
|
||||
// For `export { foo as bar } from "baz"`, "`foo`" will be added from the singleReferences for import searches of the original export.
|
||||
|
||||
@@ -254,7 +254,7 @@ namespace ts.FindAllReferences {
|
||||
}
|
||||
|
||||
// 'default' might be accessed as a named import `{ default as foo }`.
|
||||
if (!isForRename && exportKind === ExportKind.Default) {
|
||||
if (exportKind === ExportKind.Default) {
|
||||
searchForNamedImport(namedBindings as NamedImports | undefined);
|
||||
}
|
||||
}
|
||||
@@ -286,7 +286,9 @@ namespace ts.FindAllReferences {
|
||||
if (propertyName) {
|
||||
// This is `import { foo as bar } from "./a"` or `export { foo as bar } from "./a"`. `foo` isn't a local in the file, so just add it as a single reference.
|
||||
singleReferences.push(propertyName);
|
||||
if (!isForRename) { // If renaming `foo`, don't touch `bar`, just `foo`.
|
||||
// If renaming `{ foo as bar }`, don't touch `bar`, just `foo`.
|
||||
// But do rename `foo` in ` { default as foo }` if that's the original export name.
|
||||
if (!isForRename || name.escapedText === exportSymbol.escapedName) {
|
||||
// Search locally for `bar`.
|
||||
addSearch(name, checker.getSymbolAtLocation(name));
|
||||
}
|
||||
|
||||
@@ -16,5 +16,6 @@ const bGroup = { definition: "(alias) const x: 0\nimport x", ranges: bRanges };
|
||||
verify.referenceGroups(aRanges, [aGroup, bGroup]);
|
||||
verify.referenceGroups(bRanges, [bGroup]);
|
||||
|
||||
verify.rangesAreRenameLocations(aRanges);
|
||||
verify.rangesAreRenameLocations(aRanges);
|
||||
verify.renameLocations(r0, [r0, r1, r2, r3]);
|
||||
verify.renameLocations(r1, [r0, r1, r2, r3]);
|
||||
verify.rangesAreRenameLocations([r2, r3]);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////export { default } from "./b";
|
||||
////export { default as [|b|] } from "./b";
|
||||
////export { default as bee } from "./b";
|
||||
////import { default as [|b|] } from "./b";
|
||||
////import { default as bee } from "./b";
|
||||
////import [|b|] from "./b";
|
||||
|
||||
// @Filename: /b.ts
|
||||
////const [|b|] = 0;
|
||||
////export default [|b|];
|
||||
|
||||
const [r0, r1, r2, r3, r4] = test.ranges();
|
||||
verify.renameLocations(r0, [r0]);
|
||||
verify.renameLocations(r1, [r1]);
|
||||
verify.renameLocations(r2, [r2]);
|
||||
verify.renameLocations([r3, r4], [r0, r1, r2, r3, r4]);
|
||||
Reference in New Issue
Block a user