You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to build an internal compiler in my program that can convert from ts to js and I found that example.
Explain
When I tried to run the example I got this error for an unknown reason
thread 'main' panicked at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_transforms_typescript-0.189.1/src/typescript.rs:68:9:
internal error: entered unreachable code: Use Program as entry
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
After some debugging, I found I got this issue from this line
// Remove typescript types
let module = module.fold_with(&mut strip(top_level_mark));
The error is gone when I remove this line but the problem is the typescript types aren't removed
Source code
main.rs
use std::{env, path::Path};use swc_common::{
comments::SingleThreadedComments,
errors::{ColorConfig,Handler},
sync::Lrc,Globals,Mark,SourceMap,GLOBALS,};use swc_ecma_codegen::{text_writer::JsWriter,Emitter};use swc_ecma_parser::{lexer::Lexer,Parser,StringInput,Syntax,TsConfig};use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene, resolver};use swc_ecma_transforms_typescript::strip;use swc_ecma_visit::FoldWith;fnmain(){let cm:Lrc<SourceMap> = Default::default();// Real usagelet fm = cm
.load_file(Path::new("../../tests/web-app/App.tsx")).expect("failed to load test.js");let input = env::args().nth(1).expect("please provide the path of input typescript file");let comments = SingleThreadedComments::default();let lexer = Lexer::new(Syntax::Typescript(TsConfig{tsx: input.ends_with(".tsx"),
..Default::default()}),Default::default(),StringInput::from(&*fm),Some(&comments),);letmut parser = Parser::new_from(lexer);for e in parser.take_errors(){eprintln!["{e:?}"]}let module = parser
.parse_module().map_err(|e| eprintln!("{e:?}")).expect("failed to parse module.");let globals = Globals::default();GLOBALS.set(&globals, || {let unresolved_mark = Mark::new();let top_level_mark = Mark::new();// Optionally transforms decorators here before the resolver pass// as it might produce runtime declarations.// Conduct identifier scope analysislet module = module.fold_with(&mutresolver(unresolved_mark, top_level_mark,true));// !!! the error appears here// Remove typescript typeslet module = module.fold_with(&mutstrip(top_level_mark));// Fix up any identifiers with the same name, but different contextslet module = module.fold_with(&muthygiene());// Ensure that we have enough parenthesis.let module = module.fold_with(&mutfixer(Some(&comments)));letmut buf = vec![];{letmut emitter = Emitter{cfg: swc_ecma_codegen::Config::default(),cm: cm.clone(),comments:Some(&comments),wr:JsWriter::new(cm.clone(),"\n",&mut buf,None),};
emitter.emit_module(&module).unwrap();}println!("{}", String::from_utf8(buf).expect("non-utf8?"));})}
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
My case
I tried to build an internal compiler in my program that can convert from ts to js and I found that example.
Explain
When I tried to run the example I got this error for an unknown reason
After some debugging, I found I got this issue from this line
The error is gone when I remove this line but the problem is the typescript types aren't removed
Source code
main.rs
../../tests/web-app/App.tsx
Crates
The text was updated successfully, but these errors were encountered: