Aalexbit-codemod

jsx-new-transform

Migrate React default/namespace imports for the new JSX transform (jscodeshift tutorial parity)

reactjsxmigration
Public
9 executions
Run locally
npx codemod jsx-new-transform
Documentation

jsx-new-transform

**Rewrites import React / import * as React to named or namespace imports so code matches the automatic JSX runtime (same goal as the Backstage JSX migration tutorial, not Backstage-specific).

What it does

  • Finds value imports from react where the binding is React (default or import * as React).
  • Safe destructure path: When React is only used as a qualifier (React.createElement, React.FC, <React.Fragment>, etc.) and there are no conflicting bindings, replaces those uses and switches to named / import type imports from react.
  • Fallback: When React is still needed as a value (e.g. returned or passed around), rewrites toward import * as React from "react" (including splitting default + named imports when needed).
  • Cleanup: Removes unused default or namespace React imports when nothing references React.
  • Errors: Throws if more than one conflicting React binding import is found (same rule as the original jscodeshift recipe).

Metrics

MetricMeaning
jsx-react-import-outcomeOne row per file outcome. Dimension outcome: destructured, namespace-fallback, namespace-fallback-split, removed-unused-namespace, removed-unused-default, skipped-no-react-import, error-duplicate-react-import, unchanged.
jsx-react-destructure-symbolsWhen destructuring, counts symbols pulled into imports. Dimensions symbol (imported:local), kind: value or type.
jsx-react-member-replacedCounts qualifier rewrites. Dimension kind: nested_type_identifier (e.g. React.FCFC) or member_expression (e.g. React.memomemo, JSX React.FragmentFragment).

Workflow parameters

  • destructureNamespaceImports (boolean, default true): When true, also attempt to destructure import * as React when only React.* access is used (aligned with the tutorial’s --destructureNamespaceImports=true).

Workflow (see workflow.yaml): runs the JSSG step on **/*.{ts,tsx,js,jsx} excluding node_modules.

Ready to contribute?

Build your own codemod and share it with the community.