#[allow(dead_code)]
pub(crate) struct SourceMap {
}
impl SourceMap {
#[allow(dead_code)]
pub(crate) fn new() -> Self {
Self {}
}
#[allow(dead_code)]
pub(crate) fn parse(_json: &str) -> Result<Self, String> {
Err("Source map parsing not yet implemented".to_string())
}
#[allow(dead_code)]
pub(crate) fn map_location(&self, _line: u32, _column: u32) -> Option<(String, u32, u32)> {
None
}
#[allow(dead_code)]
pub(crate) fn get_source_content(&self, _source_file: &str) -> Option<&str> {
None
}
}
#[allow(dead_code)]
pub(crate) fn detect_inline_sourcemap(content: &str) -> Option<&str> {
let prefix = "//# sourceMappingURL=data:application/json;base64,";
for line in content.lines().rev().take(10) {
let trimmed = line.trim();
if let Some(data) = trimmed.strip_prefix(prefix) {
return Some(data);
}
}
None
}
#[allow(dead_code)]
pub(crate) fn detect_external_sourcemap(content: &str) -> Option<&str> {
let prefix = "//# sourceMappingURL=";
for line in content.lines().rev().take(10) {
let trimmed = line.trim();
if let Some(url) = trimmed.strip_prefix(prefix) {
if !url.starts_with("data:") {
return Some(url.trim());
}
}
}
None
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_detect_inline_sourcemap() {
let js = r#"
console.log("test");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozfQ==
"#;
let result = detect_inline_sourcemap(js);
assert_eq!(result, Some("eyJ2ZXJzaW9uIjozfQ=="));
}
#[test]
fn test_detect_external_sourcemap() {
let js = r#"
console.log("test");
//# sourceMappingURL=bundle.js.map
"#;
let result = detect_external_sourcemap(js);
assert_eq!(result, Some("bundle.js.map"));
}
#[test]
fn test_no_sourcemap() {
let js = r#"
console.log("test");
"#;
assert_eq!(detect_inline_sourcemap(js), None);
assert_eq!(detect_external_sourcemap(js), None);
}
}