Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(css/compat): Support custom media queries #6625

Merged
merged 76 commits into from Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
7cf040a
Add a module
kdy1 Dec 9, 2022
ddab609
test
kdy1 Dec 12, 2022
59b2877
copy
kdy1 Dec 12, 2022
2788bc2
rename
kdy1 Dec 12, 2022
da1f44f
print_stylesheet
kdy1 Dec 12, 2022
6210758
parse_stylesheet
kdy1 Dec 12, 2022
2cc9fc6
Move
kdy1 Dec 12, 2022
75773b9
Move
kdy1 Dec 12, 2022
60c1e24
fixup
kdy1 Dec 12, 2022
bdf720b
fixup
kdy1 Dec 12, 2022
4016935
AST API
kdy1 Dec 12, 2022
1f8033c
custom media
kdy1 Dec 12, 2022
1414907
collect medias
kdy1 Dec 12, 2022
755d181
AST API
kdy1 Dec 12, 2022
b643a9e
take
kdy1 Dec 12, 2022
b712c06
change api
kdy1 Dec 12, 2022
b983b83
WIP
kdy1 Dec 12, 2022
1cb1a9d
exclude
kdy1 Dec 12, 2022
6e79037
Remove useless
kdy1 Dec 12, 2022
935b4d3
WIP
kdy1 Dec 12, 2022
77d1a1e
We need better visitor
kdy1 Dec 12, 2022
11901b0
More
kdy1 Dec 12, 2022
c9f1b12
More methods
kdy1 Dec 12, 2022
2ecb654
More methods
kdy1 Dec 12, 2022
95e3bb8
visitor
kdy1 Dec 12, 2022
e5b8c10
Drop
kdy1 Dec 12, 2022
feb0bd2
More work
kdy1 Dec 12, 2022
e2f9fbe
Drop
kdy1 Dec 12, 2022
a936e1e
fixup
kdy1 Dec 12, 2022
0a90736
drop more
kdy1 Dec 12, 2022
248fc8c
Drop
kdy1 Dec 12, 2022
661b230
fixup
kdy1 Dec 12, 2022
d136c52
Revert
kdy1 Dec 12, 2022
21ac176
Remove again
kdy1 Dec 12, 2022
5e4e500
Remove import test
kdy1 Dec 12, 2022
e1b1f10
Add tests
kdy1 Dec 12, 2022
935be83
rustfmt
kdy1 Dec 12, 2022
bb23052
CustomMediaHandler
kdy1 Dec 12, 2022
df491c3
store_custom_media
kdy1 Dec 12, 2022
c0a044d
fixup
kdy1 Dec 12, 2022
eaffc00
feature
kdy1 Dec 12, 2022
2013648
config
kdy1 Dec 12, 2022
83504eb
Drop
kdy1 Dec 12, 2022
c33784f
fixup
kdy1 Dec 12, 2022
fc773b3
process_media_query_list
kdy1 Dec 12, 2022
a7a7974
WIP
kdy1 Dec 12, 2022
c550874
Remove
kdy1 Dec 12, 2022
d49d129
fix
kdy1 Dec 12, 2022
5f21738
AST API
kdy1 Dec 12, 2022
11be78f
More
kdy1 Dec 12, 2022
f4a6c59
More
kdy1 Dec 12, 2022
3c83eec
More
kdy1 Dec 12, 2022
da9ec77
Replace simple
kdy1 Dec 12, 2022
ae7e1f6
Try: Pass down `to`
kdy1 Dec 12, 2022
6fa599e
take
kdy1 Dec 12, 2022
8ec71ab
Remove
kdy1 Dec 12, 2022
55db425
Rename
kdy1 Dec 12, 2022
6dbd0f6
More context
kdy1 Dec 12, 2022
609573d
drop
kdy1 Dec 12, 2022
5f836ad
drop more
kdy1 Dec 12, 2022
4b9143a
fix: logic
alexander-akait Dec 12, 2022
76091f4
fix: logic
alexander-akait Dec 12, 2022
397ed13
test: add weird cases
alexander-akait Dec 12, 2022
6ea6d62
fix: bug with case sensitivity
alexander-akait Dec 12, 2022
17a7f6a
test: more and todos
alexander-akait Dec 12, 2022
cb9ee49
test: more and todos
alexander-akait Dec 12, 2022
a2ff9fc
test: more
alexander-akait Dec 12, 2022
a06885f
test: more
alexander-akait Dec 12, 2022
a011ec7
refactor: todo
alexander-akait Dec 12, 2022
dca4341
refactor: code
alexander-akait Dec 12, 2022
60e6dff
refactor: code
alexander-akait Dec 12, 2022
1f0fdc8
refactor: code
alexander-akait Dec 12, 2022
1db6b79
refactor: code
alexander-akait Dec 12, 2022
3636442
fix: some bugs
alexander-akait Dec 12, 2022
23a320c
fix: bug
alexander-akait Dec 12, 2022
8c361e4
Merge branch 'main' into lowering
swc-bot Dec 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 53 additions & 1 deletion crates/swc_css_ast/src/at_rule.rs
@@ -1,7 +1,7 @@
use is_macro::Is;
use string_enum::StringEnum;
use swc_atoms::{Atom, JsWord};
use swc_common::{ast_node, EqIgnoreSpan, Span};
use swc_common::{ast_node, util::take::Take, EqIgnoreSpan, Span};

