Skip to content

Commit 320a6d7

Browse files
committed
fix generation of property keys
1 parent d515fd1 commit 320a6d7

File tree

1 file changed

+9
-1
lines changed
  • packages/jsxpression/src/codegen/schema

1 file changed

+9
-1
lines changed

packages/jsxpression/src/codegen/schema/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export function generateObjectTypeWithJSDoc(properties: any, depth: number = 0):
4848

4949
const nestedType = mapSchemaTypeToTypeScript(value, depth + 1);
5050
const required = value.required !== false ? "" : "?";
51-
result += ` ${key}${required}: ${nestedType};\n`;
51+
52+
result += ` ${formatKey(key)}${required}: ${nestedType};\n`;
5253
});
5354

5455
result += " }";
@@ -112,3 +113,10 @@ export function generatePropertyJSDoc(
112113

113114
return output;
114115
}
116+
117+
function formatKey(key: string): string {
118+
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key)) {
119+
return key;
120+
}
121+
return `"${key}"`;
122+
}

0 commit comments

Comments
 (0)