Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bindings/binding_typescript_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 4 additions & 11 deletions bindings/binding_typescript_wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)?)
}
Expand Down Expand Up @@ -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;
Expand Down
Loading