Skip to content

Commit

Permalink
fix: find url in minimized css
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Jun 17, 2024
1 parent 4f22bb4 commit 92e9888
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1764,14 +1764,11 @@ impl<'s, D: HandleDependency<'s>, W: HandleWarning<'s>> Visitor<'s> for LexDepen
self.exit_font_palette_property();
}
}

self.is_next_rule_prelude = self.is_next_nested_syntax(lexer)?;
}
self.is_next_rule_prelude = self.is_next_nested_syntax(lexer)?;
}
Scope::TopLevel => {
if self.mode_data.is_some() {
self.is_next_rule_prelude = self.is_next_nested_syntax(lexer)?;
}
self.is_next_rule_prelude = self.is_next_nested_syntax(lexer)?;
}
}
Some(())
Expand Down Expand Up @@ -2047,6 +2044,7 @@ impl<'s, D: HandleDependency<'s>, W: HandleWarning<'s>> Visitor<'s> for LexDepen
}
_ => return Some(()),
}
self.is_next_rule_prelude = self.is_next_nested_syntax(lexer)?;
if let Some(mode_data) = &mut self.mode_data {
if mode_data.is_pure_mode() && mode_data.pure_global.is_some() {
let pure_global_start = mode_data.pure_global.unwrap();
Expand All @@ -2069,7 +2067,6 @@ impl<'s, D: HandleDependency<'s>, W: HandleWarning<'s>> Visitor<'s> for LexDepen

self.balanced.update_property_mode(mode_data);
self.balanced.pop_mode_pseudo_class(mode_data);
self.is_next_rule_prelude = self.is_next_nested_syntax(lexer)?;
if self.is_next_rule_prelude && self.block_nesting_level == 0 {
let mode_data = self.mode_data.as_mut().unwrap();
mode_data.composes_local_classes.reset_to_initial();
Expand Down Expand Up @@ -2109,11 +2106,11 @@ impl<'s, D: HandleDependency<'s>, W: HandleWarning<'s>> Visitor<'s> for LexDepen
}
if self.block_nesting_level == 0 {
self.scope = Scope::TopLevel;
self.is_next_rule_prelude = true;
if let Some(mode_data) = &mut self.mode_data {
self.is_next_rule_prelude = true;
mode_data.composes_local_classes.reset_to_initial();
}
} else if self.mode_data.is_some() {
} else {
self.is_next_rule_prelude = self.is_next_nested_syntax(lexer)?;
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,4 +957,22 @@ mod tests {
"#},
);
}

#[test]
fn parse_minimized_urls() {
assert_lexer_snapshot(
"body{background:url(./image.png)}",
indoc! {r#"
ident: body
left_curly: {
ident: background
pseudo_function: :url(
class: .
ident: image
class: .png
right_parenthesis: )
right_curly: }
"#},
);
}
}
14 changes: 14 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,20 @@ fn url() {
assert_eq!(dependencies.len(), 2);
}

#[test]
fn url_2() {
let input = "body{background-image:url(./img.png)}";
let (dependencies, warnings) = collect_dependencies(input, Mode::Css);
assert!(warnings.is_empty());
assert_url_dependency(
input,
&dependencies[0],
"./img.png",
UrlRangeKind::Function,
"url(./img.png)",
);
}

#[test]
fn duplicate_url() {
let input = indoc! {r#"
Expand Down

0 comments on commit 92e9888

Please sign in to comment.