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
+11 -4
View File
@@ -12,7 +12,14 @@ export const propertyName = (node: t.Node): string => {
export const semanticStaticPropertyName = (
property: t.Node,
computed: boolean,
): string =>
computed && !t.isStringLiteral(property) && !t.isNumericLiteral(property)
? ""
: propertyName(property);
): string => semanticStaticPropertyKey(property, computed) ?? "";
/** Read an exact property key, preserving the legal empty-string key. */
export const semanticStaticPropertyKey = (
property: t.Node,
computed: boolean,
): string | null => {
if (t.isStringLiteral(property) || t.isNumericLiteral(property))
return String(property.value);
return !computed && t.isIdentifier(property) ? property.name : null;
};