[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
|
|
@ -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