Skip to content

Commit 527a7a8

Browse files
authored
Allow rewrite name (#11)
Signed-off-by: Marcos Candeia <[email protected]>
1 parent 356403c commit 527a7a8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/codemod.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,10 @@ async (txt, ctx) => {
246246
*/
247247
export type SymbolMap = Record<
248248
string,
249-
Record<string, { moduleSpecifier: string; isTypeOnly?: boolean }>
249+
Record<
250+
string,
251+
{ moduleSpecifier: string; isTypeOnly?: boolean; name?: string }
252+
>
250253
>;
251254

252255
/**
@@ -271,11 +274,12 @@ export const rewriteImport = (
271274
const name = namedImport.getName();
272275
const alias = namedImport.getAliasNode()?.getText();
273276
const isTypeOnly = namedImport.isTypeOnly();
274-
if (symbolMapForModule[name]) {
277+
const rewriter = symbolMapForModule[name];
278+
if (rewriter) {
275279
const {
276280
moduleSpecifier: newModuleSpecifier,
277281
isTypeOnly: newIsTypeOnly,
278-
} = symbolMapForModule[name];
282+
} = rewriter;
279283
namedImport.remove();
280284
if (!newImports[newModuleSpecifier]) {
281285
newImports[newModuleSpecifier] = {
@@ -287,8 +291,8 @@ export const rewriteImport = (
287291
const namedImports = newImports[newModuleSpecifier].namedImports;
288292
if (Array.isArray(namedImports)) {
289293
namedImports.push({
290-
name,
291-
alias,
294+
name: rewriter.name ?? name,
295+
alias: alias ?? name,
292296
isTypeOnly: newIsTypeOnly ?? isTypeOnly,
293297
});
294298
}

0 commit comments

Comments
 (0)