-
I write a function like this, some of codes are copied from swc codebase. pub fn ast_to_source(node: &Module) {
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let wr = stdout();
let mut emitter = Emitter {
cfg: swc_ecma_codegen::Config { minify: false },
cm: cm.clone(),
comments: None,
wr: Box::new(JsWriter::new(cm.clone(), "\n", wr.lock(), None)),
};
emitter.emit_module(node).unwrap();
} While I trying to use it, It panics. I think it's related to let result = swc_ecma_ast::Module {
span: DUMMY_SP,
body,
shebang: None,
};
println!("source");
ast_to_source(&result) |
Beta Was this translation helpful? Give feedback.
Answered by
kdy1
Sep 24, 2021
Replies: 1 comment 2 replies
-
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); This is wrong. You should use the same instance of |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
hyf0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is wrong. You should use the same instance of
Lrc<SourceMap>
for parsing and codegen.It is designed to be shared and that's why it's wrapped in
Lrc
, which isRc
orArc
, depending on the compile option.