[oden][oden-js] Notes on source maps
This commit is contained in:
parent
93d4e3eb91
commit
7a1bf5a19b
2 changed files with 10 additions and 4 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<RefCell<Vec<Diagnostic>>>,
|
||||
|
|
@ -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<String> {
|
|||
// 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<SourceMap> = Default::default();
|
||||
let diagnostics_cell: Rc<RefCell<Vec<Diagnostic>>> = Rc::new(RefCell::new(Vec::new()));
|
||||
let diagnostics_cell: Rc<RefCell<Vec<Diagnostic>>> = Default::default();
|
||||
let handler = DiagnosticCollector {
|
||||
cell: diagnostics_cell.clone(),
|
||||
}
|
||||
|
|
@ -107,7 +111,7 @@ pub fn transpile_to_javascript(path: &str, input: String) -> Result<String> {
|
|||
|
||||
let lexer = Lexer::new(
|
||||
Syntax::Typescript(Default::default()),
|
||||
Default::default(),
|
||||
EsVersion::Es2020,
|
||||
StringInput::from(&*fm),
|
||||
Some(&comments),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue