Skip to content

rn: simplify src/ and bin/rn-cli.js - #387

Merged
ChALkeR merged 5 commits into
mainfrom
claude/quirky-pascal-w4dfxf
Nov 3, 2026
Merged

ChALkeR merged 5 commits into
mainfrom
claude/quirky-pascal-w4dfxf

Conversation

@ChristopherTuring

Copy link
Copy Markdown
Collaborator

What

This simplifies rn/src/ and rn/bin/rn-cli.js. Behaviour is the same: exported names and signatures, every message text, and every generated output are unchanged, and no existing test had to change.

src/ plus bin/rn-cli.js goes from 3,834 to 3,738 lines. That's a modest cut, because most of the remaining comments explain why, for example Metro, Babel or react-native compatibility, and those are kept. Comments that only restated the code are removed and others are shortened.

if statements follow one style:

  • a single statement with no else has no braces: if (cond) statement;
  • an if with an else always has braces and line breaks.

Code changes

Resolution and config

  • metro-options.js:
    • the two inline-requires factories, always built in pairs, are now one inliningsOf(), so fallback() takes one fewer parameter;
    • an unreachable null branch is gone;
    • the refusal message is built in one place.
  • exports.js: targets are narrowed in one pass, and iterator helpers replace key arrays.
  • metro-config.js: one walk loop covers both arrays and nodes.
  • resolve.js: smaller type checks, and one path join in resolveFile().

Command line

  • rn-config.js: the modeOf() and sourceOf() helpers are inlined.
  • rn-bundle.js: one esmOf() and one inliningOf() replace repeated flagOf() calls.
  • bin/rn-cli.js: translate() resolves --config itself.

Bundling

  • assets.js:
    • assetRecord() filters an asset's files and takes the platform's own over the generic ones, instead of grouping under "name : platform" keys;
    • isAssetFile() is two lines instead of a backwards character loop.
  • build-host.js: a duplicated directory-entry lookup is now one entry().
  • load.js: the TSX case falls through to the plain transform.
  • image-size.js: an SVG unit table replaces a nested ternary.

Babel

  • babel-aliases.js: a plain alias key uses the same ^key(/.*|)$ RegExp the module-resolver plugin builds, instead of a hand-written matcher. Compared on about 1.1 million random keys and specifiers, they always matched.
  • babel-switches.js: loaded() is a closure instead of returning { plugin, error } pairs.
  • babel-transformer.js:
    • one loadPlugin() replaces two copies of the same call;
    • the single-use memoized() helper is inlined;
    • the block-scoping lookup searches one combined list;
    • the fingerprint case returns early.
  • module-resolver.js: aliasesOf() returns a match function, removing two duplicated loops.
  • es-module.js: TypeScript namespaces join the other value declarations under one check.
  • esm-imports.js: the built-in RegExp.escape replaces a local helper, and one set serves as both the seen set and the queue for export *.
  • babel-worker.js: any message from a worker marks it ready. A worker always sends ready before it can answer anything.

Unchanged: self-test.js, assets-dest.js, serializer.js, source-map.js, defaults.js and babelrc.js had nothing worth removing.

A bug found on the way

If a Metro config's getTransformOptions gave inlineRequires: null, turning inline requires on with --inline-requires or rn.config.json's inlineRequires threw a TypeError, because typeof null is 'object'. The blockList is now read with optional chaining. A new assertion in rn-bundle.test.js covers it and fails without the fix.

Checks

node --run lint passes. All rn tests pass: 686, plus one skipped plutil test that only runs on macOS.


Generated by Claude Code

metro-options: merge inlineRequiresOf and forcedInliningOf into one
inliningsOf, called once per config path, and drop the unreachable null
branch from inliningOf. Combine errorsOf and joined into refusalOf.
exports: narrow the targets in one pass, with no early-exit loop, and use
iterator helpers instead of copying keys. metro-config: one walk loop for
both arrays and nodes. resolve: smaller type checks and one join in
resolveFile. Trim comments that restate the code; keep Metro notes and
attributions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M1K1MwBwvz2fxsHzWHnvrM
rn-config.js: drop the modeOf() and sourceOf() helpers for inline
expressions, check the underlying refusal before reading the flag, and
cut the header and doc comments to their constraints. rn-bundle.js: one
esmOf()/inliningOf() each, shared by withInlineRequires() and the
no-Babel-config checks, instead of repeating the flagOf() calls; drop
comments that restate the code. bin/rn-cli.js: translate() resolves
--config against the cwd itself, and --bundle-encoding is always a
string. cli.js: shorter projectBabel() comments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M1K1MwBwvz2fxsHzWHnvrM
….js, jsval.js

assetRecord() picks the platform's files or else the generic ones by direct
filtering instead of grouping under string keys; isAssetFile() checks each
dot-suffix by splitting the name. lookups() shares one entry() between typed
lookups and its API, calling the dirent's own method. load.js's lower() runs
the plain transform once for both TSX-without-JSX and other loaders. An empty
SVG unit is a table entry. Comments that restated code are gone, others are
shorter; loadCached()'s if/else takes braces.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M1K1MwBwvz2fxsHzWHnvrM
…liases, module-resolver, es-module, esm-imports, worklets

- babel-aliases: a plain alias key is matched by the plugin's own
  `^key(/.*|)$` RegExp instead of a hand-rolled exec duck type;
  aliasing() returns early when memoized.
- babel-switches: loaded() becomes a closure returning the plugin and
  pushing its error, instead of a { plugin, error } pair threaded through
  four parameters.
- babel-transformer: one loadPlugin() for the inlining and syntax-only
  plugins; memoized() inlined; block-scoping lookup over one list; early
  return for the fingerprint; brace style for if/else.
- babel-worker: any worker message marks it ready (READY comes first).
- module-resolver: aliasesOf() returns a predicate used directly by
  filter()/some(); inline-requires reuses sameFor().
- es-module, esm-imports: TSModuleDeclaration joins the value
  declarations; RegExp.escape replaces a local escaper; the seen Set
  doubles as the export * work queue.
- Comments shortened where they restated code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M1K1MwBwvz2fxsHzWHnvrM
… of a getTransformOptions giving inlineRequires null

The if/else pairs left without braces (metro-config.js, resolve.js) have
them, and image-size.js's two single-statement ifs have none.

Inline requires turned on (--inline-requires, rn.config.json's
inlineRequires) where the Metro config's getTransformOptions gave
inlineRequires null threw: typeof null is 'object', and its blockList
was read. The blockList is now read through optional chaining, of none
there as of true or false.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M1K1MwBwvz2fxsHzWHnvrM
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T14:18:45.523740Z aa59435 PR opened
🔒 Security Review ✅ Completed 2026-11-03T14:20:29.897295Z aa59435 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ChALkeR
ChALkeR merged commit 8145368 into main Nov 3, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants