@thinksharpe/react-compiler-unmemo 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/helpers/remove-hooks.mjs +9 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
[](https://nodejs.org)
|
|
6
|
-
[](./tests)
|
|
7
7
|
|
|
8
8
|
A codemod that removes `useMemo` and `useCallback` from your React codebase so you can adopt [React Compiler](https://react.dev/learn/react-compiler) without the manual cleanup.
|
|
9
9
|
|
package/helpers/remove-hooks.mjs
CHANGED
|
@@ -436,31 +436,33 @@ export function processFile(filePath, { dryRun = false } = {}) {
|
|
|
436
436
|
|
|
437
437
|
// Phase 3: Clean up imports
|
|
438
438
|
if (changed) {
|
|
439
|
-
// Handle: import React, { useMemo, useCallback, ... } from "react"; (single or double quotes)
|
|
439
|
+
// Handle: import React, { useMemo, useCallback, ... } from "react"; (single or double quotes, semicolon optional)
|
|
440
440
|
content = content.replace(
|
|
441
|
-
/import React, \{([^}]*)\} from (["'])react\2\
|
|
441
|
+
/import React, \{([^}]*)\} from (["'])react\2[^\S\n]*;?/g,
|
|
442
442
|
(match, imports, quote) => {
|
|
443
|
+
const semi = match.trimEnd().endsWith(";") ? ";" : "";
|
|
443
444
|
const cleaned = imports
|
|
444
445
|
.split(",")
|
|
445
446
|
.map((s) => s.trim())
|
|
446
447
|
.filter((s) => s && s !== "useMemo" && s !== "useCallback")
|
|
447
448
|
.join(", ");
|
|
448
|
-
if (!cleaned) return `import React from ${quote}react${quote}
|
|
449
|
-
return `import React, { ${cleaned} } from ${quote}react${quote}
|
|
449
|
+
if (!cleaned) return `import React from ${quote}react${quote}${semi}`;
|
|
450
|
+
return `import React, { ${cleaned} } from ${quote}react${quote}${semi}`;
|
|
450
451
|
},
|
|
451
452
|
);
|
|
452
453
|
|
|
453
|
-
// Handle: import { useMemo, useCallback, ... } from "react"; (single or double quotes)
|
|
454
|
+
// Handle: import { useMemo, useCallback, ... } from "react"; (single or double quotes, semicolon optional)
|
|
454
455
|
content = content.replace(
|
|
455
|
-
/import \{([^}]*)\} from (["'])react\2\
|
|
456
|
+
/import \{([^}]*)\} from (["'])react\2[^\S\n]*;?/g,
|
|
456
457
|
(match, imports, quote) => {
|
|
458
|
+
const semi = match.trimEnd().endsWith(";") ? ";" : "";
|
|
457
459
|
const cleaned = imports
|
|
458
460
|
.split(",")
|
|
459
461
|
.map((s) => s.trim())
|
|
460
462
|
.filter((s) => s && s !== "useMemo" && s !== "useCallback")
|
|
461
463
|
.join(", ");
|
|
462
464
|
if (!cleaned) return ""; // Remove empty import entirely
|
|
463
|
-
return `import { ${cleaned} } from ${quote}react${quote}
|
|
465
|
+
return `import { ${cleaned} } from ${quote}react${quote}${semi}`;
|
|
464
466
|
},
|
|
465
467
|
);
|
|
466
468
|
|
package/package.json
CHANGED