Skip to content

Commit

Permalink
Ensure consistent order of custom properties with all property
Browse files Browse the repository at this point in the history
Fixes #855
  • Loading branch information
devongovett committed Nov 25, 2024
1 parent 4159bc5 commit d4eec35
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const-str = "0.3.1"
pathdiff = "0.2.1"
ahash = "0.8.7"
paste = "1.0.12"
indexmap = "2.2.6"
# CLI deps
atty = { version = "0.2", optional = true }
clap = { version = "3.0.6", features = ["derive"], optional = true }
Expand Down
6 changes: 3 additions & 3 deletions src/declaration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! CSS declarations.
use std::borrow::Cow;
use std::collections::HashMap;
use std::ops::Range;

use crate::context::{DeclarationContext, PropertyHandlerContext};
Expand Down Expand Up @@ -41,6 +40,7 @@ use crate::values::string::CowArcStr;
#[cfg(feature = "visitor")]
use crate::visitor::Visit;
use cssparser::*;
use indexmap::IndexMap;

/// A CSS declaration block.
///
Expand Down Expand Up @@ -518,7 +518,7 @@ pub(crate) struct DeclarationHandler<'i> {
prefix: PrefixHandler,
direction: Option<Direction>,
unicode_bidi: Option<UnicodeBidi>,
custom_properties: HashMap<DashedIdent<'i>, usize>,
custom_properties: IndexMap<DashedIdent<'i>, usize>,
decls: DeclarationList<'i>,
}

Expand Down Expand Up @@ -609,7 +609,7 @@ impl<'i> DeclarationHandler<'i> {
direction: self.direction.clone(),
..Default::default()
};
for (key, index) in self.custom_properties.drain() {
for (key, index) in self.custom_properties.drain(..) {
handler.custom_properties.insert(key, handler.decls.len());
handler.decls.push(self.decls[index].clone());
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28355,5 +28355,9 @@ mod tests {
".foo { all: unset; background: var(--foo); }",
".foo{all:unset;background:var(--foo)}",
);
minify_test(
".foo {--bar:currentcolor; --foo:1.1em; all:unset}",
".foo{--bar:currentcolor;--foo:1.1em;all:unset}",
);
}
}

0 comments on commit d4eec35

Please sign in to comment.