Skip to content

Commit bb06f4f

Browse files
committed
Fix calc() minify bug
1 parent 3e1fd07 commit bb06f4f

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

rust-toolchain.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
[toolchain]
22
channel = "nightly-2023-10-12"
3-
components = ["rustfmt", "clippy", "rust-src", "llvm-tools-preview"]
3+
components = [
4+
"rustfmt",
5+
"clippy",
6+
"rust-src",
7+
"llvm-tools-preview",
8+
"rust-analyzer",
9+
]
410
targets = ["wasm32-unknown-unknown"]

src/ast/token/space.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl NeedsWhitespaceStringExt for str {
3939
|| x == '+'
4040
|| x == '"'
4141
|| x == '\''
42+
|| x == '('
4243
})
4344
.unwrap_or_default()
4445
}
@@ -54,6 +55,7 @@ impl NeedsWhitespaceStringExt for str {
5455
|| x == '_'
5556
|| x == '%'
5657
|| x == '+'
58+
|| x == ')'
5759
})
5860
.unwrap_or_default()
5961
}

tests/at_ruleset.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn test_font_face() {
131131
.map(|x| x.flatten_tree().as_css_string())
132132
.as_deref(),
133133
Ok("@font-face{font-family:\"Open \
134-
Sans\";font-display:block;src:url(./font/open-sans.woff2)format(\"truetype\");}")
134+
Sans\";font-display:block;src:url(./font/open-sans.woff2) format(\"truetype\");}")
135135
)
136136
}
137137

@@ -149,7 +149,7 @@ fn test_media() {
149149
)
150150
.map(|x| x.flatten_tree().as_css_string())
151151
.as_deref(),
152-
Ok("@media(max-width:1250px){div{color:red;}}")
152+
Ok("@media (max-width:1250px){div{color:red;}}")
153153
)
154154
}
155155

@@ -174,7 +174,7 @@ fn test_nested_media_preserved_after_flatten() {
174174
.map(|x| x.flatten_tree().as_css_string())
175175
.as_deref(),
176176
Ok(
177-
"@media(max-width:1250px){@media(min-width:50px){div{color:red;}div \
177+
"@media (max-width:1250px){@media (min-width:50px){div{color:red;}div \
178178
span{color:blue;}}}"
179179
)
180180
)

tests/minify.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,13 @@ fn test_minify_svg() {
4545
Ok("div{background:url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' preserveAspectRatio='none' viewBox='0 0 100 100'><path d='M100 0 L0 100 ' stroke='black' stroke-width='1'/><path d='M0 0 L100 100 ' stroke='black' stroke-width='1'/></svg>\")#8b868045;}")
4646
)
4747
}
48+
49+
#[test]
50+
fn test_minify_complex_calc() {
51+
assert_matches!(
52+
parse(r#"div { padding: calc(17px + ((var(--status-bar--height) - 48px) / 2)); }"#)
53+
.map(|x| x.as_css_string())
54+
.as_deref(),
55+
Ok("div{padding:calc(17px + ((var(--status-bar--height) - 48px)/2));}")
56+
)
57+
}

0 commit comments

Comments
 (0)