Skip to content

Commit 77fd67f

Browse files
Expose old names directly for Darwin codegen. (#869)
* Expose old names directly for Darwin codegen. Also adds a way to check whether a field in a container has been renamed. * Fix code coverage failure
1 parent 4f12354 commit 77fd67f

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ module.exports = {
6262
'/node_modules/',
6363
'<rootDir>/test/download-artifact.test.js',
6464
],
65+
coveragePathIgnorePatterns: [
66+
'/node_modules/',
67+
'<rootDir>/src-electron/generator/matter/darwin/Framework/CHIP/templates/helper.js',
68+
],
6569
}

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ function oldName(cluster, options) {
207207
return findDataForPath(data, ['renames', ...path]);
208208
}
209209

210+
function hasOldName(cluster, options) {
211+
return oldName.call(this, cluster, options) !== undefined;
212+
}
213+
210214
async function asObjectiveCClass(type, cluster, options) {
211215
let pkgIds = await templateUtil.ensureZclPackageIds(this);
212216
let isStruct = await zclHelper
@@ -742,6 +746,50 @@ function wasRemoved(cluster, options) {
742746
return removedRelease !== undefined;
743747
}
744748

749+
function hasRenamedFields(cluster, options) {
750+
const data = fetchAvailabilityData(this.global);
751+
// Try to minimize duplication by reusing existing path-construction and
752+
// manipulation bits. Just use dummy values for the leaf we're going to
753+
// remove.
754+
let hashAddition;
755+
if (options.hash.struct) {
756+
hashAddition = {
757+
structField: "dummy"
758+
};
759+
} else if (options.hash.event) {
760+
hashAddition = {
761+
eventField: "dummy"
762+
};
763+
} else if (options.hash.command) {
764+
hashAddition = {
765+
commandField: "dummy"
766+
};
767+
} else if (options.hash.enum) {
768+
hashAddition = {
769+
enumValue: "dummy"
770+
};
771+
} else if (options.hash.bitmap) {
772+
hashAddition = {
773+
bitmapValue: "dummy"
774+
};
775+
} else {
776+
throw new Error(`hasRenamedFields called for a non-container object: ${cluster} '${JSON.stringfify(options.hash)}'`);
777+
}
778+
779+
let path = makeAvailabilityPath(cluster, {
780+
hash: {
781+
...options.hash, ...hashAddition
782+
}
783+
});
784+
785+
// Now strip off the last bit of the path, so we're just checking for any
786+
// renames in our container.
787+
path.pop();
788+
789+
return findDataForPath(data, [ 'renames', ...path ]) !== undefined;
790+
791+
}
792+
745793
function and() {
746794
let args = [...arguments];
747795
// Strip off the options arg.
@@ -845,6 +893,9 @@ exports.async_if = async_if;
845893
exports.async_and = async_and;
846894
exports.async_or = async_or;
847895
exports.async_not = async_not;
896+
exports.oldName = oldName;
897+
exports.hasOldName = hasOldName;
898+
exports.hasRenamedFields = hasRenamedFields;
848899

849900
exports.meta = {
850901
category: dbEnum.helperCategory.matter,

0 commit comments

Comments
 (0)