@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 CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
5
5
  [![Node.js](https://img.shields.io/badge/node-%3E%3D18-brightgreen?style=flat-square)](https://nodejs.org)
6
- [![Tests](https://img.shields.io/badge/tests-55%20passing-brightgreen?style=flat-square)](./tests)
6
+ [![Tests](https://img.shields.io/badge/tests-62%20passing-brightgreen?style=flat-square)](./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
 
@@ -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\s*;/g,
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\s*;/g,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinksharpe/react-compiler-unmemo",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Remove useMemo and useCallback hooks from React codebases to leverage React Compiler automatic optimization",
5
5
  "license": "MIT",
6
6
  "type": "module",