From af0e0edbc2f8afedd49008ad64b8ff6bbebb6f48 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Thu, 19 Nov 2026 07:34:44 -0500 Subject: [PATCH] fix(web): require ambient identity for bundle require edges (#12320) --- src/domain/webBundleAnalyzer.test.ts | 9 +++++++-- src/domain/webBundleAnalyzerInspection.ts | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/domain/webBundleAnalyzer.test.ts b/src/domain/webBundleAnalyzer.test.ts index b2e0a6c38a..830c31851b 100644 --- a/src/domain/webBundleAnalyzer.test.ts +++ b/src/domain/webBundleAnalyzer.test.ts @@ -2012,7 +2012,7 @@ it("does not infer call names from dynamic computed identifiers", () => { expect(result.observations.webmcp_declarations).toEqual([]); }); -it("retains direct and literal computed call names", () => { +it("retains literal calls and requires ambient identity for require edges", () => { const result = analyzeWebBundleFixture( inspection(` window.fetch("/direct"); @@ -2020,6 +2020,11 @@ it("retains direct and literal computed call names", () => { window[receiver].fetch("/nested-receiver"); window.require("./direct.js"); window["require"]("./literal.js"); + require("./bare.js"); + const vendor = { require() {} }; + vendor.require("./vendor.js"); + function local(require) { require("./local.js"); } + function withWindow(window) { window["require"]("./shadowed.js"); } document.modelContext["registerTool"]({ name: "literal-tool" }); `), ); @@ -2030,7 +2035,7 @@ it("retains direct and literal computed call names", () => { ]); expect( result.observations.chunks.edges.map(({ specifier }) => specifier), - ).toEqual(["./direct.js", "./literal.js"]); + ).toEqual(["./direct.js", "./literal.js", "./bare.js"]); expect(result.observations.webmcp_declarations).toEqual([ expect.objectContaining({ name: "literal-tool" }), ]); diff --git a/src/domain/webBundleAnalyzerInspection.ts b/src/domain/webBundleAnalyzerInspection.ts index 4b5b6bed5e..1fa025daf7 100644 --- a/src/domain/webBundleAnalyzerInspection.ts +++ b/src/domain/webBundleAnalyzerInspection.ts @@ -239,7 +239,10 @@ const inspectCall = ( ): void => { const name = calleeName(node.callee); const first = stringValue(node.arguments[0]); - if ((name === "require" || name.endsWith(".require")) && first !== undefined) + if ( + first !== undefined && + isUnmodifiedGlobalReference(node.callee, bindings, "require") + ) addEdge({ script, specifier: first,