Skip to content

Commit

Permalink
refactor: 🎨 no need to resolve empty url in css (#1732)
Browse files Browse the repository at this point in the history
* refactor: 🎨 no need to resolve empty url in css

* refactor: 🎨 add test case
  • Loading branch information
stormslowly authored Dec 24, 2024
1 parent ab465e2 commit 99012b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/mako/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ fn do_resolve(
}
_ => {
eprintln!(
"failed to resolve {} from {} with resolver err: {:?}",
"failed to resolve `{}` from `{}` with resolver err: {:?}",
source,
path.to_string_lossy(),
oxc_resolve_err
Expand Down
12 changes: 11 additions & 1 deletion crates/mako/src/visitors/css_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ impl VisitMut for CSSAssets {
box UrlValue::Raw(s) => s.value.to_string(),
};

if is_remote_or_data_or_hash(&url) {
if is_remote_or_data_or_hash(&url) || url.is_empty() {
return;
}

let url = remove_first_tilde(url);

let dep = Dependency {
source: url,
resolve_as: None,
Expand Down Expand Up @@ -110,6 +112,14 @@ mod tests {
);
}

#[test]
fn test_empty_url() {
assert_eq!(
run(r#".foo { background: url("") }"#),
r#".foo{background:url("")}"#
);
}

#[test]
fn test_big_image() {
assert!(run(r#".foo { background: url(big.jpg) }"#).contains(".foo{background:url(big."));
Expand Down

0 comments on commit 99012b2

Please sign in to comment.