build(bindings): Fix build of typescript binding (#9125)

This commit is contained in:
Donny/강동윤 2024-07-03 10:40:16 +09:00 committed by GitHub
parent 50c0eaf4de
commit f409bc09d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 12 deletions

View File

@ -24,8 +24,11 @@ serde = { version = "1", features = ["derive"] }
serde-wasm-bindgen = "0.4.5"
serde_json = "1.0.120"
swc_core = { version = "0.96.1", features = [
"ecma_ast_serde",
"common",
"common_sourcemap",
"ecma_ast",
"ecma_codegen",
"ecma_parser",
"ecma_transforms",
"ecma_transforms_typescript",
"ecma_visit",

View File

@ -1,7 +1,6 @@
use anyhow::{Context, Error};
use serde::{Deserialize, Serialize};
use swc_core::{
base::{config::ErrorFormat, HandlerOpts},
common::{
comments::SingleThreadedComments, errors::ColorConfig, source_map::SourceMapGenConfig,
sync::Lrc, FileName, Mark, SourceMap, GLOBALS,
@ -21,7 +20,7 @@ use swc_core::{
visit::VisitMutWith,
},
};
use swc_error_reporters::handler::try_with_handler;
use swc_error_reporters::handler::{try_with_handler, HandlerOpts};
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::{
future_to_promise,
@ -79,7 +78,7 @@ pub fn transform_sync(input: JsString, options: JsValue) -> Result<JsValue, JsVa
let result = GLOBALS
.set(&Default::default(), || operate(input, options))
.map_err(|err| convert_err(err, None))?;
.map_err(convert_err)?;
Ok(serde_wasm_bindgen::to_value(&result)?)
}
@ -208,14 +207,8 @@ fn operate(input: String, options: Options) -> Result<TransformOutput, Error> {
)
}
pub fn convert_err(
err: Error,
error_format: Option<ErrorFormat>,
) -> wasm_bindgen::prelude::JsValue {
error_format
.unwrap_or(ErrorFormat::Normal)
.format(&err)
.into()
pub fn convert_err(err: Error) -> wasm_bindgen::prelude::JsValue {
format!("{:?}", err).into()
}
struct TsSourceMapGenConfig;