Repository navigation
fix(javascript): follow bundler namespace interop for Electron APIs - #1827
Conversation
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]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| return helper !== undefined && | ||
| !helper.definitions.some(({ kind }) => kind === "assignment") && | ||
| t.isExpression(operand) | ||
| ? operand |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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]>
Summary
Fixes #1802.
Some bundled Electron main processes reported
browser_windows: 0andpreload_entrypoints: 0even though they plainly constructnew electron.BrowserWindow(...). A plainconst electron = require("electron")namespace already resolved. The miss comes from the CommonJS interop that bundlers emit forimport * as Electron from "electron":let electron = require("electron"); electron = __toESM(electron);var import_electron = __toESM(require("electron"));requireoriginesModuleInterop)const Electron = __importStar(require("electron"));Change
semanticNamespaceInteropOperandrecognizes__toESM,__importStar, and_interopRequireWildcardby 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.=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.docs/javascript-artifact-reconstruction.mdnow say that these helpers are recognized by name.These cases still produce no finding and are covered by the test:
||=Not in this PR: a
webPreferences.preloadwritten 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 inpreload_entrypoints, and I left that as is.Validation
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:focusedpasses on allsrc/domain/javascripttests, the Electron composition tests, the application acceptance tests, and the bundler runtime-scope boundary test: 68 files, 1001 tests.npm run check:fastandnpm run docs:checkpass.rea analyze-javascript-applicationon hand-written source shaped like each bundler's output. I did not run it against the T3 Code AppImage itself.🤖 Generated with Claude Code