Skip to content

Commit

Permalink
Update transpiler
Browse files Browse the repository at this point in the history
  • Loading branch information
rscarson committed Jun 5, 2024
1 parent 74ffa5c commit 463fd26
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ criterion = "0.5.1"

[dependencies]
deno_core = "0.283.0"
deno_ast = { version = "0.38.2", features = ["transpiling"]}
deno_ast = { version = "0.39.0", features = ["transpiling"]}
thiserror = "1.0.60"
serde = "1.0.202"
tokio = "1.37.0"
Expand Down
13 changes: 9 additions & 4 deletions src/transpiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ pub fn transpile(module_specifier: &ModuleSpecifier, code: &str) -> Result<Modul
let should_transpile = should_transpile(&media_type);

let code = if should_transpile {
let sti = SourceTextInfo::from_string(code.to_string());
let text = sti.text();
let parsed = deno_ast::parse_module(ParseParams {
specifier: module_specifier.clone(),
text_info: SourceTextInfo::from_string(code.to_string()),
text,
media_type,
capture_tokens: false,
scope_analysis: false,
Expand All @@ -57,7 +59,7 @@ pub fn transpile(module_specifier: &ModuleSpecifier, code: &str) -> Result<Modul
};

let emit_options = deno_ast::EmitOptions {
keep_comments: true,
remove_comments: false,
source_map: deno_ast::SourceMapOption::Separate,
inline_sources: false,
..Default::default()
Expand All @@ -66,8 +68,11 @@ pub fn transpile(module_specifier: &ModuleSpecifier, code: &str) -> Result<Modul
.transpile(&transpile_options, &emit_options)?
.into_source();

let text = res.text;
let source_map: Option<SourceMapData> = res.source_map.map(|sm| sm.into_bytes().into());
let text = res.source;
// Convert utf8 bytes to a string
let text = String::from_utf8(text)?;

let source_map: Option<SourceMapData> = res.source_map.map(|sm| sm.into());

(text, source_map)
} else {
Expand Down

0 comments on commit 463fd26

Please sign in to comment.