Skip to content

Commit bc1c637

Browse files
committed
Skip over comments in Ruby code
1 parent c29506b commit bc1c637

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

crates/oxide/src/extractor/pre_processors/ruby.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,28 @@ impl PreProcessor for Ruby {
118118
continue;
119119
},
120120

121+
// Replace comments in Ruby files
122+
b'#' => {
123+
result[cursor.pos] = b' ';
124+
cursor.advance();
125+
126+
while cursor.pos < len {
127+
match cursor.curr {
128+
// End of the comment
129+
b'\n' => break,
130+
131+
// Everything else is part of the comment and replaced
132+
_ => {
133+
result[cursor.pos] = b' ';
134+
cursor.advance();
135+
},
136+
};
137+
}
138+
139+
cursor.advance();
140+
continue;
141+
},
142+
121143
_ => {}
122144
}
123145

@@ -224,6 +246,11 @@ mod tests {
224246
// (not nested array).
225247
(r#"%w[foo[bar baz]qux]"#, r#"%w foo[bar baz]qux "#),
226248

249+
(
250+
"# test\n# test\n# {ActiveRecord::Base#save!}[rdoc-ref:Persistence#save!]\n%w[flex px-2.5]",
251+
" \n \n \n%w flex px-2.5 "
252+
),
253+
227254
(r#""foo # bar""#, r#""foo # bar""#),
228255
(r#"'foo # bar'"#, r#"'foo # bar'"#),
229256
(
@@ -262,6 +289,12 @@ mod tests {
262289
"%w(flex data-[state=pending]:bg-(--my-color) flex-col)",
263290
vec!["flex", "data-[state=pending]:bg-(--my-color)", "flex-col"],
264291
),
292+
293+
(
294+
"# test\n# test\n# {ActiveRecord::Base#save!}[rdoc-ref:Persistence#save!]\n%w[flex px-2.5]",
295+
vec!["flex", "px-2.5"],
296+
),
297+
265298
(r#""foo # bar""#, vec!["foo", "bar"]),
266299
(r#"'foo # bar'"#, vec!["foo", "bar"]),
267300
] {

crates/oxide/src/extractor/pre_processors/test-fixtures/haml/dst-17051.haml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
.relative
88
^^^^^^^^
99
- # Blurred background star
10-
^^^^^^^^^^ ^^^^
1110
.absolute.left-0.z-0{ class: "-top-[400px] -right-[400px]" }
1211
^^^^^^^^ ^^^^^^ ^^^ ^^^^^ ^^^^^^^^^^^^ ^^^^^^^^^^^^^^
1312
.flex.justify-end.blur-3xl
@@ -196,7 +195,6 @@
196195
^^^^^^^^ ^^^^ ^^^ ^^^^ ^^
197196
:escaped
198197
- # app/components/character_component.html.haml
199-
^^^^
200198
= part(:component) do
201199
^^
202200
= part(:head)

0 commit comments

Comments
 (0)