From b4502be51a2898308cd5fb5cea6f04c3e1c52c2b Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Sat, 24 Oct 2026 03:05:35 +0800 Subject: [PATCH] test(javascript): preserve exact empty property keys in declarations --- src/domain/webBundleAnalyzerAst.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/domain/webBundleAnalyzerAst.test.ts b/src/domain/webBundleAnalyzerAst.test.ts index b3210d94fc..98a18795d0 100644 --- a/src/domain/webBundleAnalyzerAst.test.ts +++ b/src/domain/webBundleAnalyzerAst.test.ts @@ -4,6 +4,28 @@ import { expect, it } from "vitest"; import { parseJavaScriptSource } from "./javascript/javascriptSourceParser.js"; import { objectString } from "./webBundleAnalyzerAst.js"; +it.each([ + { property: "[``]: 0", expected: "catalog" }, + { property: '"": 0', expected: "catalog" }, + { property: '[""]: 0', expected: "catalog" }, + { property: "[`other`]: 0", expected: "catalog" }, + { property: "[unknownKey]: 0", expected: undefined }, +])( + "preserves WebMCP identity beside exact unrelated keys: $property", + ({ property, expected }) => { + const file = parseJavaScriptSource( + `const declaration = {name:"catalog", ${property}};`, + ); + const declaration = file?.program.body[0]; + if (!t.isVariableDeclaration(declaration)) + throw new Error("Expected variable declaration"); + const object = declaration.declarations[0]?.init; + if (!t.isObjectExpression(object)) + throw new Error("Expected object expression"); + expect(objectString(object, "name")).toBe(expected); + }, +); + it("reads WebMCP declaration strings through the exact-literal owner", () => { const file = parseJavaScriptSource( "const declaration = { name: `catalog`, description: `Browse catalog` }; const dynamic = { name: `catalog ${scope}` };",