From 7a1bf5a19bbec0e6272b75cb309a85e9b0a32464 Mon Sep 17 00:00:00 2001 From: John Doty Date: Fri, 15 Sep 2023 07:59:49 -0700 Subject: [PATCH] [oden][oden-js] Notes on source maps --- oden-js-sys/quickjs/quickjs.c | 4 +++- src/script/typescript.rs | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/oden-js-sys/quickjs/quickjs.c b/oden-js-sys/quickjs/quickjs.c index 94ed0e54..a0c0ece7 100644 --- a/oden-js-sys/quickjs/quickjs.c +++ b/oden-js-sys/quickjs/quickjs.c @@ -6437,7 +6437,7 @@ static int find_line_num(JSContext *ctx, JSFunctionBytecode *b, if (pc_value < pc) return line_num; line_num = new_line_num; - } + } return line_num; } @@ -6518,6 +6518,8 @@ static void build_backtrace(JSContext *ctx, JSValueConst error_obj, b = p->u.func.function_bytecode; backtrace_barrier = b->backtrace_barrier; if (b->has_debug) { + /* TODO: SOURCEMAP: Indirect through the source map here if + there is one. */ line_num1 = find_line_num(ctx, b, sf->cur_pc - b->byte_code_buf - 1); atom_str = JS_AtomToCString(ctx, b->debug.filename); diff --git a/src/script/typescript.rs b/src/script/typescript.rs index dadeba6a..9e94bb35 100644 --- a/src/script/typescript.rs +++ b/src/script/typescript.rs @@ -10,7 +10,7 @@ use swc_ecma_codegen::{text_writer::JsWriter, Emitter}; use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax}; use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene, resolver}; use swc_ecma_transforms_typescript::strip; -use swc_ecma_visit::FoldWith; +use swc_ecma_visit::{swc_ecma_ast::EsVersion, FoldWith}; struct DiagnosticCollector { cell: Rc>>, @@ -41,6 +41,7 @@ fn is_fatal_swc_diagnostic(diagnostic: &Diagnostic) -> bool { Level::Help | Level::Note | Level::Warning => false, } } + fn format_swc_diagnostic(source_map: &SourceMap, diagnostic: &Diagnostic) -> String { if let Some(span) = &diagnostic.span.primary_span() { let file_name = source_map.span_to_filename(*span); @@ -95,8 +96,11 @@ pub fn transpile_to_javascript(path: &str, input: String) -> Result { // https://github.com/swc-project/swc/blob/main/crates/swc_ecma_transforms_typescript/examples/ts_to_js.rs // This appears to be similar to what deno_ast does, but this has // the advantage of actually compiling. :P + // + // NOTE: Really need to figure out how to get this to generate a source + // map for the transpilation or something. let cm: Lrc = Default::default(); - let diagnostics_cell: Rc>> = Rc::new(RefCell::new(Vec::new())); + let diagnostics_cell: Rc>> = Default::default(); let handler = DiagnosticCollector { cell: diagnostics_cell.clone(), } @@ -107,7 +111,7 @@ pub fn transpile_to_javascript(path: &str, input: String) -> Result { let lexer = Lexer::new( Syntax::Typescript(Default::default()), - Default::default(), + EsVersion::Es2020, StringInput::from(&*fm), Some(&comments), );