fix(semantics): preserve empty string property keys (#764)

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>
This commit is contained in:
Rudy Mizrahi Celekli
2026-10-07 10:23:43 +08:00
committed by GitHub
parent dd3640548f
commit 630bdafcac
11 changed files with 149 additions and 33 deletions
@@ -0,0 +1,33 @@
import { expect, it } from "vitest";
import { analyzeJavaScriptSemantics } from "./javascriptSemanticAnalysis.js";
it.each([
"const routes = {'': 'HOME'}; const root = routes[''];",
"const routes = {['']: 'HOME'}; const root = routes[''];",
"const routes = {'': 'HOME'}; const {'': root} = routes;",
"const routes = {'': 'HOME'}; const {['']: root} = routes;",
"const routes = {home: 'HOME'}; const root = routes.home;",
])("preserves exact string keys in %s", (source) => {
const ir = analyzeJavaScriptSemantics(source);
expect(ir.bindings.find(({ name }) => name === "root")?.value).toEqual({
status: "literal",
value: "HOME",
});
expect(
ir.frontiers.filter(({ kind }) => kind === "dynamic-property"),
).toEqual([]);
});
it("keeps a computed identifier key unresolved", () => {
const ir = analyzeJavaScriptSemantics(
"const routes = {'': 'HOME'}; const root = routes[key];",
);
expect(ir.bindings.find(({ name }) => name === "root")?.value.status).toBe(
"unknown",
);
expect(ir.frontiers).toEqual(
expect.arrayContaining([
expect.objectContaining({ kind: "dynamic-property" }),
]),
);
});