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

refactor(css/parser): many fixes #6281

Merged
merged 13 commits into from
Oct 28, 2022
6 changes: 5 additions & 1 deletion crates/swc_css_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,11 @@ where
}

if is_custom_property {
self.emit_list(&n.value, ListFormat::NotDelimited)?;
self.with_ctx(Ctx {
in_list_of_component_values: true,
..self.ctx
})
.emit_list(&n.value, ListFormat::NotDelimited)?;
} else {
self.emit_list_of_component_values_inner(
&n.value,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@supports (--x: y , z ) {
@supports (--x: y , z) {
a {
color: red;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
div {
--y: ;
--x: var(--y) ;
--x: var(--y);
--z: 0px;
--foo: if(x > 5) this.width = 10;
--bar: ;
--bar2: ;
--yz: foo !important;
--yz: foo!important;
}
div {
width: var(--a,);
Expand Down Expand Up @@ -59,10 +59,10 @@ div {
--x: y;
}
* {
--x: y ;
--x: y;
}
* {
--x: y, ;
--x: y,;
}
* {
--x: var(y,);
Expand All @@ -74,7 +74,7 @@ div {
--x: (y);
}
* {
--x: (y) ;
--x: (y);
}
* {
--x: (y);
Expand All @@ -89,7 +89,7 @@ div {
--x: f(y);
}
* {
--x: f(y) ;
--x: f(y);
}
* {
--x: f(y);
Expand All @@ -104,7 +104,7 @@ div {
--x: [y];
}
* {
--x: [y] ;
--x: [y];
}
* {
--x: [y];
Expand All @@ -119,7 +119,7 @@ div {
--x: {y};
}
* {
--x: {y} ;
--x: {y};
}
* {
--x: {y};
Expand All @@ -130,7 +130,7 @@ div {
* {
--x: { y};
}
@supports (--x: y , z ) {
@supports (--x: y , z) {
a {
color: red;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:root {
--foo: red !important;
--foo: red!important;
--foo: red!important;
}
div {
Expand All @@ -24,7 +24,8 @@ a {
}
}
.foo {
color: red !ie;}
color: red !ie;
}
* {
--x: !important;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
--x: y;
}
* {
--x: y ;
--x: y;
}
* {
--x: y, ;
--x: y,;
}
* {
--x: var(y,);
Expand All @@ -29,7 +29,7 @@
--x: (y);
}
* {
--x: (y) ;
--x: (y);
}
* {
--x: (y);
Expand All @@ -44,7 +44,7 @@
--x: f(y);
}
* {
--x: f(y) ;
--x: f(y);
}
* {
--x: f(y);
Expand All @@ -59,7 +59,7 @@
--x: [y];
}
* {
--x: [y] ;
--x: [y];
}
* {
--x: [y];
Expand All @@ -74,7 +74,7 @@
--x: {y};
}
* {
--x: {y} ;
--x: {y};
}
* {
--x: {y};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $bad: rule;
a {
div.major { color: blue } color: red }
a {
div: hover { color: blue } color:red;
div: hover { color: blue } color: red;
}
a {
div: hover { color: blue };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{}{color:red}#broken# {color:red}$bad{color:red}$bad {color:red}$bad foo{color:red}$bad foo {color:red}$bad: rule;


a {div.major { color: blue } color: red }a{div:hover{ color: blue }color:red}a{div:hover{ color: blue };color:red}
a {div.major { color: blue } color: red }a{div:hover { color: blue } color: red}a{div:hover{ color: blue };color:red}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ body:first-of-type .selector {}
|property: value;color: red;
}
.selector {
property: value !ie;}
property: value !ie;
}
@media screen\9 {}
@media \0screen\,screen\9 {}
@media \0screen {}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ div {
background: url('\"foo\"');
}
.bar {
background: url(http://example.com/image.svg param(--color var(--primary-color)));}
background: url(http://example.com/image.svg param(--color var(--primary-color);
}
.baz {
background: url("http://example.com/image.svg" param(--color var(--primary-color)));
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions crates/swc_css_lints/src/rules/unit_no_unknown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,21 @@ impl Visit for UnitNoUnknown {

unknown_dimension.visit_children_with(self);
}

fn visit_component_value(&mut self, component_value: &ComponentValue) {
if let ComponentValue::PreservedToken(
token_and_span @ TokenAndSpan {
token: Token::Dimension { unit, .. },
..
},
) = component_value
{
if self.ignored_units.iter().all(|item| !item.is_match(unit)) {
let message = format!("Unexpected unknown unit \"{}\".", unit);
self.ctx.report(token_and_span, message);
}
}

component_value.visit_children_with(self);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
x Unexpected unknown unit "pix".
,-[$DIR/tests/rules/fail/unit-no-unknown/default/input.css:5:1]
5 | a { color: rgb(255pix, 0, 51); }
: ^^^
: ^^^^^^
`----

x Unexpected unknown unit "pix".
Expand Down