Skip to content

Commit b14728f

Browse files
samcconeljharb
authored andcommitted
Remove deep-equal-json as a dep from the project (#357)
Inspection of the code and types showed that the actual check does not need to handle all cases, but rather there is a small handful of attributes and cases to check. As such do it in the project and remove the entire need for a dep. Ref: #354
1 parent 23033c3 commit b14728f

File tree

5 files changed

+49
-14
lines changed

5 files changed

+49
-14
lines changed

__tests__/src/elementAXObjectMap-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test('elementAXObjectMap', async (t) => {
8585
t.test('iteration', (st) => {
8686

8787
st.notEqual(elementAXObjectMap[Symbol.iterator], undefined, 'has an iterator defined');
88-
st.equal([...elementAXObjectMap].length, 70, 'has a specific length');
88+
st.equal([...elementAXObjectMap].length, 71, 'has a specific length');
8989

9090
st.test('supports the spread operator', async (s2t) => {
9191
[...elementAXObjectMap].forEach(([role, elements]) => {

flow/deep-equal-json.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

package-lock.json

Lines changed: 20 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@babel/preset-flow": "^7.18.6",
4040
"@babel/register": "^7.24.6",
4141
"babel-plugin-module-resolver": "^5.0.2",
42+
"deep-equal-json": "^1.0.0",
4243
"encoding": "^0.1.13",
4344
"eslint": "^8.26.0",
4445
"eslint-config-airbnb-base": "^15.0.0",
@@ -60,9 +61,6 @@
6061
"not op_mini all",
6162
"ie 11"
6263
],
63-
"dependencies": {
64-
"deep-equal-json": "^1.0.0"
65-
},
6664
"engines": {
6765
"node": ">= 0.4"
6866
}

src/elementAXObjectMap.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @flow
33
*/
44

5-
import deepEqual from 'deep-equal-json';
65
import AXObjects from './AXObjectsMap';
76
import iterationDecorator from './util/iterationDecorator';
87

@@ -48,6 +47,32 @@ for (let [name, def] of AXObjects.entries()) {
4847
}
4948
}
5049

50+
function deepAxObjectModelRelationshipConceptAttributeCheck(a?: Array<AXObjectModelRelationConceptAttribute>, b?: Array<AXObjectModelRelationConceptAttribute>) {
51+
if (a === undefined && b !== undefined) {
52+
return false;
53+
}
54+
55+
if (a !== undefined && b === undefined) {
56+
return false;
57+
}
58+
59+
if (a !== undefined && b !== undefined) {
60+
if (a.length != b.length) {
61+
return false;
62+
}
63+
64+
// dequal checks position equality
65+
// https://github.com/lukeed/dequal/blob/5ecd990c4c055c4658c64b4bdfc170f219604eea/src/index.js#L17-L22
66+
for (let i = 0; i < a.length; i++) {
67+
if (b[i].name !== a[i].name || b[i].value !== a[i].value) {
68+
return false;
69+
}
70+
}
71+
}
72+
73+
return true;
74+
}
75+
5176
const elementAXObjectMap: TAXObjectQueryMap<
5277
TElementAXObjects,
5378
AXObjectModelRelationConcept,
@@ -66,7 +91,7 @@ const elementAXObjectMap: TAXObjectQueryMap<
6691
},
6792
get: function (key: AXObjectModelRelationConcept): ?Array<AXObjectName> {
6893
const item = elementAXObjects.find(tuple => (
69-
key.name === tuple[0].name && deepEqual(key.attributes, tuple[0].attributes)
94+
key.name === tuple[0].name && deepAxObjectModelRelationshipConceptAttributeCheck(key.attributes, tuple[0].attributes)
7095
));
7196
return item && item[1];
7297
},

0 commit comments

Comments
 (0)