Skip to content

Commit 35e3933

Browse files
committed
align tovar name with generator
Signed-off-by: xil <fridalu66@gmail.com>
1 parent 4587292 commit 35e3933

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

tools/proto-convert/src/postprocessing/CompatibilityMerger.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,23 @@ function isVersionedName(name: string): boolean {
130130
}
131131

132132
/**
133-
* Convert PascalCase/camelCase type name to snake_case.
134-
* e.g., "TermsAggregation" -> "terms_aggregation"
133+
* Convert a name to snake_case variable name format.
135134
*/
136-
function toSnakeCase(typeName: string): string {
137-
return typeName
138-
.replace(/([A-Z])/g, '_$1')
139-
.toLowerCase()
140-
.replace(/^_/, '');
135+
function toVarName(name: string): string {
136+
name = name.replace(/^_+/, '');
137+
138+
return name
139+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
140+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
141+
.replace(/(\d)([A-Za-z])/g, '$1_$2')
142+
.toLowerCase();
141143
}
142144

143145
/**
144146
* Check if field name is the formatted (snake_case) version of the type name.
145147
*/
146148
function isFormattedName(fieldName: string, typeName: string): boolean {
147-
return fieldName === toSnakeCase(typeName);
149+
return fieldName === toVarName(typeName);
148150
}
149151

150152
/** Check if message has any oneof with fields */

0 commit comments

Comments
 (0)