mirror of
https://github.com/morluto/rea
synced 2026-10-25 22:08:11 -04:00
test(javascript): preserve exact empty property keys in declarations
This commit is contained in:
@@ -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}` };",
|
||||
|
||||
Reference in New Issue
Block a user