mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(linter): get correct source offsets for astro files (#6196)
Previously, we reported the `source_text` of an Astro file correctly, but the `start` offset was incorrectly set to before the `---` of the frontmatter. The start value now correctly points to the end of the split.
This commit is contained in:
parent
f28006668b
commit
f6a3450710
1 changed files with 10 additions and 2 deletions
|
|
@ -42,8 +42,9 @@ impl<'a> AstroPartialLoader<'a> {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
let js_code =
|
// move start to the end of the ASTRO_SPLIT
|
||||||
Span::new(start + ASTRO_SPLIT.len() as u32, end).source_text(self.source_text);
|
let start = start + ASTRO_SPLIT.len() as u32;
|
||||||
|
let js_code = Span::new(start, end).source_text(self.source_text);
|
||||||
Some(JavaScriptSource::partial(js_code, SourceType::ts(), start))
|
Some(JavaScriptSource::partial(js_code, SourceType::ts(), start))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,6 +119,7 @@ mod test {
|
||||||
let sources = parse_astro(source_text);
|
let sources = parse_astro(source_text);
|
||||||
assert_eq!(sources.len(), 1);
|
assert_eq!(sources.len(), 1);
|
||||||
assert_eq!(sources[0].source_text.trim(), r#"console.log("Hi");"#);
|
assert_eq!(sources[0].source_text.trim(), r#"console.log("Hi");"#);
|
||||||
|
assert_eq!(sources[0].start, 51);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -140,7 +142,9 @@ mod test {
|
||||||
sources[0].source_text.trim(),
|
sources[0].source_text.trim(),
|
||||||
"const { message = 'Welcome, world!' } = Astro.props;"
|
"const { message = 'Welcome, world!' } = Astro.props;"
|
||||||
);
|
);
|
||||||
|
assert_eq!(sources[0].start, 12);
|
||||||
assert_eq!(sources[1].source_text.trim(), r#"console.log("Hi");"#);
|
assert_eq!(sources[1].source_text.trim(), r#"console.log("Hi");"#);
|
||||||
|
assert_eq!(sources[1].start, 141);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -158,7 +162,9 @@ mod test {
|
||||||
let sources = parse_astro(source_text);
|
let sources = parse_astro(source_text);
|
||||||
assert_eq!(sources.len(), 2);
|
assert_eq!(sources.len(), 2);
|
||||||
assert!(sources[0].source_text.is_empty());
|
assert!(sources[0].source_text.is_empty());
|
||||||
|
assert_eq!(sources[0].start, 102);
|
||||||
assert_eq!(sources[1].source_text.trim(), r#"console.log("Hi");"#);
|
assert_eq!(sources[1].source_text.trim(), r#"console.log("Hi");"#);
|
||||||
|
assert_eq!(sources[1].start, 129);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -176,6 +182,8 @@ mod test {
|
||||||
let sources = parse_astro(source_text);
|
let sources = parse_astro(source_text);
|
||||||
assert_eq!(sources.len(), 2);
|
assert_eq!(sources.len(), 2);
|
||||||
assert!(sources[0].source_text.is_empty());
|
assert!(sources[0].source_text.is_empty());
|
||||||
|
assert_eq!(sources[0].start, 104);
|
||||||
assert_eq!(sources[1].source_text.trim(), r#"console.log("Hi");"#);
|
assert_eq!(sources[1].source_text.trim(), r#"console.log("Hi");"#);
|
||||||
|
assert_eq!(sources[1].start, 122);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue