Repository navigation
fix(javascript): recover Electron APIs through default imports and optional calls - #1673
Conversation
…tional calls `import electron from "electron"` bound the module with a leading `default` export segment, so `electron.ipcMain.handle(...)`, `new electron.BrowserWindow(...)` and destructuring from that binding matched no Electron API. Electron's CommonJS exports define no `default` member, so the segment can only denote the module object; drop it when classifying Electron bindings. The binding classifier already recorded optional-call roots, but the IPC, context-bridge, utility-process and sender-validation visitors accepted only plain calls. `ipcMain?.handle(...)`, `contextBridge?.exposeInMainWorld(...)` and the common `event.senderFrame?.url.startsWith(...)` check were dropped without a limitation. Refs #1656 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
…import-optional-calls
|
TL;DR: I tested this after the merge, on Linux. Default imports and optional calls now work for Electron code. Rewritten to a default import, real Stretchly code gives all 30 handlers back. This PR merged as fe574c0 (#1673). I tested main at 17f7040 (#1682) against 3a7a307 (#1670), the commit just before the merge. Results
On 3a7a307, both tests fail (Node 24.18.0). In the next table, Before is 3a7a307 and Main is 17f7040, all on Node 24.18.0.
The last row follows from the fix. A default import now counts as the Electron namespace, so a write to it drops the handlers, like the Still unresolved, as the PR says (0 on both commits): Real app: Stretchly 1.22.1 (BSD-2-Clause), Not run
Thanks, kaoru0822-kitauji, for the fix and for the new tests. Variant detailsEach Stretchly variant keeps every line number. The default-import forms rewrite lines 1 to 5. The optional-call forms change the 30 Test setup
Commands🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
Summary
Follow-up to #1656 (fixed by 2612e47). Three Electron API shapes on current main still report
0findings with no limitation that names the miss:import electron from "electron"; electron.ipcMain.handle("ch:ping", …)main_handlers: 01import electron from "electron"; const { ipcMain } = electron; ipcMain.handle(…)01import electron from "electron"; new electron.BrowserWindow(…)andelectron.contextBridge.exposeInMainWorld(…)browser_windows: 0,context_bridge_apis: 01,1ipcMain?.handle(…),contextBridge?.exposeInMainWorld(…),utilityProcess?.fork(…)01if (!event.senderFrame?.url.startsWith("file://")) …inside a handlersender_validation_observations: 01The default import is the pattern used by libraries such as electron-util and electron-store.
Causes
bindImportsgives a default import the origin path["default"], so the classifier produced["default", "ipcMain"], which no Electron matcher accepts. Electron's CommonJS exports define nodefaultmember, so the segment can only mean the module object (the ES module default import of a CommonJS module ismodule.exports). The newelectronExportPathdrops the leadingdefaultonly when the classifier returns an Electron path. The semantic IR keeps its exact["default"]origin.electron.default.ipcMainstill matches nothing.classifyParsedJavaScriptElectronBindingsStepsalready recordsOptionalCallExpressionroots, andelectronCalleePathwalksOptionalMemberExpression. But the IPC, context-bridge, utility-process and sender-validation visitors accepted onlyCallExpression. Babel parses any call in a?.chain, includingevent.senderFrame?.url.startsWith(x), as anOptionalCallExpression. So the existing optional-member branch ininspectValidationCallcould never run for that chain.Not changed: data-flow shapes the identity limitation already calls unresolved (
let ipc; ipc = ipcMain, passingipcMainas an argument,{ ipc: ipcMain }.ipc,ipcMain || null,.bind). Bundler interop wrappers (__importDefault(require("electron")).default) remain unrecognized, as before.Verification
src/domain/javascript/electronStaticAnalysisIdentity.test.ts(2 tests). Both fail with the source changes stashed and pass with them.npm run test:focused --all 43src/domain/javascript/*.test.tsfiles plustests/composition/javascript-applications/electronApplicationAnalysis.test.ts: 808 passed.tests/acceptance/applications/applicationWorkflowCli.test.ts(afterbuild:cached): 31 passed.npm run typecheck,npm run check:fastpass. jscpd stays at 2.489%.analyze-javascript-application <dir> --artifact-format directory, compared main vs branch on the shapes in the table.No Hopper/Ghidra involvement; no real Electron runtime execution.
🤖 Generated with Claude Code