Skip to content

Commit 1a2a0cf

Browse files
committed
Use physical properties when inline logical properties are equal
Fixes parcel-bundler#201
1 parent 1b3d471 commit 1a2a0cf

File tree

2 files changed

+96
-4
lines changed

2 files changed

+96
-4
lines changed

src/lib.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,82 @@ mod tests {
10421042
},
10431043
);
10441044

1045+
prefix_test(
1046+
r#"
1047+
.foo {
1048+
border-inline-width: 2px;
1049+
}
1050+
"#,
1051+
indoc! {r#"
1052+
.foo {
1053+
border-left-width: 2px;
1054+
border-right-width: 2px;
1055+
}
1056+
"#
1057+
},
1058+
Browsers {
1059+
safari: Some(8 << 16),
1060+
..Browsers::default()
1061+
},
1062+
);
1063+
1064+
prefix_test(
1065+
r#"
1066+
.foo {
1067+
border-inline-width: 2px;
1068+
}
1069+
"#,
1070+
indoc! {r#"
1071+
.foo {
1072+
border-left-width: 2px;
1073+
border-right-width: 2px;
1074+
}
1075+
"#
1076+
},
1077+
Browsers {
1078+
safari: Some(8 << 16),
1079+
..Browsers::default()
1080+
},
1081+
);
1082+
1083+
prefix_test(
1084+
r#"
1085+
.foo {
1086+
border-inline-style: solid;
1087+
}
1088+
"#,
1089+
indoc! {r#"
1090+
.foo {
1091+
border-left-style: solid;
1092+
border-right-style: solid;
1093+
}
1094+
"#
1095+
},
1096+
Browsers {
1097+
safari: Some(8 << 16),
1098+
..Browsers::default()
1099+
},
1100+
);
1101+
1102+
prefix_test(
1103+
r#"
1104+
.foo {
1105+
border-inline-color: red;
1106+
}
1107+
"#,
1108+
indoc! {r#"
1109+
.foo {
1110+
border-left-color: red;
1111+
border-right-color: red;
1112+
}
1113+
"#
1114+
},
1115+
Browsers {
1116+
safari: Some(8 << 16),
1117+
..Browsers::default()
1118+
},
1119+
);
1120+
10451121
prefix_test(
10461122
r#"
10471123
.foo {

src/properties/border.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,10 +1146,26 @@ impl<'i> BorderHandler<'i> {
11461146
prop!(BorderRight => $inline_start.to_border());
11471147
}
11481148
} else {
1149-
if $is_logical && logical_supported && !$inline_start.is_valid() && !$inline_end.is_valid() {
1150-
logical_shorthand!(BorderInlineStyle, style, $inline_start, $inline_end);
1151-
logical_shorthand!(BorderInlineWidth, width, $inline_start, $inline_end);
1152-
logical_shorthand!(BorderInlineColor, color, $inline_start, $inline_end);
1149+
if $is_logical && !$inline_start.is_valid() && !$inline_end.is_valid() {
1150+
if logical_supported {
1151+
logical_shorthand!(BorderInlineStyle, style, $inline_start, $inline_end);
1152+
logical_shorthand!(BorderInlineWidth, width, $inline_start, $inline_end);
1153+
logical_shorthand!(BorderInlineColor, color, $inline_start, $inline_end);
1154+
} else {
1155+
// If both values of an inline logical property are equal, then we can just convert them to physical properties.
1156+
macro_rules! inline_prop {
1157+
($key: ident, $left: ident, $right: ident) => {
1158+
if $inline_start.$key.is_some() && $inline_start.$key == $inline_end.$key {
1159+
prop!($left => std::mem::take(&mut $inline_start.$key).unwrap());
1160+
prop!($right => std::mem::take(&mut $inline_end.$key).unwrap());
1161+
}
1162+
}
1163+
}
1164+
1165+
inline_prop!(style, BorderLeftStyle, BorderRightStyle);
1166+
inline_prop!(width, BorderLeftWidth, BorderRightWidth);
1167+
inline_prop!(color, BorderLeftColor, BorderRightColor);
1168+
}
11531169
}
11541170

11551171
side!($inline_start, $inline_start_prop, $inline_start_width, $inline_start_style, $inline_start_color);

0 commit comments

Comments
 (0)