From 0586aaa718bec1dbc77e276f72da66574069c415 Mon Sep 17 00:00:00 2001 From: Johannes Odland Date: Sat, 12 Oct 2024 15:12:16 +0200 Subject: [PATCH] Refactor type comparison logic in addTypes function --- src/numeric-values.js | 8 ++++++-- test/unit/cssom/css-numeric-value-type.test.js | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/numeric-values.js b/src/numeric-values.js index 16af704..dbc26d8 100644 --- a/src/numeric-values.js +++ b/src/numeric-values.js @@ -490,7 +490,9 @@ export function addTypes(input1, input2) { // 3a If all the entries of type1 with non-zero values are contained in type2 with the same value, and vice-versa // Copy all of type1’s entries to finalType, and then copy all of type2’s entries to finalType that // finalType doesn’t already contain. Set finalType’s percent hint to type1’s percent hint. Return finalType. - if (!baseTypes.some(baseType => (type1[baseType] || type2[baseType]) && type1[baseType] !== type2[baseType])) { + if (baseTypes + .filter(baseType=> type1[baseType] || type2[baseType]) + .every(baseType => type1[baseType] === type2[baseType])) { return { ...type2, ...type1, @@ -517,7 +519,9 @@ export function addTypes(input1, input2) { // If, afterwards, all the entries of type1 with non-zero values are contained in type2 with the same value, // and vice versa, then copy all of type1’s entries to finalType, and then copy all of type2’s entries to // finalType that finalType doesn’t already contain. Set finalType’s percent hint to hint. Return finalType. - if (!baseTypes.some(baseType => (tempType1[baseType] || tempType2[baseType]) && tempType1[baseType] !== tempType2[baseType])) { + if (baseTypes + .filter(baseType => tempType1[baseType] || tempType2[baseType]) + .every(baseType => tempType1[baseType] === tempType2[baseType])) { return { ...tempType2, ...tempType1, diff --git a/test/unit/cssom/css-numeric-value-type.test.js b/test/unit/cssom/css-numeric-value-type.test.js index c2277e6..e671318 100644 --- a/test/unit/cssom/css-numeric-value-type.test.js +++ b/test/unit/cssom/css-numeric-value-type.test.js @@ -86,7 +86,7 @@ describe('CSSNumericValue.type()', () => { ]; for (const [unitA, unitB, type] of compatibleTuples) { - test(`Type of CSSMathSum of '${unitA}' and '${unitB}' is '${type}'`, () => { + test(`Type of CSSMathSum of '${unitA}' and '${unitB}' is '${JSON.stringify(type)}'`, () => { expect(new CSSMathSum(new CSSUnitValue(10, unitA), new CSSUnitValue(10, unitB)).type()).toEqual(type); }); } @@ -100,7 +100,7 @@ describe('CSSNumericValue.type()', () => { ['percent', 'fr', {flex: 1, percentHint: 'flex'}], // ]; for (const [unitA, unitB, type] of percentHintTuples) { - test(`Type of CSSMathSum of '${unitA}' and '${unitB}' is '${type}'`, () => { + test(`Type of CSSMathSum of '${unitA}' and '${unitB}' is '${JSON.stringify(type)}'`, () => { expect(new CSSMathSum(new CSSUnitValue(10, unitA), new CSSUnitValue(10, unitB)).type()).toEqual(type); }); }