Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc6ed6b
commit 1f94210
Showing
6 changed files
with
272 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use swc_atoms::js_word; | ||
use swc_css_ast::{ | ||
CompoundSelector, PseudoClassSelector, PseudoClassSelectorChildren, SelectorList, | ||
SubclassSelector, | ||
}; | ||
|
||
use crate::compiler::Compiler; | ||
|
||
impl Compiler { | ||
pub(crate) fn process_selector_not(&mut self, n: &mut CompoundSelector) { | ||
let has_not = n.subclass_selectors.iter().any(|n| matches!(n, SubclassSelector::PseudoClass(PseudoClassSelector { name, children: Some(children), ..}) if name.value == js_word!("not") | ||
&& matches!(children.get(0), Some(PseudoClassSelectorChildren::SelectorList(selector_list)) if selector_list.children.len() > 1))); | ||
|
||
if !has_not { | ||
return; | ||
} | ||
|
||
let mut new_subclass_selectors = Vec::with_capacity(n.subclass_selectors.len()); | ||
|
||
for selector in &mut n.subclass_selectors.drain(..) { | ||
match selector { | ||
SubclassSelector::PseudoClass(PseudoClassSelector { | ||
span, | ||
name, | ||
children: Some(children), | ||
.. | ||
}) if name.value == js_word!("not") | ||
&& matches!(children.get(0), Some(PseudoClassSelectorChildren::SelectorList(selector_list)) if selector_list.children.len() > 1) => | ||
{ | ||
if let Some(PseudoClassSelectorChildren::SelectorList(selector_list)) = | ||
children.get(0) | ||
{ | ||
for child in &selector_list.children { | ||
new_subclass_selectors.push(SubclassSelector::PseudoClass( | ||
PseudoClassSelector { | ||
span, | ||
name: name.clone(), | ||
children: Some(vec![ | ||
PseudoClassSelectorChildren::SelectorList(SelectorList { | ||
span: child.span, | ||
children: vec![child.clone()], | ||
}), | ||
]), | ||
}, | ||
)); | ||
} | ||
} | ||
} | ||
_ => new_subclass_selectors.push(selector), | ||
} | ||
} | ||
|
||
n.subclass_selectors = new_subclass_selectors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
body { | ||
order: 1; | ||
} | ||
|
||
body, Not { | ||
order: 2; | ||
} | ||
|
||
em[attr=:not], | ||
em[attr=":not"] { | ||
order: 3; | ||
} | ||
|
||
em[attr~=:not], | ||
em[attr~=":not"] { | ||
order: 4; | ||
} | ||
|
||
em[not=abc], | ||
em[not="abc"] { | ||
order: 5; | ||
} | ||
|
||
:not { | ||
order: 6; | ||
} | ||
|
||
:not(a, b) { | ||
order: 7; | ||
} | ||
|
||
:nOt(a, b) { | ||
order: 7.1; | ||
} | ||
|
||
tag:not(.class, .class2) { | ||
order: 8; | ||
} | ||
|
||
tag :not(tag2, tag3) { | ||
order: 9; | ||
} | ||
|
||
tag :not(tag2, tag3) :not(tag4, tag5) { | ||
order: 10; | ||
} | ||
|
||
tag :not(tag2, tag3) :not(tag4, tag5), test { | ||
order: 11; | ||
} | ||
|
||
tag :not(tag2 :not(tag4, tag5), tag3) { | ||
order: 12; | ||
} | ||
|
||
.foo:not(:nth-child(-n+2), .bar) { | ||
order: 13; | ||
} | ||
|
||
a:not(.b, | ||
.c) { | ||
order: 14; | ||
} | ||
|
||
.foo:not(:hover, :focus)::before { | ||
order: 15; | ||
} | ||
|
||
.foo\\:not-italic { | ||
order: 16; | ||
} | ||
|
||
.foo\\:not-italic:not(:hover, :focus) { | ||
order: 17; | ||
} | ||
|
||
:not :dir(ltr) { | ||
order: 18; | ||
} | ||
|
||
:not(something > complex, other) { | ||
order: 19; | ||
} | ||
|
||
div:not([style*="(120, 60, 12"]) { | ||
order: 20; | ||
} | ||
|
||
@supports selector(:not(something > complex, other)) { | ||
:not(something > complex, other) { | ||
order: 19; | ||
} | ||
} | ||
|
||
:not(h1, h2, h3) { | ||
color: red; | ||
} | ||
|
||
:not(h1) { | ||
color: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
body { | ||
order: 1; | ||
} | ||
body, | ||
Not { | ||
order: 2; | ||
} | ||
em[attr=:not], | ||
em[attr=":not"] { | ||
order: 3; | ||
} | ||
em[attr~=:not], | ||
em[attr~=":not"] { | ||
order: 4; | ||
} | ||
em[not=abc], | ||
em[not="abc"] { | ||
order: 5; | ||
} | ||
:not { | ||
order: 6; | ||
} | ||
:not(a):not(b) { | ||
order: 7; | ||
} | ||
:nOt(a):nOt(b) { | ||
order: 7.1; | ||
} | ||
tag:not(.class):not(.class2) { | ||
order: 8; | ||
} | ||
tag :not(tag2):not(tag3) { | ||
order: 9; | ||
} | ||
tag :not(tag2):not(tag3) :not(tag4):not(tag5) { | ||
order: 10; | ||
} | ||
tag :not(tag2):not(tag3) :not(tag4):not(tag5), | ||
test { | ||
order: 11; | ||
} | ||
tag :not(tag2 :not(tag4):not(tag5)):not(tag3) { | ||
order: 12; | ||
} | ||
.foo:not(:nth-child(-n+2)):not(.bar) { | ||
order: 13; | ||
} | ||
a:not(.b):not(.c) { | ||
order: 14; | ||
} | ||
.foo:not(:hover):not(:focus)::before { | ||
order: 15; | ||
} | ||
.foo\\:not-italic { | ||
order: 16; | ||
} | ||
.foo\\:not-italic:not(:hover):not(:focus) { | ||
order: 17; | ||
} | ||
:not :dir(ltr) { | ||
order: 18; | ||
} | ||
:not(something > complex):not(other) { | ||
order: 19; | ||
} | ||
div:not([style*="(120, 60, 12"]) { | ||
order: 20; | ||
} | ||
@supports selector(:not(something > complex, other)) { | ||
:not(something > complex):not(other) { | ||
order: 19; | ||
} | ||
} | ||
:not(h1):not(h2):not(h3) { | ||
color: red; | ||
} | ||
:not(h1) { | ||
color: red; | ||
} |