Skip to content

Commit eadc359

Browse files
committed
fix(linter): correct source text for vue files having script attributes containig ">" char inside (#12375)
1 parent 6d2b549 commit eadc359

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

crates/oxc_linter/src/loader/partial_loader/mod.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,34 @@ impl PartialLoader {
3838

3939
/// Find closing angle for situations where there is another `>` in between.
4040
/// e.g. `<script generic="T extends Record<string, string>">`
41+
/// or `<script attribute="text with > inside">`
4142
fn find_script_closing_angle(source_text: &str, pointer: usize) -> Option<usize> {
42-
let mut numbers_of_open_angle = 0;
43+
let mut open_angle = 0;
44+
let mut in_quote: Option<char> = None;
45+
4346
for (offset, c) in source_text[pointer..].char_indices() {
4447
match c {
45-
'>' => {
46-
if numbers_of_open_angle == 0 {
47-
return Some(offset);
48+
'"' | '\'' => {
49+
if let Some(q) = in_quote {
50+
if q == c {
51+
in_quote = None;
52+
}
53+
} else {
54+
in_quote = Some(c);
4855
}
49-
numbers_of_open_angle -= 1;
5056
}
51-
'<' => {
52-
numbers_of_open_angle += 1;
57+
'<' if in_quote.is_none() => {
58+
open_angle += 1;
59+
}
60+
'>' if in_quote.is_none() => {
61+
if open_angle == 0 {
62+
return Some(offset);
63+
}
64+
open_angle -= 1;
5365
}
5466
_ => {}
5567
}
5668
}
69+
5770
None
5871
}

crates/oxc_linter/src/loader/partial_loader/vue.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ mod test {
241241
assert_eq!(sources[0].source_text, "a");
242242
}
243243

244+
#[test]
245+
fn test_closing_character_inside_attribute() {
246+
let source_text = r"
247+
<script description='PI > 5'>a</script>
248+
";
249+
250+
let result = parse_vue(source_text);
251+
assert_eq!(result.source_text, "a");
252+
}
253+
244254
#[test]
245255
fn lang() {
246256
let cases = [

0 commit comments

Comments
 (0)