Skip to content

Commit 9630aae

Browse files
authored
Merge pull request #1189 from appwrite/pla-3442
fix: wrap invalid variable names in quotes in ts type generation
2 parents aea747c + e7fea13 commit 9630aae

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

templates/cli/lib/type-generation/languages/typescript.js.twig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ export enum <%- toPascalCase(attribute.key) %> {
9090
<% for (const [index, collection] of Object.entries(collections)) { -%>
9191
export type <%- toPascalCase(collection.name) %> = Models.Row & {
9292
<% for (const attribute of collection.attributes) { -%>
93-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections) %>;
93+
<% const propertyName = strict ? toCamelCase(attribute.key) : attribute.key; -%>
94+
<% const isValidIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(propertyName); -%>
95+
<% if (isValidIdentifier) { %><%- propertyName %><% } else { %>"<%- propertyName %>"<% } %>: <%- getType(attribute, collections) %>;
9496
<% } -%>
9597
}<% if (index < collections.length - 1) { %>
9698
<% } %>

0 commit comments

Comments
 (0)