Skip to content

Commit 3705035

Browse files
asamuzaKdomenic
authored andcommitted
Refactor priority calculation for property setters
Simplifies and unifies the logic for determining the priority argument in property setters across background, border, flex, font, margin, and padding property modules. The new approach uses a single conditional to check shorthand and property priorities, improving code clarity and maintainability.
1 parent e337088 commit 3705035

44 files changed

Lines changed: 176 additions & 144 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/properties/backgroundAttachment.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ module.exports.definition = {
4949
globalObject: this._global
5050
});
5151
if (typeof val === "string") {
52-
const shorthandPriority = this._priorities.get(shorthand);
53-
const prior = this._priorities.get(property) ?? "";
54-
const priority = shorthandPriority && prior ? "" : prior;
52+
const priority =
53+
!this._priorities.get(shorthand) && this._priorities.has(property)
54+
? this._priorities.get(property)
55+
: "";
5556
this._setProperty(property, val, priority);
5657
}
5758
}

lib/properties/backgroundClip.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ module.exports.definition = {
4949
globalObject: this._global
5050
});
5151
if (typeof val === "string") {
52-
const shorthandPriority = this._priorities.get(shorthand);
53-
const prior = this._priorities.get(property) ?? "";
54-
const priority = shorthandPriority && prior ? "" : prior;
52+
const priority =
53+
!this._priorities.get(shorthand) && this._priorities.has(property)
54+
? this._priorities.get(property)
55+
: "";
5556
this._setProperty(property, val, priority);
5657
}
5758
}

lib/properties/backgroundColor.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ module.exports.definition = {
4040
globalObject: this._global
4141
});
4242
if (typeof val === "string") {
43-
const shorthandPriority = this._priorities.get(shorthand);
44-
const prior = this._priorities.get(property) ?? "";
45-
const priority = shorthandPriority && prior ? "" : prior;
43+
const priority =
44+
!this._priorities.get(shorthand) && this._priorities.has(property)
45+
? this._priorities.get(property)
46+
: "";
4647
this._setProperty(property, val, priority);
4748
}
4849
}

lib/properties/backgroundImage.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ module.exports.definition = {
6363
globalObject: this._global
6464
});
6565
if (typeof val === "string") {
66-
const shorthandPriority = this._priorities.get(shorthand);
67-
const prior = this._priorities.get(property) ?? "";
68-
const priority = shorthandPriority && prior ? "" : prior;
66+
const priority =
67+
!this._priorities.get(shorthand) && this._priorities.has(property)
68+
? this._priorities.get(property)
69+
: "";
6970
this._setProperty(property, val, priority);
7071
}
7172
}

lib/properties/backgroundOrigin.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ module.exports.definition = {
4949
globalObject: this._global
5050
});
5151
if (typeof val === "string") {
52-
const shorthandPriority = this._priorities.get(shorthand);
53-
const prior = this._priorities.get(property) ?? "";
54-
const priority = shorthandPriority && prior ? "" : prior;
52+
const priority =
53+
!this._priorities.get(shorthand) && this._priorities.has(property)
54+
? this._priorities.get(property)
55+
: "";
5556
this._setProperty(property, val, priority);
5657
}
5758
}

lib/properties/backgroundPosition.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ module.exports.definition = {
178178
globalObject: this._global
179179
});
180180
if (typeof val === "string") {
181-
const shorthandPriority = this._priorities.get(shorthand);
182-
const prior = this._priorities.get(property) ?? "";
183-
const priority = shorthandPriority && prior ? "" : prior;
181+
const priority =
182+
!this._priorities.get(shorthand) && this._priorities.has(property)
183+
? this._priorities.get(property)
184+
: "";
184185
this._setProperty(property, val, priority);
185186
}
186187
}

lib/properties/backgroundRepeat.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ module.exports.definition = {
7474
globalObject: this._global
7575
});
7676
if (typeof val === "string") {
77-
const shorthandPriority = this._priorities.get(shorthand);
78-
const prior = this._priorities.get(property) ?? "";
79-
const priority = shorthandPriority && prior ? "" : prior;
77+
const priority =
78+
!this._priorities.get(shorthand) && this._priorities.has(property)
79+
? this._priorities.get(property)
80+
: "";
8081
this._setProperty(property, val, priority);
8182
}
8283
}

lib/properties/backgroundSize.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ module.exports.definition = {
105105
globalObject: this._global
106106
});
107107
if (typeof val === "string") {
108-
const shorthandPriority = this._priorities.get(shorthand);
109-
const prior = this._priorities.get(property) ?? "";
110-
const priority = shorthandPriority && prior ? "" : prior;
108+
const priority =
109+
!this._priorities.get(shorthand) && this._priorities.has(property)
110+
? this._priorities.get(property)
111+
: "";
111112
this._setProperty(property, val, priority);
112113
}
113114
}

lib/properties/borderBottom.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ module.exports.definition = {
141141
globalObject: this._global
142142
});
143143
if (val || typeof val === "string") {
144-
const shorthandPriority = this._priorities.get(shorthand);
145-
const prior = this._priorities.get(property) ?? "";
146-
const priority = shorthandPriority && prior ? "" : prior;
144+
const priority =
145+
!this._priorities.get(shorthand) && this._priorities.has(property)
146+
? this._priorities.get(property)
147+
: "";
147148
this._borderSetter(property, val, priority);
148149
}
149150
}

lib/properties/borderBottomColor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ module.exports.definition = {
4444
const shorthandPriority = this._priorities.get(shorthand);
4545
const linePriority = this._priorities.get(lineShorthand);
4646
const positionPriority = this._priorities.get(positionShorthand);
47-
let priority = this._priorities.get(property) ?? "";
48-
if ((shorthandPriority || linePriority || positionPriority) && priority) {
49-
priority = "";
50-
}
47+
const priority =
48+
!(shorthandPriority || linePriority || positionPriority) && this._priorities.has(property)
49+
? this._priorities.get(property)
50+
: "";
5151
this._borderSetter(property, val, priority);
5252
}
5353
}

0 commit comments

Comments
 (0)