mirror of
https://github.com/swc-project/swc.git
synced 2024-12-18 11:11:30 +03:00
fix(css/codegen): Improve output of @supports
(#5529)
This commit is contained in:
parent
e28fd34ce7
commit
0f45822410
@ -19,7 +19,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Copy)]
|
#[derive(Debug, Default, Clone, Copy)]
|
||||||
pub(crate) struct Ctx {}
|
pub(crate) struct Ctx {
|
||||||
|
pub in_at_rule_prelude: bool,
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) struct WithCtx<'w, I: 'w + CssWriter> {
|
pub(super) struct WithCtx<'w, I: 'w + CssWriter> {
|
||||||
inner: &'w mut CodeGenerator<I>,
|
inner: &'w mut CodeGenerator<I>,
|
||||||
|
@ -93,7 +93,13 @@ where
|
|||||||
emit!(self, n.name);
|
emit!(self, n.name);
|
||||||
|
|
||||||
if let Some(prelude) = &n.prelude {
|
if let Some(prelude) = &n.prelude {
|
||||||
emit!(self, prelude);
|
emit!(
|
||||||
|
&mut *self.with_ctx(Ctx {
|
||||||
|
in_at_rule_prelude: true,
|
||||||
|
..self.ctx
|
||||||
|
}),
|
||||||
|
prelude
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.block.is_some() {
|
if n.block.is_some() {
|
||||||
@ -212,7 +218,15 @@ where
|
|||||||
}
|
}
|
||||||
AtRulePrelude::SupportsPrelude(n) => {
|
AtRulePrelude::SupportsPrelude(n) => {
|
||||||
match n.conditions.get(0) {
|
match n.conditions.get(0) {
|
||||||
Some(SupportsConditionType::SupportsInParens(_)) => {
|
Some(SupportsConditionType::SupportsInParens(
|
||||||
|
SupportsInParens::SupportsCondition(_),
|
||||||
|
))
|
||||||
|
| Some(SupportsConditionType::SupportsInParens(SupportsInParens::Feature(
|
||||||
|
SupportsFeature::Declaration(_),
|
||||||
|
)))
|
||||||
|
| Some(SupportsConditionType::SupportsInParens(
|
||||||
|
SupportsInParens::GeneralEnclosed(GeneralEnclosed::SimpleBlock(_)),
|
||||||
|
)) => {
|
||||||
formatting_space!(self);
|
formatting_space!(self);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -525,7 +539,14 @@ where
|
|||||||
|
|
||||||
#[emitter]
|
#[emitter]
|
||||||
fn emit_supports_condition(&mut self, n: &SupportsCondition) -> Result {
|
fn emit_supports_condition(&mut self, n: &SupportsCondition) -> Result {
|
||||||
self.emit_list(&n.conditions, ListFormat::NotDelimited)?;
|
self.emit_list(
|
||||||
|
&n.conditions,
|
||||||
|
if self.config.minify {
|
||||||
|
ListFormat::NotDelimited
|
||||||
|
} else {
|
||||||
|
ListFormat::SpaceDelimited
|
||||||
|
},
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[emitter]
|
#[emitter]
|
||||||
@ -540,7 +561,6 @@ where
|
|||||||
|
|
||||||
#[emitter]
|
#[emitter]
|
||||||
fn emit_supports_not(&mut self, n: &SupportsNot) -> Result {
|
fn emit_supports_not(&mut self, n: &SupportsNot) -> Result {
|
||||||
formatting_space!(self);
|
|
||||||
emit!(self, n.keyword);
|
emit!(self, n.keyword);
|
||||||
space!(self);
|
space!(self);
|
||||||
emit!(self, n.condition);
|
emit!(self, n.condition);
|
||||||
@ -548,7 +568,6 @@ where
|
|||||||
|
|
||||||
#[emitter]
|
#[emitter]
|
||||||
fn emit_supports_and(&mut self, n: &SupportsAnd) -> Result {
|
fn emit_supports_and(&mut self, n: &SupportsAnd) -> Result {
|
||||||
formatting_space!(self);
|
|
||||||
emit!(self, n.keyword);
|
emit!(self, n.keyword);
|
||||||
space!(self);
|
space!(self);
|
||||||
emit!(self, n.condition);
|
emit!(self, n.condition);
|
||||||
@ -556,7 +575,6 @@ where
|
|||||||
|
|
||||||
#[emitter]
|
#[emitter]
|
||||||
fn emit_support_or(&mut self, n: &SupportsOr) -> Result {
|
fn emit_support_or(&mut self, n: &SupportsOr) -> Result {
|
||||||
formatting_space!(self);
|
|
||||||
emit!(self, n.keyword);
|
emit!(self, n.keyword);
|
||||||
space!(self);
|
space!(self);
|
||||||
emit!(self, n.condition);
|
emit!(self, n.condition);
|
||||||
@ -1665,7 +1683,7 @@ where
|
|||||||
fn emit_selector_list(&mut self, n: &SelectorList) -> Result {
|
fn emit_selector_list(&mut self, n: &SelectorList) -> Result {
|
||||||
self.emit_list(
|
self.emit_list(
|
||||||
&n.children,
|
&n.children,
|
||||||
if self.config.minify {
|
if self.config.minify || self.ctx.in_at_rule_prelude {
|
||||||
ListFormat::CommaDelimited
|
ListFormat::CommaDelimited
|
||||||
} else {
|
} else {
|
||||||
ListFormat::CommaDelimited | ListFormat::MultiLine
|
ListFormat::CommaDelimited | ListFormat::MultiLine
|
||||||
@ -1728,8 +1746,8 @@ where
|
|||||||
|
|
||||||
#[emitter]
|
#[emitter]
|
||||||
fn emit_compound_selector(&mut self, n: &CompoundSelector) -> Result {
|
fn emit_compound_selector(&mut self, n: &CompoundSelector) -> Result {
|
||||||
emit!(&mut *self.with_ctx(self.ctx), n.nesting_selector);
|
emit!(self, n.nesting_selector);
|
||||||
emit!(&mut *self.with_ctx(self.ctx), n.type_selector);
|
emit!(self, n.type_selector);
|
||||||
|
|
||||||
self.emit_list(&n.subclass_selectors, ListFormat::NotDelimited)?;
|
self.emit_list(&n.subclass_selectors, ListFormat::NotDelimited)?;
|
||||||
}
|
}
|
||||||
|
@ -12,3 +12,22 @@
|
|||||||
|
|
||||||
@supports not (not (transform-origin: 2px)) {}
|
@supports not (not (transform-origin: 2px)) {}
|
||||||
@supports (display: grid) and (not (display: inline-grid)) {}
|
@supports (display: grid) and (not (display: inline-grid)) {}
|
||||||
|
@supports not (not (display: flex)) {
|
||||||
|
body {
|
||||||
|
background: red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@supports not (not (not (not (display: flex)))) {
|
||||||
|
body {
|
||||||
|
background: red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@supports selector(A > B) {}
|
||||||
|
@supports (display: grid) and (not (display: inline-grid)) {}
|
||||||
|
@supports (display: table-cell) and (display: list-item) and (display:contents) {}
|
||||||
|
@supports not ((text-align-last: justify) or (-moz-text-align-last: justify)) {}
|
||||||
|
@supports (--foo: green) {}
|
||||||
|
@supports not selector(:is(a, b)) {}
|
||||||
|
@supports selector(:nth-child(1n of a, b)) {}
|
||||||
|
@supports (display: flex) and selector(:nth-child(1n of a, b)) {}
|
||||||
|
@supports selector(:nth-child(1n of a, b)) and (display: flex) {}
|
||||||
|
@ -3,10 +3,29 @@
|
|||||||
color: hotpink;
|
color: hotpink;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@supports not (display: grid) {
|
@supports not (display: grid) {
|
||||||
div {
|
div {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@supports not ( not (transform-origin: 2px)) {}
|
@supports not (not (transform-origin: 2px)) {}
|
||||||
@supports (display: grid) and ( not (display: inline-grid)) {}
|
@supports (display: grid) and (not (display: inline-grid)) {}
|
||||||
|
@supports not (not (display: flex)) {
|
||||||
|
body {
|
||||||
|
background: red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@supports not (not (not (not (display: flex)))) {
|
||||||
|
body {
|
||||||
|
background: red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@supports selector(A > B) {}
|
||||||
|
@supports (display: grid) and (not (display: inline-grid)) {}
|
||||||
|
@supports (display: table-cell) and (display: list-item) and (display: contents) {}
|
||||||
|
@supports not ((text-align-last: justify) or (-moz-text-align-last: justify)) {}
|
||||||
|
@supports (--foo: green) {}
|
||||||
|
@supports not selector(:is(a, b)) {}
|
||||||
|
@supports selector(:nth-child(1n of a, b)) {}
|
||||||
|
@supports (display: flex) and selector(:nth-child(1n of a, b)) {}
|
||||||
|
@supports selector(:nth-child(1n of a, b)) and (display: flex) {}
|
||||||
|
@ -1 +1 @@
|
|||||||
@supports(display:flex){h1{color:hotpink}}@supports not (display:grid){div{float:right}}@supports not (not (transform-origin:2px)){}@supports(display:grid)and (not (display:inline-grid)){}
|
@supports(display:flex){h1{color:hotpink}}@supports not (display:grid){div{float:right}}@supports not (not (transform-origin:2px)){}@supports(display:grid)and (not (display:inline-grid)){}@supports not (not (display:flex)){body{background:red}}@supports not (not (not (not (display:flex)))){body{background:red}}@supports selector(A>B){}@supports(display:grid)and (not (display:inline-grid)){}@supports(display:table-cell)and (display:list-item)and (display:contents){}@supports not ((text-align-last:justify)or (-moz-text-align-last:justify)){}@supports(--foo:green){}@supports not selector(:is(a,b)){}@supports selector(:nth-child(n of a,b)){}@supports(display:flex)and selector(:nth-child(n of a,b)){}@supports selector(:nth-child(n of a,b))and (display:flex){}
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.class {
|
.class {
|
||||||
@supports not (display: grid) {
|
@supports not (display: grid) {
|
||||||
float: right;
|
float: right;
|
||||||
& .class {
|
& .class {
|
||||||
color: red;
|
color: red;
|
||||||
@ -40,7 +40,7 @@
|
|||||||
}
|
}
|
||||||
.class {
|
.class {
|
||||||
color: blue;
|
color: blue;
|
||||||
@supports not (display: grid) {
|
@supports not (display: grid) {
|
||||||
float: right;
|
float: right;
|
||||||
& .class {
|
& .class {
|
||||||
color: red;
|
color: red;
|
||||||
@ -52,7 +52,7 @@
|
|||||||
&.foo {
|
&.foo {
|
||||||
color: green;
|
color: green;
|
||||||
}
|
}
|
||||||
@supports not (display: grid) {
|
@supports not (display: grid) {
|
||||||
float: right;
|
float: right;
|
||||||
& .class {
|
& .class {
|
||||||
color: red;
|
color: red;
|
||||||
|
@ -20,7 +20,7 @@ a {
|
|||||||
&.foo {
|
&.foo {
|
||||||
ident
|
ident
|
||||||
color: green;}
|
color: green;}
|
||||||
@supports not (display: grid) {
|
@supports not (display: grid) {
|
||||||
float: right;
|
float: right;
|
||||||
& .class {
|
& .class {
|
||||||
ident
|
ident
|
||||||
@ -33,7 +33,7 @@ a {
|
|||||||
&.foo {
|
&.foo {
|
||||||
ident;color: green;
|
ident;color: green;
|
||||||
}
|
}
|
||||||
@supports not (display: grid) {
|
@supports not (display: grid) {
|
||||||
float: right;
|
float: right;
|
||||||
& .class {
|
& .class {
|
||||||
ident;color: red;
|
ident;color: red;
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@supports not ((display: flex) or (display: -webkit-box) or (display: -webkit-flex) or (display: -moz-box) or (display: -ms-flexbox)) {
|
@supports not ((display: flex) or (display: -webkit-box) or (display: -webkit-flex) or (display: -moz-box) or (display: -ms-flexbox)) {
|
||||||
a {
|
a {
|
||||||
color: #000;
|
color: #000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@supports not ( not ((display: flex) or (display: -webkit-box) or (display: -webkit-flex) or (display: -moz-box) or (display: -ms-flexbox))) {
|
@supports not (not ((display: flex) or (display: -webkit-box) or (display: -webkit-flex) or (display: -moz-box) or (display: -ms-flexbox))) {
|
||||||
a {
|
a {
|
||||||
color: #000;
|
color: #000;
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@supports (((perspective: 1px) or (-webkit-perspective: 1px) or (-moz-perspective: 1px)) and ( not (-webkit-overflow-scrolling: touch))) {
|
@supports (((perspective: 1px) or (-webkit-perspective: 1px) or (-moz-perspective: 1px)) and (not (-webkit-overflow-scrolling: touch))) {
|
||||||
a {
|
a {
|
||||||
color: #000;
|
color: #000;
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@supports not (display: flex) {
|
@supports not (display: flex) {
|
||||||
a {
|
a {
|
||||||
color: #000;
|
color: #000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@supports not ( not (display: flex)) {
|
@supports not (not (display: flex)) {
|
||||||
a {
|
a {
|
||||||
color: #000;
|
color: #000;
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@supports ((perspective: 1px) and ( not (-webkit-overflow-scrolling: touch))) {
|
@supports ((perspective: 1px) and (not (-webkit-overflow-scrolling: touch))) {
|
||||||
a {
|
a {
|
||||||
color: #000;
|
color: #000;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user