Skip to content

Commit

Permalink
fix: ensure newline before inline sourcemap (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato authored Nov 1, 2023
1 parent f9d6dab commit df94f1e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/transpiling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ impl ParsedSource {
.to_writer(&mut buf)?;

if options.inline_source_map {
if !src.ends_with('\n') {
src.push('\n');
}
src.push_str("//# sourceMappingURL=data:application/json;base64,");
base64::encode_config_buf(
buf,
Expand Down Expand Up @@ -1158,6 +1161,32 @@ const a = _jsx(Foo, {
children: _jsxTemplate($$_tpl_2)
}))
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJza"#;
assert_eq!(&code[0..expected1.len()], expected1);
}

#[test]
fn test_inline_source_map_newline() {
let specifier =
ModuleSpecifier::parse("https://deno.land/x/mod.tsx").unwrap();
let source = r#"{ const foo = "bar"; };"#;
let module = parse_module(ParseParams {
specifier: specifier.as_str().to_string(),
text_info: SourceTextInfo::from_string(source.to_string()),
media_type: MediaType::Tsx,
capture_tokens: false,
maybe_syntax: None,
scope_analysis: false,
})
.unwrap();
let options = EmitOptions {
inline_source_map: true,
..Default::default()
};
let code = module.transpile(&options).unwrap().text;
let expected1 = r#"{
const foo = "bar";
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJza"#;
assert_eq!(&code[0..expected1.len()], expected1);
}
Expand Down

0 comments on commit df94f1e

Please sign in to comment.