Skip to content

Commit e74dd35

Browse files
Fix asStructPropertyName to handle pluralized acronyms better. (#1583)
The old code turned "URLs" into "urLs". The new thing turns it into "urls".
1 parent 4aaa973 commit e74dd35

File tree

1 file changed

+16
-3
lines changed
  • src-electron/generator/matter/darwin/Framework/CHIP/templates

1 file changed

+16
-3
lines changed

src-electron/generator/matter/darwin/Framework/CHIP/templates/helper.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,20 @@ async function asObjectiveCType(type, cluster, options) {
312312
}
313313

314314
function asStructPropertyName(prop) {
315-
prop = appHelper.asLowerCamelCase(prop);
315+
prop = appHelper.asLowerCamelCase(prop, { hash: { preserveAcronyms: true } });
316+
317+
// If prop is now all-uppercase (which can happen, because we are preserving
318+
// acronyms), lowercase it.
319+
if (prop.match(/^[A-Z0-9]+$/)) {
320+
prop = prop.toLowerCase();
321+
}
322+
323+
// If prop is now all-uppercase, with at least two capital letters followed by
324+
// a lowercase "s" (probably acronym being pluralized), just lowercase the
325+
// whole thing.
326+
if (prop.match(/^[A-Z][A-Z]+s$/)) {
327+
prop = prop.toLowerCase();
328+
}
316329

317330
// If prop is now "description", we need to rename it, because that's
318331
// reserved.
@@ -322,8 +335,8 @@ function asStructPropertyName(prop) {
322335

323336
// If prop starts with a sequence of capital letters (which can happen for
324337
// output of asLowerCamelCase if the original string started that way),
325-
// lowercase all but the last one.
326-
return prop.replace(/^([A-Z]+)([A-Z])/, (match, p1, p2) => {
338+
// followed by a lowercase letter, lowercase all but the last capital letter.
339+
return prop.replace(/^([A-Z]+)([A-Z][a-z])/, (match, p1, p2) => {
327340
return p1.toLowerCase() + p2;
328341
});
329342
}

0 commit comments

Comments
 (0)