mirror of
https://github.com/morluto/rea.git
synced 2026-11-11 09:21:16 +00:00
test(javascript): preserve exact empty property keys in declarations
This commit is contained in:
1 parent
e8374f4e58
commit
b4502be51a
1 file changed
+22
@@ -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