How tsr modifies code to remove unused elements
maintsr performs several types of automated cleanup when it detects unused code:
- Removing unused exports: If an exported constant is not used anywhere in the project, the
exportkeyword (or the entire declaration) is removed. - Downgrading exports to locals: If an
exportis unused but the value itself is used within the same file, tsr removes theexportkeyword to make it a local variable. - Removing unused functions and their dependencies: If a function is unused, tsr removes the function declaration and any local variables that were only used within that function.
- Cleaning up imports: When a function or variable is removed, tsr automatically removes the corresponding
importstatements if they become unnecessary.
--- src/c.ts
+++ src/c.ts
@@ -1,7 +1,1 @@
-import { cwd } from "node:process";
-
export const c = 'c';
-
export function f() {
- return cwd();
-}