mirror of
https://github.com/morluto/rea
synced 2026-10-26 06:16:17 -04:00
refactor(javascript): remove obsolete Electron classifier facade
This commit is contained in:
@@ -835,28 +835,9 @@ const resolveGlobalAliasFact = (
|
||||
return openGlobalFact(name);
|
||||
};
|
||||
|
||||
/**
|
||||
* Proven Electron export path segments for call and construction roots, keyed by
|
||||
* root offset. Only proven Electron origins are present; callers must not
|
||||
* infer an Electron export from an absent entry or familiar local name.
|
||||
*/
|
||||
export const classifyParsedJavaScriptElectronBindings = (
|
||||
file: ParsedJavaScriptSource,
|
||||
): ReadonlyMap<number, readonly string[]> =>
|
||||
completeSemanticSteps(classifyParsedJavaScriptElectronBindingsSteps(file));
|
||||
|
||||
/** Resolve Electron aliases while yielding during lexical and AST scans. */
|
||||
export function* classifyParsedJavaScriptElectronBindingsSteps(
|
||||
file: ParsedJavaScriptSource,
|
||||
): Generator<void, ReadonlyMap<number, readonly string[]>> {
|
||||
const state = createState(file.program);
|
||||
yield* collectDefinitionsSteps(file.program, state);
|
||||
return (yield* indexJavaScriptElectronIdentitySteps(file.program, state))
|
||||
.bindings;
|
||||
}
|
||||
|
||||
/** Shared lexical identity and visible-write proof for direct and wrapped calls. */
|
||||
export interface JavaScriptElectronIdentity {
|
||||
/** Proven export paths keyed by call/construction root offset; absence is unknown. */
|
||||
readonly bindings: ReadonlyMap<number, readonly string[]>;
|
||||
readonly intactExport: (path: readonly (string | null)[]) => boolean;
|
||||
readonly exportPath: (root: t.Node) => readonly string[] | undefined;
|
||||
|
||||
@@ -4,8 +4,7 @@ import * as t from "@babel/types";
|
||||
import {
|
||||
analyzeParsedJavaScriptSemantics,
|
||||
analyzeParsedJavaScriptSemanticsSteps,
|
||||
classifyParsedJavaScriptElectronBindings,
|
||||
classifyParsedJavaScriptElectronBindingsSteps,
|
||||
indexJavaScriptElectronIdentitySteps,
|
||||
indexJavaScriptBindingsWithReceiversSteps,
|
||||
} from "./javascriptSemanticAnalysis.js";
|
||||
import * as semanticProjection from "./javascriptSemanticProjection.js";
|
||||
@@ -198,16 +197,16 @@ new NativeWindow();
|
||||
[text.indexOf('ambient.open("/global")'), "window"],
|
||||
]);
|
||||
|
||||
const electronSteps = classifyParsedJavaScriptElectronBindingsSteps(parsed);
|
||||
const electronSteps = indexJavaScriptElectronIdentitySteps(
|
||||
parsed.program,
|
||||
openStep.value.bindings,
|
||||
);
|
||||
let electronStep = electronSteps.next();
|
||||
expect(electronStep.done).toBe(false);
|
||||
while (electronStep.done !== true) electronStep = electronSteps.next();
|
||||
expect([...electronStep.value]).toEqual([
|
||||
expect([...electronStep.value.bindings]).toEqual([
|
||||
[text.lastIndexOf("NativeWindow()"), ["BrowserWindow"]],
|
||||
]);
|
||||
expect(electronStep.value).toEqual(
|
||||
classifyParsedJavaScriptElectronBindings(parsed),
|
||||
);
|
||||
});
|
||||
|
||||
it("resolves Electron APIs through proven immutable aliases", () => {
|
||||
@@ -262,7 +261,13 @@ conditionalAlias.handle("conditional-alias:ping", () => "local");
|
||||
const parsed = parseJavaScriptSource(text, "aliases.js");
|
||||
if (parsed === null) throw new Error("Expected parsed source");
|
||||
|
||||
expect([...classifyParsedJavaScriptElectronBindings(parsed)]).toEqual([
|
||||
const index = completeSemanticSteps(
|
||||
indexJavaScriptBindingsWithReceiversSteps(parsed.program),
|
||||
);
|
||||
const electron = completeSemanticSteps(
|
||||
indexJavaScriptElectronIdentitySteps(parsed.program, index.bindings),
|
||||
);
|
||||
expect([...electron.bindings]).toEqual([
|
||||
[text.indexOf("Win({"), ["BrowserWindow"]],
|
||||
[text.indexOf("bridge.exposeInMainWorld"), ["contextBridge"]],
|
||||
[text.indexOf('ipc.handle("main:ping"'), ["ipcMain"]],
|
||||
|
||||
Reference in New Issue
Block a user