summaryrefslogtreecommitdiffstats
path: root/vendor/minifier/src/css
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:42 +0000
commitcec1877e180393eba0f6ddb0cf97bf3a791631c7 (patch)
tree47b4dac2a9dd9a40c30c251b4d4a72d7ccf77e9f /vendor/minifier/src/css
parentAdding debian version 1.74.1+dfsg1-1. (diff)
downloadrustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.tar.xz
rustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/minifier/src/css')
-rw-r--r--vendor/minifier/src/css/mod.rs2
-rw-r--r--vendor/minifier/src/css/tests.rs7
-rw-r--r--vendor/minifier/src/css/token.rs8
3 files changed, 15 insertions, 2 deletions
diff --git a/vendor/minifier/src/css/mod.rs b/vendor/minifier/src/css/mod.rs
index 224ad8126..70ac41037 100644
--- a/vendor/minifier/src/css/mod.rs
+++ b/vendor/minifier/src/css/mod.rs
@@ -18,7 +18,7 @@ mod token;
/// let css_minified = minify(css).expect("minification failed");
/// assert_eq!(&css_minified.to_string(), ".foo>p{color:red;}");
/// ```
-pub fn minify<'a>(content: &'a str) -> Result<Minified<'a>, &'static str> {
+pub fn minify(content: &str) -> Result<Minified<'_>, &'static str> {
token::tokenize(content).map(Minified)
}
diff --git a/vendor/minifier/src/css/tests.rs b/vendor/minifier/src/css/tests.rs
index dd696afde..2a3459e1e 100644
--- a/vendor/minifier/src/css/tests.rs
+++ b/vendor/minifier/src/css/tests.rs
@@ -200,6 +200,13 @@ fn check_calc() {
}
#[test]
+fn check_container() {
+ let s = "@container rustdoc (min-width: 1250px) { .foo { width: 100px; } }";
+ let expected = "@container rustdoc (min-width:1250px){.foo{width:100px;}}";
+ assert_eq!(minify(s).expect("minify failed").to_string(), expected);
+}
+
+#[test]
fn check_spaces() {
let s = ".line-numbers .line-highlighted { color: #0a042f !important; }";
let expected = ".line-numbers .line-highlighted{color:#0a042f !important;}";
diff --git a/vendor/minifier/src/css/token.rs b/vendor/minifier/src/css/token.rs
index 58e416fcd..467bed0fa 100644
--- a/vendor/minifier/src/css/token.rs
+++ b/vendor/minifier/src/css/token.rs
@@ -427,7 +427,7 @@ fn fill_other<'a>(
}
#[allow(clippy::comparison_chain)]
-pub(super) fn tokenize<'a>(source: &'a str) -> Result<Tokens<'a>, &'static str> {
+pub(super) fn tokenize(source: &str) -> Result<Tokens<'_>, &'static str> {
let mut v = Vec::with_capacity(1000);
let mut iterator = source.char_indices().peekable();
let mut start = 0;
@@ -579,6 +579,7 @@ fn clean_tokens(mut v: Vec<Token<'_>>) -> Vec<Token<'_>> {
// Index of the previous retained token, if there is one.
let mut ip: Option<usize> = None;
let mut is_in_calc = false;
+ let mut is_in_container = false;
let mut paren = 0;
// A vector of bools indicating which elements are to be retained.
let mut b = Vec::with_capacity(v.len());
@@ -594,6 +595,9 @@ fn clean_tokens(mut v: Vec<Token<'_>>) -> Vec<Token<'_>> {
paren += 1;
}
}
+ if v[i] == Token::SelectorElement(SelectorElement::Media("container")) {
+ is_in_container = true;
+ }
let mut retain = true;
if v[i].is_useless() {
@@ -609,6 +613,8 @@ fn clean_tokens(mut v: Vec<Token<'_>>) -> Vec<Token<'_>> {
// retain the space after "and", "or" or "not"
} else if is_in_calc && v[ip.unwrap()].is_useless() {
retain = false;
+ } else if is_in_container && matches!(v[ip.unwrap()], Token::Other(_)) {
+ // retain spaces between keywords in container queryes
} else if !is_in_calc
&& ((ip.is_some() && {
let prev = &v[ip.unwrap()];