mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 20:14:01 -06:00
feat(49358): use filename based on exported name (#49875)
This commit is contained in:
parent
5b0eea48e9
commit
94bb950008
@ -62,7 +62,7 @@ namespace ts.refactor {
|
||||
|
||||
const currentDirectory = getDirectoryPath(oldFile.fileName);
|
||||
const extension = extensionFromPath(oldFile.fileName);
|
||||
const newModuleName = makeUniqueModuleName(getNewModuleName(usage.movedSymbols), extension, currentDirectory, host);
|
||||
const newModuleName = makeUniqueModuleName(getNewModuleName(usage.oldFileImportsFromNewFile, usage.movedSymbols), extension, currentDirectory, host);
|
||||
const newFileNameWithExtension = newModuleName + extension;
|
||||
|
||||
// If previous file was global, this is easy.
|
||||
@ -478,8 +478,8 @@ namespace ts.refactor {
|
||||
}
|
||||
}
|
||||
|
||||
function getNewModuleName(movedSymbols: ReadonlySymbolSet): string {
|
||||
return movedSymbols.forEachEntry(symbolNameNoDefault) || "newFile";
|
||||
function getNewModuleName(importsFromNewFile: ReadonlySymbolSet, movedSymbols: ReadonlySymbolSet): string {
|
||||
return importsFromNewFile.forEachEntry(symbolNameNoDefault) || movedSymbols.forEachEntry(symbolNameNoDefault) || "newFile";
|
||||
}
|
||||
|
||||
interface UsageInfo {
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////[|type Props = {
|
||||
//// a: number;
|
||||
////}
|
||||
////class Foo {
|
||||
//// readonly a: number;
|
||||
//// constructor({ a }: Props) {
|
||||
//// this.a = a;
|
||||
//// }
|
||||
////}|]
|
||||
////
|
||||
////export default function f() {
|
||||
//// return new Foo({ a: 1 });
|
||||
////}
|
||||
|
||||
verify.moveToNewFile({
|
||||
newFileContents: {
|
||||
"/a.ts":
|
||||
`import { Foo } from "./Foo";
|
||||
|
||||
export default function f() {
|
||||
return new Foo({ a: 1 });
|
||||
}`,
|
||||
|
||||
"/Foo.ts":
|
||||
`type Props = {
|
||||
a: number;
|
||||
};
|
||||
export class Foo {
|
||||
readonly a: number;
|
||||
constructor({ a }: Props) {
|
||||
this.a = a;
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user