Skip to content

Commit 3d183de

Browse files
committed
Update normalize.js
1 parent 9e2adad commit 3d183de

File tree

2 files changed

+45
-23
lines changed

2 files changed

+45
-23
lines changed

lib/normalize.js

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@ const font = require("./properties/font");
1616
const margin = require("./properties/margin");
1717
const padding = require("./properties/padding");
1818

19+
const BACKGROUND = "background"
1920
const BORDER = "border";
21+
const BORDER_BOTTOM = "border-bottom";
22+
const BORDER_COLOR = "border-color";
2023
const BORDER_IMAGE = "border-image";
24+
const BORDER_LEFT = "border-left";
25+
const BORDER_RIGHT = "border-right";
26+
const BORDER_STYLE = "border-style";
27+
const BORDER_TOP = "border-top";
28+
const BORDER_WIDTH = "border-width";
2129
const TOP = "top";
2230
const RIGHT = "right";
2331
const BOTTOM = "bottom";
@@ -28,7 +36,7 @@ const COLOR = "color";
2836
const NONE = "none";
2937

3038
const shorthandProperties = new Map([
31-
["background", background],
39+
[BACKGROUND, background],
3240
[
3341
BORDER,
3442
{
@@ -41,13 +49,13 @@ const shorthandProperties = new Map([
4149
])
4250
}
4351
],
44-
["border-width", borderWidth],
45-
["border-style", borderStyle],
46-
["border-color", borderColor],
47-
["border-top", borderTop],
48-
["border-right", borderRight],
49-
["border-bottom", borderBottom],
50-
["border-left", borderLeft],
52+
[BORDER_WIDTH, borderWidth],
53+
[BORDER_STYLE, borderStyle],
54+
[BORDER_COLOR, borderColor],
55+
[BORDER_TOP, borderTop],
56+
[BORDER_RIGHT, borderRight],
57+
[BORDER_BOTTOM, borderBottom],
58+
[BORDER_LEFT, borderLeft],
5159
["flex", flex],
5260
["font", font],
5361
["margin", margin],
@@ -970,45 +978,45 @@ const prepareBorderShorthands = (properties) => {
970978
}
971979
}
972980
if (lineWidthItems.size === 4) {
973-
const [property, item] = generateBorderLineShorthand(lineWidthItems, "border-width") ?? [];
981+
const [property, item] = generateBorderLineShorthand(lineWidthItems, BORDER_WIDTH) ?? [];
974982
if (property && item) {
975983
properties.set(property, item);
976984
}
977985
} else if (lineWidthPriorItems.size === 4) {
978986
const [property, item] =
979-
generateBorderLineShorthand(lineWidthPriorItems, "border-width", "important") ?? [];
987+
generateBorderLineShorthand(lineWidthPriorItems, BORDER_WIDTH, "important") ?? [];
980988
if (property && item) {
981989
properties.set(property, item);
982990
}
983991
}
984992
if (lineStyleItems.size === 4) {
985-
const [property, item] = generateBorderLineShorthand(lineStyleItems, "border-style") ?? [];
993+
const [property, item] = generateBorderLineShorthand(lineStyleItems, BORDER_STYLE) ?? [];
986994
if (property && item) {
987995
properties.set(property, item);
988996
}
989997
} else if (lineStylePriorItems.size === 4) {
990998
const [property, item] =
991-
generateBorderLineShorthand(lineStylePriorItems, "border-style", "important") ?? [];
999+
generateBorderLineShorthand(lineStylePriorItems, BORDER_STYLE, "important") ?? [];
9921000
if (property && item) {
9931001
properties.set(property, item);
9941002
}
9951003
}
9961004
if (lineColorItems.size === 4) {
997-
const [property, item] = generateBorderLineShorthand(lineColorItems, "border-color") ?? [];
1005+
const [property, item] = generateBorderLineShorthand(lineColorItems, BORDER_COLOR) ?? [];
9981006
if (property && item) {
9991007
properties.set(property, item);
10001008
}
10011009
} else if (lineColorPriorItems.size === 4) {
10021010
const [property, item] =
1003-
generateBorderLineShorthand(lineColorPriorItems, "border-color", "important") ?? [];
1011+
generateBorderLineShorthand(lineColorPriorItems, BORDER_COLOR, "important") ?? [];
10041012
if (property && item) {
10051013
properties.set(property, item);
10061014
}
10071015
}
10081016
const nameItems = [];
10091017
const namePriorItems = [];
10101018
if (positionTopItems.size === 3) {
1011-
const [property, item] = generateBorderPositionShorthand(positionTopItems, "border-top") ?? [];
1019+
const [property, item] = generateBorderPositionShorthand(positionTopItems, BORDER_TOP) ?? [];
10121020
if (property && item) {
10131021
properties.set(property, item);
10141022
if (properties.has(BORDER_IMAGE)) {
@@ -1021,7 +1029,7 @@ const prepareBorderShorthands = (properties) => {
10211029
}
10221030
} else if (positionTopPriorItems.size === 3) {
10231031
const [property, item] =
1024-
generateBorderPositionShorthand(positionTopPriorItems, "border-top", "important") ?? [];
1032+
generateBorderPositionShorthand(positionTopPriorItems, BORDER_TOP, "important") ?? [];
10251033
if (property && item) {
10261034
properties.set(property, item);
10271035
if (properties.has(BORDER_IMAGE)) {
@@ -1035,7 +1043,7 @@ const prepareBorderShorthands = (properties) => {
10351043
}
10361044
if (positionRightItems.size === 3) {
10371045
const [property, item] =
1038-
generateBorderPositionShorthand(positionRightItems, "border-right") ?? [];
1046+
generateBorderPositionShorthand(positionRightItems, BORDER_RIGHT) ?? [];
10391047
if (property && item) {
10401048
properties.set(property, item);
10411049
if (properties.has(BORDER_IMAGE)) {
@@ -1048,7 +1056,7 @@ const prepareBorderShorthands = (properties) => {
10481056
}
10491057
} else if (positionRightPriorItems.size === 3) {
10501058
const [property, item] =
1051-
generateBorderPositionShorthand(positionRightPriorItems, "border-right", "important") ?? [];
1059+
generateBorderPositionShorthand(positionRightPriorItems, BORDER_RIGHT, "important") ?? [];
10521060
if (property && item) {
10531061
properties.set(property, item);
10541062
if (properties.has(BORDER_IMAGE)) {
@@ -1062,7 +1070,7 @@ const prepareBorderShorthands = (properties) => {
10621070
}
10631071
if (positionBottomItems.size === 3) {
10641072
const [property, item] =
1065-
generateBorderPositionShorthand(positionBottomItems, "border-bottom") ?? [];
1073+
generateBorderPositionShorthand(positionBottomItems, BORDER_BOTTOM) ?? [];
10661074
if (property && item) {
10671075
properties.set(property, item);
10681076
if (properties.has(BORDER_IMAGE)) {
@@ -1075,7 +1083,7 @@ const prepareBorderShorthands = (properties) => {
10751083
}
10761084
} else if (positionBottomPriorItems.size === 3) {
10771085
const [property, item] =
1078-
generateBorderPositionShorthand(positionBottomPriorItems, "border-bottom", "important") ?? [];
1086+
generateBorderPositionShorthand(positionBottomPriorItems, BORDER_BOTTOM, "important") ?? [];
10791087
if (property && item) {
10801088
properties.set(property, item);
10811089
if (properties.has(BORDER_IMAGE)) {
@@ -1089,7 +1097,7 @@ const prepareBorderShorthands = (properties) => {
10891097
}
10901098
if (positionLeftItems.size === 3) {
10911099
const [property, item] =
1092-
generateBorderPositionShorthand(positionLeftItems, "border-left") ?? [];
1100+
generateBorderPositionShorthand(positionLeftItems, BORDER_LEFT) ?? [];
10931101
if (property && item) {
10941102
properties.set(property, item);
10951103
if (properties.has(BORDER_IMAGE)) {
@@ -1102,7 +1110,7 @@ const prepareBorderShorthands = (properties) => {
11021110
}
11031111
} else if (positionLeftPriorItems.size === 3) {
11041112
const [property, item] =
1105-
generateBorderPositionShorthand(positionLeftPriorItems, "border-left", "important") ?? [];
1113+
generateBorderPositionShorthand(positionLeftPriorItems, BORDER_LEFT, "important") ?? [];
11061114
if (property && item) {
11071115
properties.set(property, item);
11081116
if (properties.has(BORDER_IMAGE)) {
@@ -1248,7 +1256,13 @@ const prepareProperties = (properties, opt = {}) => {
12481256
}
12491257
}
12501258
if (!omitShorthandProperty) {
1251-
parsedProperties.set(property, { property, value, priority });
1259+
if (property === BACKGROUND) {
1260+
if (priority) {
1261+
parsedProperties.set(property, { property, value, priority });
1262+
}
1263+
} else {
1264+
parsedProperties.set(property, { property, value, priority });
1265+
}
12521266
}
12531267
} else {
12541268
parsedProperties.set(property, { property, value, priority });

test/CSSStyleProperties.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,3 +1525,11 @@ describe("regression test for https://github.com/jsdom/cssstyle/issues/214", ()
15251525
assert.strictEqual(style.getPropertyPriority("word-spacing"), "important", "priority");
15261526
});
15271527
});
1528+
1529+
describe("regression test for https://github.com/jsdom/jsdom/issues/3944", () => {
1530+
it("should get overwritten value", () => {
1531+
const style = new CSSStyleProperties();
1532+
style.cssText = "background:linear-gradient(rgb(0 0 255 / 0.5), rgb(255 255 0 / 0.5)) center center;background-position:top;";
1533+
assert.strictEqual(style.backgroundPosition, "center top");
1534+
});
1535+
});

0 commit comments

Comments
 (0)