Skip to content

Commit

Permalink
fix: clear stored local classes for invalid composes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Jun 7, 2024
1 parent 492d161 commit ce756de
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ impl<'s> ComposesLocalClasses<'s> {

pub fn invalidate(&mut self) {
if !matches!(self.is_single, SingleLocalClass::AtKeyword) {
self.is_single = SingleLocalClass::Invalid
self.is_single = SingleLocalClass::Invalid;
self.local_classes.clear();
}
}

Expand All @@ -385,17 +386,22 @@ impl<'s> ComposesLocalClasses<'s> {
SingleLocalClass::Initial => {
self.is_single = SingleLocalClass::Single(Range::new(start, end))
}
SingleLocalClass::Single(_) => self.is_single = SingleLocalClass::Invalid,
SingleLocalClass::Single(_) => {
self.is_single = SingleLocalClass::Invalid;
self.local_classes.clear();
}
_ => {}
};
}

pub fn find_at_keyword(&mut self) {
self.is_single = SingleLocalClass::AtKeyword;
self.local_classes.clear();
}

pub fn reset_to_initial(&mut self) {
self.is_single = SingleLocalClass::Initial;
self.local_classes.clear();
}

pub fn find_comma(&mut self, lexer: &Lexer<'s>) -> Option<()> {
Expand Down
27 changes: 27 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,33 @@ fn css_modules_composes_7() {
assert_eq!(dependencies.len(), 4);
}

#[test]
fn css_modules_composes_8() {
let input = indoc! {r#"
.first,
.second {
color: green;
}
.base {
background-color: red;
}
.third {
composes: base;
}
"#};
let (dependencies, warnings) = collect_dependencies(input, Mode::Local);
assert!(warnings.is_empty());
assert_local_class_dependency(input, &dependencies[0], ".first", false);
assert_local_class_dependency(input, &dependencies[1], ".second", false);
assert_local_class_dependency(input, &dependencies[2], ".base", false);
assert_local_class_dependency(input, &dependencies[3], ".third", false);
assert_composes_dependency(input, &dependencies[4], "third", "base", None, "base");
assert_replace_dependency(input, &dependencies[5], "", "composes: base;");
assert_eq!(dependencies.len(), 6);
}

#[test]
fn icss_export_unexpected() {
let input = ":export {\n/sl/ash;";
Expand Down

0 comments on commit ce756de

Please sign in to comment.