Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(wasm): pass glue filenames to the JavaScript parser (#4485)

jayinversf4cabe535fa5
diff --git a/src/wasm/WabtOutput.test.ts b/src/wasm/WabtOutput.test.ts
index d69cafa73..f1aabe95a 100644
--- a/src/wasm/WabtOutput.test.ts
+++ b/src/wasm/WabtOutput.test.ts
@@ -284,6 +284,40 @@ it("keeps exact local, ambiguous URL, computed and unparseable glue distinct", (
});
});
+it("retains .wasm references in glue whose conditional arrows only parse as JavaScript", () => {
+ const candidates = ["/app/module.wasm"];
+ // TypeScript grammar reads `n===0?H=>(x):H=>(y)` as a return type, so the
+ // unnamed-source fallback fails the file; the .js filename selects JavaScript.
+ const conditional = associateWasmGlue(
+ 'const pick=n===0?H=>({start:H.startY}):H=>({start:H.startX});\nfetch("./module.wasm");\n',
+ "/app/glue.js",
+ candidates,
+ );
+ expect(conditional.parse_status).toBe("complete");
+ expect(conditional.references).toMatchObject([
+ {
+ value: "./module.wasm",
+ line: 2,
+ column: 6,
+ candidate_paths: candidates,
+ association: "local-path-candidate",
+ evidence_kind: "static-literal",
+ },
+ ]);
+
+ expect(
+ associateWasmGlue('fetch("./module.wasm");\n', "/app/glue.js", candidates)
+ .references,
+ ).toMatchObject([
+ {
+ value: "./module.wasm",
+ line: 1,
+ column: 6,
+ association: "local-path-candidate",
+ },
+ ]);
+});
+
it("retains directive literals and matches their cooked escaped path", () => {
const candidates = ["/app/module.wasm"];
const directive = associateWasmGlue(
diff --git a/src/wasm/WasmGlueAdapter.ts b/src/wasm/WasmGlueAdapter.ts
index f249c232c..4a130508e 100644
--- a/src/wasm/WasmGlueAdapter.ts
+++ b/src/wasm/WasmGlueAdapter.ts
@@ -11,8 +11,11 @@ export const associateWasmGlue = (
) => {
// Babel requires a hashbang at offset zero. Removing only its preceding BOM
// leaves reference coordinates intact: all code starts on a later line.
+ // The selected filename selects the JavaScript grammar for .js glue; the
+ // unnamed-source fallback would misread valid JavaScript conditionals.
const file = parseJavaScriptSource(
source.startsWith("\uFEFF#!") ? source.slice(1) : source,
+ path,
);
const references: {
value: string;