Skip to content
Merged
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
Next Next commit
allow . in arbitrary values for Pug
  • Loading branch information
RobinMalfait committed Mar 6, 2025
commit 269cd62333bf09ef5eaf6d7911b0e3f2cea41f21
17 changes: 16 additions & 1 deletion crates/oxide/src/extractor/pre_processors/pug.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::cursor;
use crate::extractor::bracket_stack::BracketStack;
use crate::extractor::machine::Machine;
use crate::extractor::pre_processors::pre_processor::PreProcessor;
use crate::StringMachine;
Expand All @@ -12,6 +13,7 @@ impl PreProcessor for Pug {
let mut result = content.to_vec();
let mut cursor = cursor::Cursor::new(content);
let mut string_machine = StringMachine;
let mut bracket_stack = BracketStack::default();

while cursor.pos < len {
match cursor.curr {
Expand All @@ -21,10 +23,18 @@ impl PreProcessor for Pug {
}

// Replace dots with spaces
b'.' => {
b'.' if bracket_stack.is_empty() => {
result[cursor.pos] = b' ';
}

b'(' | b'[' | b'{' => {
bracket_stack.push(cursor.curr);
}

b')' | b']' | b'}' if !bracket_stack.is_empty() => {
bracket_stack.pop(cursor.curr);
}

// Consume everything else
_ => {}
};
Expand All @@ -49,6 +59,11 @@ mod tests {
(".flex.bg-red-500", " flex bg-red-500"),
// Keep dots in strings
(r#"div(class="px-2.5")"#, r#"div(class="px-2.5")"#),
// Nested brackets
(
"bg-[url(https://example.com/?q=[1,2])]",
"bg-[url(https://example.com/?q=[1,2])]",
),
] {
Pug::test(input, expected);
}
Expand Down