Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
rename function
It's shorter, and fits on a single line now.
  • Loading branch information
RobinMalfait committed Mar 28, 2025
commit 5272925870747383886b341d61fa8d9914e8fcce
2 changes: 1 addition & 1 deletion crates/oxide/src/extractor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<'a> Extractor<'a> {
extracted
}

pub fn extract_css_variables_from_css_files(&mut self) -> Vec<Extracted<'a>> {
pub fn extract_variables_from_css(&mut self) -> Vec<Extracted<'a>> {
Copy link
Member

Choose a reason for hiding this comment

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

Could this be done in a pre-processor where we already have logic to do that based on file extension?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sort of but not really, we do have the contents and the extension so we do have all the information we need, but we return a new potentially transformed input file.

pub fn pre_process_input(content: &[u8], extension: &str) -> Vec<u8> {}

But we don't emit extracted variables here. So we could update this logic to also emit Vec<Extracted>.

Another solution is that we could transform the CSS file and replace everything that is not a used CSS variable with whitespace. That way the normal extractor won't find anything, and the CSS extractor will only find used variables.

But both these solutions seem like a hack, and a bit of an abuse for this pre_process_input function 😅 unless you're thinking about something completely different?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think this does make sense, agree that abusing pre-process for this does feel wrong too now that I think about it more.

let mut extracted = Vec::with_capacity(100);

let len = self.cursor.input.len();
Expand Down
3 changes: 1 addition & 2 deletions crates/oxide/src/scanner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,7 @@ fn extract_css_variables(blobs: Vec<Vec<u8>>) -> Vec<String> {
return None;
}

let extracted =
crate::extractor::Extractor::new(blob).extract_css_variables_from_css_files();
let extracted = crate::extractor::Extractor::new(blob).extract_variables_from_css();
if extracted.is_empty() {
return None;
}
Expand Down