[quickjs][oden][oden-js] Source maps

The worst support but it should cost very little if nobody is using
them (psst we're using them)
This commit is contained in:
John Doty 2023-09-20 09:31:57 -07:00
parent eb9fed759a
commit c96a1a4979
10 changed files with 554 additions and 374 deletions

View file

@ -1,7 +1,8 @@
use deno_ast::{parse_module, MediaType, ParseParams, SourceTextInfo};
use oden_js::{Error, Result};
use sourcemap::SourceMap;
pub fn transpile_to_javascript(path: &str, input: String) -> Result<String> {
pub fn transpile_to_javascript(path: &str, input: String) -> Result<(String, SourceMap)> {
let text_info = SourceTextInfo::new(input.into());
let parsed_source = parse_module(ParseParams {
specifier: path.to_string(),
@ -25,9 +26,18 @@ pub fn transpile_to_javascript(path: &str, input: String) -> Result<String> {
)
})?;
let options: deno_ast::EmitOptions = Default::default();
let options = deno_ast::EmitOptions {
inline_source_map: false,
source_map: true,
..Default::default()
};
let transpiled = parsed_source
.transpile(&options)
.map_err(|e| Error::ParseError(path.into(), e.to_string()))?;
return Ok(transpiled.text);
let source_map = transpiled.source_map.unwrap();
let bytes = source_map.into_bytes();
let source_map = SourceMap::from_slice(&bytes).expect("unable to parse source map");
return Ok((transpiled.text, source_map));
}