From bf2e2fe08aaf001e7a5dc0ba9872e95c2dbb2d64 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Thu, 26 Feb 2026 12:23:50 +0100 Subject: [PATCH] Extract classes from interpolated expressions in Ruby (#19730) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR ensures that interpolated expressions in Ruby syntax are correctly extracted. The issue was that we ignore comments in Ruby syntax (which start with `#`). We already made an exception for locals (`<%# locals: … %>`), but we also need to handle interpolated expressions (`#{ … }`) in the same way because they are not comments. Fixes: #19728 ## Test plan 1. Existing tests pass 2. Added a regression test for this scenario 3. Tested using the extractor on the given code snippet: image Notice that the `w-100` gets extracted now. --- .../oxide/src/extractor/pre_processors/ruby.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/oxide/src/extractor/pre_processors/ruby.rs b/crates/oxide/src/extractor/pre_processors/ruby.rs index 1f2221414ff4..5a3a0fabbfc7 100644 --- a/crates/oxide/src/extractor/pre_processors/ruby.rs +++ b/crates/oxide/src/extractor/pre_processors/ruby.rs @@ -124,7 +124,9 @@ impl PreProcessor for Ruby { // Except for strict locals, these are defined in a `<%# locals: … %>`. Checking if // the comment is preceded by a `%` should be enough without having to perform more // parsing logic. Worst case we _do_ scan a few comments. - b'#' if !matches!(cursor.prev(), b'%') => { + // + // We also want to skip interpolation syntax, which look like `#{…}`. + b'#' if !matches!(cursor.prev(), b'%') && !matches!(cursor.next(), b'{') => { result[cursor.pos] = b' '; cursor.advance(); @@ -388,6 +390,20 @@ mod tests { Ruby::test_extract_contains(input, vec!["z-1", "z-2", "z-3"]); } + // https://github.com/tailwindlabs/tailwindcss/issues/19728 + #[test] + fn test_interpolated_expressions() { + let input = r#" + def width_class(width = nil) + <<~STYLE_CLASS + #{width || 'w-100'} + STYLE_CLASS + end + "#; + + Ruby::test_extract_contains(input, vec!["w-100"]); + } + // https://github.com/tailwindlabs/tailwindcss/issues/19239 #[test] fn test_skip_comments() {