Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
swc-bot committed Nov 18, 2022
2 parents 8e0c63d + 19b45d2 commit 35a5f5a
Show file tree
Hide file tree
Showing 236 changed files with 8,220 additions and 79 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Expand Up @@ -641,6 +641,7 @@ jobs:
- name: Run cargo test (core)
if: matrix.settings.crate == 'swc_core'
run: |
rustup target add wasm32-unknown-unknown
cargo test -p swc_core --features ecma_quote --features common --features ecma_utils
- name: Run cargo test (binding_core_wasm)
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,9 @@

- **(es/minifier)** Preserve unused imported specifiers (#6458) ([dabea71](https://github.com/swc-project/swc/commit/dabea71c4461a96836e4456bd2c6bbcf07f238a4))


- **(xml/parser)** Fix parsing of comments (#6449) ([3a0d98b](https://github.com/swc-project/swc/commit/3a0d98b6e986dd175b64534bc99c2a59a99b97d0))

### Features


Expand All @@ -19,6 +22,15 @@

- **(html/minifier)** Remove empty script and style tags with attributes (#6447) ([7441721](https://github.com/swc-project/swc/commit/74417217a98bb26dcce7f913bb8ee35b538f0d06))


- **(html/minifier)** Use the latest `EsVersion` (#6453) ([7f6bf59](https://github.com/swc-project/swc/commit/7f6bf59a98710ce7964e99ab621a68dc729c021d))

### Refactor



- **(bindings)** Deprecate `jsvalue::*_serde` (#6462) ([dd4b9e8](https://github.com/swc-project/swc/commit/dd4b9e87de93294ed402c357745a2e0d268b34ef))

## [1.3.18] - 2022-11-16

### Bug Fixes
Expand Down
46 changes: 25 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion bindings/binding_core_wasm/Cargo.toml
Expand Up @@ -31,7 +31,6 @@ swc_core = { version = "0.43.15", features = [
] }
tracing = { version = "0.1.37", features = ["max_level_off"] }
wasm-bindgen = { version = "0.2.82", features = [
"serde-serialize",
"enable-interning",
] }

Expand Down
48 changes: 36 additions & 12 deletions bindings/binding_core_wasm/src/lib.rs
@@ -1,4 +1,6 @@
use anyhow::Error;
use serde::Serialize;
use serde_wasm_bindgen::Serializer;
use swc_core::{
base::HandlerOpts,
binding_macros::wasm::{
Expand All @@ -21,6 +23,12 @@ use swc_core::{
use wasm_bindgen::{prelude::*, JsCast};
mod types;

// A serializer with options to provide backward compat for the input / output
// from the bindgen generated swc interfaces.
const COMPAT_SERIALIZER: Serializer = Serializer::new()
.serialize_maps_as_objects(true)
.serialize_missing_as_null(true);

/// Custom interface definitions for the @swc/wasm's public interface instead of
/// auto generated one, which is not reflecting most of types in detail.
#[wasm_bindgen(typescript_custom_section)]
Expand Down Expand Up @@ -81,12 +89,16 @@ pub fn minify_sync(s: JsString, opts: JsValue) -> Result<JsValue, JsValue> {
let opts = if opts.is_null() || opts.is_undefined() {
Default::default()
} else {
anyhow::Context::context(opts.into_serde(), "failed to parse options")?
serde_wasm_bindgen::from_value(opts)
.map_err(|e| anyhow::anyhow!("failed to parse options: {}", e))?
};
let fm = c.cm.new_source_file(FileName::Anon, s.into());
let program =
anyhow::Context::context(c.minify(fm, handler, &opts), "failed to minify file")?;
anyhow::Context::context(JsValue::from_serde(&program), "failed to serialize json")

program
.serialize(&COMPAT_SERIALIZER)
.map_err(|e| anyhow::anyhow!("failed to serialize program: {}", e))
})
})
.map_err(|e| convert_err(e, None))
Expand All @@ -106,7 +118,8 @@ pub fn parse_sync(s: JsString, opts: JsValue) -> Result<JsValue, JsValue> {
let opts: ParseOptions = if opts.is_null() || opts.is_undefined() {
Default::default()
} else {
anyhow::Context::context(opts.into_serde(), "failed to parse options")?
serde_wasm_bindgen::from_value(opts)
.map_err(|e| anyhow::anyhow!("failed to parse options: {}", e))?
};
let fm = c.cm.new_source_file(FileName::Anon, s.into());
let cmts = c.comments().clone();
Expand All @@ -133,7 +146,9 @@ pub fn parse_sync(s: JsString, opts: JsValue) -> Result<JsValue, JsValue> {
opts.syntax.typescript(),
));

anyhow::Context::context(JsValue::from_serde(&program), "failed to serialize json")
program
.serialize(&COMPAT_SERIALIZER)
.map_err(|e| anyhow::anyhow!("failed to serialize program: {}", e))
})
})
})
Expand All @@ -160,9 +175,9 @@ pub fn transform_sync(
let opts: Options = if opts.is_null() || opts.is_undefined() {
Default::default()
} else {
anyhow::Context::context(opts.into_serde(), "failed to parse options")
.map_err(|e| convert_err(e, None))?
serde_wasm_bindgen::from_value(opts)?
};

let error_format = opts.experimental.error_format.unwrap_or_default();
try_with_handler(c.cm.clone(), Default::default(), |handler| {
c.run(|| {
Expand Down Expand Up @@ -193,9 +208,13 @@ pub fn transform_sync(
"failed to process js file",
)?
}
Err(v) => unsafe { c.process_js(handler, v.into_serde().expect(""), &opts)? },
Err(v) => {
c.process_js(handler, serde_wasm_bindgen::from_value(v).expect("Should able to deserialize into program"), &opts)?
}
};
anyhow::Context::context(JsValue::from_serde(&out), "failed to serialize json")

out.serialize(&COMPAT_SERIALIZER)
.map_err(|e| anyhow::anyhow!("failed to serialize transform result: {}", e))
})
})
.map_err(|e| convert_err(e, Some(error_format)))
Expand All @@ -218,10 +237,13 @@ pub fn print_sync(s: JsValue, opts: JsValue) -> Result<JsValue, JsValue> {
let opts: Options = if opts.is_null() || opts.is_undefined() {
Default::default()
} else {
anyhow::Context::context(opts.into_serde(), "failed to parse options")?
serde_wasm_bindgen::from_value(opts)
.map_err(|e| anyhow::anyhow!("failed to parse options: {}", e))?
};
let program: Program =
anyhow::Context::context(s.into_serde(), "failed to deserialize program")?;

let program: Program = serde_wasm_bindgen::from_value(s)
.map_err(|e| anyhow::anyhow!("failed to deserialize program: {}", e))?;

let s = anyhow::Context::context(
c.print(
&program,
Expand All @@ -241,7 +263,9 @@ pub fn print_sync(s: JsValue, opts: JsValue) -> Result<JsValue, JsValue> {
),
"failed to print code",
)?;
anyhow::Context::context(JsValue::from_serde(&s), "failed to serialize json")

serde_wasm_bindgen::to_value(&s)
.map_err(|e| anyhow::anyhow!("failed to serialize json: {}", e))
})
})
.map_err(|e| convert_err(e, None))
Expand Down
9 changes: 7 additions & 2 deletions crates/binding_macros/Cargo.toml
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "binding_macros"
repository = "https://github.com/swc-project/swc.git"
version = "0.20.101"
version = "0.20.102"

