Skip to content

Commit 623c66b

Browse files
committed
Refactor border property retrieval logic
Introduced getBorderItem to centralize and simplify retrieval of border property items in prepareBorderProperties. This reduces code duplication and improves maintainability.
1 parent 75fc72e commit 623c66b

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lib/normalize.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@ const getPropertyItem = (property, properties) => {
112112
return propertyItem;
113113
};
114114

115+
/**
116+
* Retrieves a property item from borderItems, properties, or creates a new one.
117+
* Prioritizes borderItems (processed items) over properties (existing items).
118+
*
119+
* @param {string} property - The name of the property.
120+
* @param {Map} borderItems - The map containing processed border items.
121+
* @param {Map} properties - The map containing all properties.
122+
* @returns {Object} The property item.
123+
*/
124+
const getBorderItem = (property, borderItems, properties) => {
125+
return borderItems.get(property) ?? properties.get(property) ?? createPropertyItem(property);
126+
};
127+
115128
/**
116129
* Calculates the value for a specific position (top, right, bottom, left)
117130
* based on the array of values provided for a shorthand property.
@@ -1030,29 +1043,20 @@ const prepareBorderProperties = (property, value, priority, properties, opt = {}
10301043
const borderProps = new Map([[BORDER, borderItems.get(BORDER)]]);
10311044
for (const line of borderLines) {
10321045
const lineProperty = `${BORDER}-${line}`;
1033-
const lineItem =
1034-
borderItems.get(lineProperty) ??
1035-
properties.get(lineProperty) ??
1036-
createPropertyItem(lineProperty);
1046+
const lineItem = getBorderItem(lineProperty, borderItems, properties);
10371047
borderProps.set(lineProperty, lineItem);
10381048
}
10391049
for (const position of borderPositions) {
10401050
const positionProperty = `${BORDER}-${position}`;
1041-
const positionItem =
1042-
borderItems.get(positionProperty) ??
1043-
properties.get(positionProperty) ??
1044-
createPropertyItem(positionProperty);
1051+
const positionItem = getBorderItem(positionProperty, borderItems, properties);
10451052
borderProps.set(positionProperty, positionItem);
10461053
for (const line of borderLines) {
10471054
const longhandProperty = `${BORDER}-${position}-${line}`;
1048-
const longhandItem =
1049-
borderItems.get(longhandProperty) ??
1050-
properties.get(longhandProperty) ??
1051-
createPropertyItem(longhandProperty);
1055+
const longhandItem = getBorderItem(longhandProperty, borderItems, properties);
10521056
borderProps.set(longhandProperty, longhandItem);
10531057
}
10541058
}
1055-
const borderImageItem = borderItems.get(BORDER_IMAGE) ?? createPropertyItem(BORDER_IMAGE);
1059+
const borderImageItem = getBorderItem(BORDER_IMAGE, borderItems, properties);
10561060
borderProps.set(BORDER_IMAGE, borderImageItem);
10571061
return borderProps;
10581062
};

0 commit comments

Comments
 (0)