Skip to content

Commit

Permalink
fix(css/parser): Fix various issues (#6281)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Oct 28, 2022
1 parent ecba416 commit 2813acc
Show file tree
Hide file tree
Showing 157 changed files with 8,681 additions and 6,606 deletions.
6 changes: 5 additions & 1 deletion crates/swc_css_codegen/src/lib.rs
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
@@ -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.

@@ -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.

@@ -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.

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.

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
@@ -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}
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.

3 changes: 2 additions & 1 deletion crates/swc_css_codegen/tests/fixture/values/url/1/output.css
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
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);
}
}
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

1 comment on commit 2813acc

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 2813acc Previous: 956d574 Ratio
es/full/bugs-1 352364 ns/iter (± 32659) 351173 ns/iter (± 21971) 1.00
es/full/minify/libraries/antd 1893909427 ns/iter (± 27658709) 1974722542 ns/iter (± 56745584) 0.96
es/full/minify/libraries/d3 430451156 ns/iter (± 28191819) 456567209 ns/iter (± 9231317) 0.94
es/full/minify/libraries/echarts 1591439748 ns/iter (± 57383003) 1688225647 ns/iter (± 38123174) 0.94
es/full/minify/libraries/jquery 110710431 ns/iter (± 8204467) 120712503 ns/iter (± 5159910) 0.92
es/full/minify/libraries/lodash 126074001 ns/iter (± 5717671) 145119092 ns/iter (± 7237146) 0.87
es/full/minify/libraries/moment 62135767 ns/iter (± 2952108) 69265521 ns/iter (± 4378178) 0.90
es/full/minify/libraries/react 20406332 ns/iter (± 419816) 21896969 ns/iter (± 733659) 0.93
es/full/minify/libraries/terser 329056037 ns/iter (± 10041735) 356031188 ns/iter (± 19978424) 0.92
es/full/minify/libraries/three 565970118 ns/iter (± 26010343) 585498327 ns/iter (± 14200213) 0.97
es/full/minify/libraries/typescript 3575160525 ns/iter (± 106495666) 3669590252 ns/iter (± 81940161) 0.97
es/full/minify/libraries/victory 836935034 ns/iter (± 11391541) 897559822 ns/iter (± 34392897) 0.93
es/full/minify/libraries/vue 164826324 ns/iter (± 5555287) 183308548 ns/iter (± 10929151) 0.90
es/full/codegen/es3 34129 ns/iter (± 4919) 34453 ns/iter (± 2215) 0.99
es/full/codegen/es5 35612 ns/iter (± 3105) 34147 ns/iter (± 3075) 1.04
es/full/codegen/es2015 36287 ns/iter (± 1687) 34521 ns/iter (± 1178) 1.05
es/full/codegen/es2016 36356 ns/iter (± 2635) 34382 ns/iter (± 1139) 1.06
es/full/codegen/es2017 35814 ns/iter (± 2078) 34197 ns/iter (± 2501) 1.05
es/full/codegen/es2018 36764 ns/iter (± 3862) 34240 ns/iter (± 1842) 1.07
es/full/codegen/es2019 37182 ns/iter (± 6582) 34137 ns/iter (± 2461) 1.09
es/full/codegen/es2020 37516 ns/iter (± 8447) 34410 ns/iter (± 1429) 1.09
es/full/all/es3 231127284 ns/iter (± 97082897) 230720682 ns/iter (± 15514517) 1.00
es/full/all/es5 221640278 ns/iter (± 92846873) 219303837 ns/iter (± 38465480) 1.01
es/full/all/es2015 176807351 ns/iter (± 81546783) 177058610 ns/iter (± 11816327) 1.00
es/full/all/es2016 184412844 ns/iter (± 73844187) 172167049 ns/iter (± 11357839) 1.07
es/full/all/es2017 179428278 ns/iter (± 61952728) 161453457 ns/iter (± 8321840) 1.11
es/full/all/es2018 164754507 ns/iter (± 61150369) 162055643 ns/iter (± 11636701) 1.02
es/full/all/es2019 170846051 ns/iter (± 34846502) 169801773 ns/iter (± 9905999) 1.01
es/full/all/es2020 162842416 ns/iter (± 34336359) 167918539 ns/iter (± 15932387) 0.97
es/full/parser 784009 ns/iter (± 73547) 754540 ns/iter (± 74902) 1.04
es/full/base/fixer 28703 ns/iter (± 1381) 26627 ns/iter (± 1444) 1.08
es/full/base/resolver_and_hygiene 100668 ns/iter (± 77011) 96495 ns/iter (± 4317) 1.04
serialization of ast node 219 ns/iter (± 10) 220 ns/iter (± 19) 1.00
serialization of serde 225 ns/iter (± 13) 222 ns/iter (± 11) 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.