[lib]
bench = false
Expand All @@ -18,12 +18,15 @@ binding_wasm = [
"swc_common",
"swc_ecma_transforms",
"swc_ecma_ast",
"swc_ecma_visit",

# Optional packages
"once_cell",
"wasm-bindgen",
"wasm-bindgen-futures",
"js-sys",
"serde",
"serde-wasm-bindgen",
"anyhow",
"console_error_panic_hook",
]
Expand All @@ -34,14 +37,16 @@ swc = { optional = true, version = "0.232.99", path = "../swc" }
swc_common = { optional = true, version = "0.29.14", path = "../swc_common" }
swc_ecma_ast = { optional = true, version = "0.94.19", path = "../swc_ecma_ast" }
swc_ecma_transforms = { optional = true, version = "0.198.52", path = "../swc_ecma_transforms" }
swc_ecma_visit = { optional = true, version = "0.80.19", path = "../swc_ecma_visit" }

# Optional deps for the wasm binding macro
anyhow = { optional = true, version = "1.0.58" }
console_error_panic_hook = { optional = true, version = "0.1.7" }
js-sys = { optional = true, version = "0.3.59" }
once_cell = { optional = true, version = "1.13.0" }
serde = { optional = true, version = "1", features = ["derive"] }
serde-wasm-bindgen = { optional = true, version = "0.4.5" }
wasm-bindgen = { optional = true, version = "0.2.82", features = [
"serde-serialize",
"enable-interning",
] }
wasm-bindgen-futures = { optional = true, version = "0.4.32" }

0 comments on commit 35a5f5a

Please sign in to comment.