use crate::{
CustomIdent, CustomPropertyName, DashedIdent, Declaration, Dimension, FamilyName, Function,
Expand All @@ -27,6 +27,15 @@ pub enum AtRuleName {
Ident(Ident),
}

impl PartialEq<str> for AtRuleName {
fn eq(&self, other: &str) -> bool {
match self {
AtRuleName::DashedIdent(v) => *v == *other,
AtRuleName::Ident(v) => *v == *other,
}
}
}

#[ast_node]
#[derive(Eq, Hash, Is, EqIgnoreSpan)]
pub enum AtRulePrelude {
Expand Down Expand Up @@ -217,6 +226,19 @@ pub struct MediaQuery {
pub condition: Option<Box<MediaConditionType>>,
}

impl Take for MediaQuery {
#[inline]
fn dummy() -> Self {
Self {
span: Take::dummy(),
modifier: Take::dummy(),
media_type: Take::dummy(),
keyword: Take::dummy(),
condition: Take::dummy(),
}
}
}

impl EqIgnoreSpan for MediaQuery {
fn eq_ignore_span(&self, other: &Self) -> bool {
self.modifier.eq_ignore_span(&other.modifier)
Expand Down Expand Up @@ -813,11 +835,23 @@ pub struct ExtensionName {
}

impl EqIgnoreSpan for ExtensionName {
#[inline]
fn eq_ignore_span(&self, other: &Self) -> bool {
self.value == other.value
}
}

impl Take for ExtensionName {
#[inline]
fn dummy() -> Self {
Self {
span: Take::dummy(),
value: Default::default(),
raw: Take::dummy(),
}
}
}

#[ast_node("CustomMedia")]
#[derive(Eq, Hash, EqIgnoreSpan)]
pub struct CustomMediaQuery {
Expand All @@ -826,6 +860,17 @@ pub struct CustomMediaQuery {
pub media: CustomMediaQueryMediaType,
}

impl Take for CustomMediaQuery {
#[inline]
fn dummy() -> Self {
Self {
span: Take::dummy(),
name: Take::dummy(),
media: Take::dummy(),
}
}
}

#[ast_node]
#[derive(Eq, Hash, Is, EqIgnoreSpan)]
pub enum CustomMediaQueryMediaType {
Expand All @@ -834,3 +879,10 @@ pub enum CustomMediaQueryMediaType {
#[tag("MediaQueryList")]
MediaQueryList(MediaQueryList),
}

impl Take for CustomMediaQueryMediaType {
#[inline]
fn dummy() -> Self {
Self::Ident(Take::dummy())
}
}
18 changes: 18 additions & 0 deletions crates/swc_css_ast/src/value.rs
Expand Up @@ -20,12 +20,21 @@ pub struct Ident {
}

impl EqIgnoreSpan for Ident {
#[inline]
fn eq_ignore_span(&self, other: &Self) -> bool {
self.value == other.value
}
}

impl PartialEq<str> for Ident {
#[inline]
fn eq(&self, other: &str) -> bool {
&*self.value == other
}
}

impl Take for Ident {
#[inline]
fn dummy() -> Self {
Self {
span: Default::default(),
Expand All @@ -45,6 +54,7 @@ pub struct CustomIdent {
}

impl EqIgnoreSpan for CustomIdent {
#[inline]
fn eq_ignore_span(&self, other: &Self) -> bool {
self.value == other.value
}
Expand All @@ -60,11 +70,19 @@ pub struct DashedIdent {
}

impl EqIgnoreSpan for DashedIdent {
#[inline]
fn eq_ignore_span(&self, other: &Self) -> bool {
self.value == other.value
}
}

impl PartialEq<str> for DashedIdent {
#[inline]
fn eq(&self, other: &str) -> bool {
&*self.value == other
}
}

#[ast_node("CustomPropertyName")]
#[derive(Eq, Hash)]
pub struct CustomPropertyName {
Expand Down