Skip to content

fix(javascript): follow bundler namespace interop for Electron APIs - #1827

Merged
kaoru0822-kitauji merged 2 commits into
mainfrom
fix/electron-namespace-browser-window
Oct 11, 2026
Merged

kaoru0822-kitauji merged 2 commits into
mainfrom
fix/electron-namespace-browser-window

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1802.

Some bundled Electron main processes reported browser_windows: 0 and preload_entrypoints: 0 even though they plainly construct new electron.BrowserWindow(...). A plain const electron = require("electron") namespace already resolved. The miss comes from the CommonJS interop that bundlers emit for import * as Electron from "electron":

Emitter Output Why it was missed
Rolldown / tsdown (the T3 Code build in the issue) let electron = require("electron"); electron = __toESM(electron); The reassignment marked the binding as unresolved
esbuild var import_electron = __toESM(require("electron")); The helper call hid the require origin
tsc (esModuleInterop) const Electron = __importStar(require("electron")); Same as esbuild

Change

  • semanticNamespaceInteropOperand recognizes __toESM, __importStar, and _interopRequireWildcard by name. A call only counts when the helper is a locally declared binding that is never reassigned and its lexical resolution is not blocked. These helpers return an object that exposes every own member of the wrapped module, so member paths pass through unchanged.
  • Electron binding classification looks through those helpers. A plain = that rewraps the binding's own value (x = __toESM(x)) no longer counts as a reassignment. Any other write still leaves the binding unresolved, as before.
  • The Electron identity limitation text and docs/javascript-artifact-reconstruction.md now say that these helpers are recognized by name.

These cases still produce no finding and are covered by the test:

  • an unbound or global helper
  • a helper that is reassigned
  • a rewrap of a different operand
  • a rewrap followed by another write
  • ||=

Not in this PR: a webPreferences.preload written as a non-literal expression (e.g. environment.preloadPath) is already kept as a dynamic web preference and counted as unknown. It still does not appear in preload_entrypoints, and I left that as is.

Validation

  • I added a case to src/domain/javascript/electronStaticAnalysisIdentity.test.ts. It covers the Rolldown, esbuild, and tsc forms plus the negative forms, and it fails without the fix.
  • npm run test:focused passes on all src/domain/javascript tests, the Electron composition tests, the application acceptance tests, and the bundler runtime-scope boundary test: 68 files, 1001 tests.
  • npm run check:fast and npm run docs:check pass.
  • I ran rea analyze-javascript-application on hand-written source shaped like each bundler's output. I did not run it against the T3 Code AppImage itself.

🤖 Generated with Claude Code

Rolldown/tsdown emit `let electron = require("electron"); electron =
__toESM(electron);` and esbuild/tsc emit `__toESM(require("electron"))`
or `__importStar(require("electron"))` for namespace imports. The
reassignment or the helper call hid the Electron origin, so bundled
main processes reported zero BrowserWindows and preloads.

Locally declared, never reassigned interop helpers recognized by name
now pass the module through, and a binding's rewrap of its own value is
not treated as a reassignment. Other writes stay unresolved.

Fixes #1802

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 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-10-11T13:19:24.105157Z 87f3e6e New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 029767fde1

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +90 to +93
return helper !== undefined &&
!helper.definitions.some(({ kind }) => kind === "assignment") &&
t.isExpression(operand)
? operand

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Verify helper semantics before treating its result as Electron

Any artifact that merely declares one of these names for a non-interop function can now produce fabricated Electron findings: for example, const __toESM = () => fake; const e = __toESM(require("electron")); new e.BrowserWindow(...) is classified as a real BrowserWindow even though the call uses fake. A declaration and no direct reassignment do not establish that the binding preserves its operand; validate the helper body against the supported bundler forms or leave such calls unresolved so reported Electron APIs remain evidence-backed.

AGENTS.md reference: AGENTS.md:L5-L5

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 87f3e6e. I can't prove what a helper does statically without evaluating it, and its dependencies (__copyProps, __create, …) would need the same proof. So recognition now requires all of the following:

  • an unblocked lexical resolution
  • one of the emitted names
  • exactly one program-scope definition that is a function declaration, an arrow or function expression, an IIFE, or (this && this.name) || <function>

Lookalikes bound to non-function values, nested helpers, unbound names, and reassigned helpers are rejected (new tests cover these). The identity limitation and docs/javascript-artifact-reconstruction.md now say this step is inferred: helper bodies are not evaluated, so a local function that reuses one of these names is trusted to pass the module through.

Only trust an interop helper name when it has a single program-scope
function definition, and state that helper bodies are not evaluated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working provider: electron Analysis provider / engine: electron

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Electron analysis reports 0 BrowserWindows and 0 preloads when main uses electron.BrowserWindow namespace form; miss is not logged as unknown

2 participants