pub mod cache;
pub mod compiler;
pub mod detect;
pub mod oxc_backend;
pub use compiler::{
CompilationOutput, ErrorSeverity, TypeScriptCompiler, TypeScriptCompilerConfig,
TypeScriptError, TypeScriptModule, TypeScriptTarget,
};
pub use detect::{looks_like_jsx_source, looks_like_typescript_source};
pub fn source_mapping_url_comment(map_json: &str) -> String {
use base64::Engine;
format!(
"\n//# sourceMappingURL=data:application/json;base64,{}",
base64::engine::general_purpose::STANDARD.encode(map_json.as_bytes())
)
}
pub fn compile_typescript(source: &str, file_name: &str) -> Result<CompilationOutput, String> {
if let Some(hit) = cache::get_cached(source, file_name) {
return Ok(hit);
}
let output = oxc_backend::transpile(source, file_name)?;
cache::put_cached(source, file_name, &output);
Ok(output)
}
pub fn compile_typescript_file(file_path: &std::path::Path) -> Result<CompilationOutput, String> {
let source = std::fs::read_to_string(file_path).map_err(|e| e.to_string())?;
let file_name = file_path.to_string_lossy().to_string();
compile_typescript(&source, &file_name)
}