Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion napi/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ impl From<Restriction> for rspack_resolver::Restriction {
panic!("Should specify path or regex")
}
(None, Some(regex)) => {
let re = Regex::new(&regex).expect(&format!("Invalid regex pattern: {}", regex));
let re =
Regex::new(&regex).unwrap_or_else(|_| panic!("Invalid regex pattern: {regex}"));
Comment on lines +220 to +221
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closure in unwrap_or_else captures the regex variable, which may be unnecessarily expensive. Consider using expect with a static string or format the message outside the closure to avoid the capture.

Suggested change
let re =
Regex::new(&regex).unwrap_or_else(|_| panic!("Invalid regex pattern: {regex}"));
let error_message = format!("Invalid regex pattern: {}", regex);
let re = Regex::new(&regex).expect(&error_message);

Copilot uses AI. Check for mistakes.
Self::Fn(Arc::new(move |path| re.is_match(path.to_str().unwrap_or_default())))
}
(Some(path), None) => Self::Path(PathBuf::from(path)),
Expand Down
Loading