Skip to content

Commit 8378345

Browse files
committed
Allow all selectors after unknown pseudo elements
#495
1 parent fabb2c9 commit 8378345

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

selectors/parser.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ pub trait PseudoElement<'i>: Sized + ToCss {
4444
fn is_view_transition(&self) -> bool {
4545
false
4646
}
47+
48+
fn is_unknown(&self) -> bool {
49+
false
50+
}
4751
}
4852

4953
/// A trait that represents a pseudo-class.
@@ -2600,7 +2604,10 @@ where
26002604
builder.push_simple_selector(Component::Slotted(selector));
26012605
}
26022606
SimpleSelectorParseResult::PseudoElement(p) => {
2607+
if !p.is_unknown() {
26032608
state.insert(SelectorParsingState::AFTER_PSEUDO_ELEMENT);
2609+
builder.push_combinator(Combinator::PseudoElement);
2610+
}
26042611
if !p.accepts_state_pseudo_classes() {
26052612
state.insert(SelectorParsingState::AFTER_NON_STATEFUL_PSEUDO_ELEMENT);
26062613
}
@@ -2610,7 +2617,6 @@ where
26102617
if p.is_view_transition() {
26112618
state.insert(SelectorParsingState::AFTER_VIEW_TRANSITION);
26122619
}
2613-
builder.push_combinator(Combinator::PseudoElement);
26142620
builder.push_simple_selector(Component::PseudoElement(p));
26152621
}
26162622
}

src/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -6668,6 +6668,19 @@ mod tests {
66686668
ParserError::SelectorError(SelectorError::InvalidState),
66696669
);
66706670
}
6671+
6672+
minify_test(".foo ::deep .bar {width: 20px}", ".foo ::deep .bar{width:20px}");
6673+
minify_test(".foo::deep .bar {width: 20px}", ".foo::deep .bar{width:20px}");
6674+
minify_test(".foo ::deep.bar {width: 20px}", ".foo ::deep.bar{width:20px}");
6675+
minify_test(".foo ::unknown .bar {width: 20px}", ".foo ::unknown .bar{width:20px}");
6676+
minify_test(
6677+
".foo ::unknown(foo) .bar {width: 20px}",
6678+
".foo ::unknown(foo) .bar{width:20px}",
6679+
);
6680+
minify_test(
6681+
".foo ::unknown:only-child {width: 20px}",
6682+
".foo ::unknown:only-child{width:20px}",
6683+
);
66716684
}
66726685

66736686
#[test]

src/selector.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,13 @@ impl<'i> parcel_selectors::parser::PseudoElement<'i> for PseudoElement<'i> {
11311131
| PseudoElement::ViewTransitionOld { .. }
11321132
)
11331133
}
1134+
1135+
fn is_unknown(&self) -> bool {
1136+
matches!(
1137+
*self,
1138+
PseudoElement::Custom { .. } | PseudoElement::CustomFunction { .. },
1139+
)
1140+
}
11341141
}
11351142

11361143
impl<'i> PseudoElement<'i> {

0 commit comments

Comments
 (0)