diff --git a/Cargo.lock b/Cargo.lock index 5de02e4951a8..5267e5bef45c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2287,7 +2287,7 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" [[package]] name = "swc" -version = "0.43.1" +version = "0.44.0" dependencies = [ "ahash", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 3f3e13a4aab3..3bdf59400ab0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc" repository = "https://github.com/swc-project/swc.git" -version = "0.43.1" +version = "0.44.0" [lib] name = "swc" diff --git a/common/src/serializer.rs b/common/src/serializer.rs index 2de505b33112..4025271ec67d 100644 --- a/common/src/serializer.rs +++ b/common/src/serializer.rs @@ -1,6 +1,9 @@ +#![allow(deprecated)] +#![deprecated = "Not used by swc, and this will be removed with next breaking change"] use serde::Deserialize; #[derive(Deserialize)] +#[deprecated = "Not used by swc, and this will be removed with next breaking change"] pub struct Node { #[serde(default, rename = "type")] pub ty: String, @@ -9,6 +12,7 @@ pub struct Node { } #[derive(Deserialize)] +#[deprecated = "Not used by swc, and this will be removed with next breaking change"] pub struct Type { #[serde(rename = "type")] pub ty: String, diff --git a/node/binding/src/util.rs b/node/binding/src/util.rs index a573807034ba..5dff0bcb98f7 100644 --- a/node/binding/src/util.rs +++ b/node/binding/src/util.rs @@ -1,6 +1,7 @@ use anyhow::Context; use napi::{CallContext, JsBuffer, Status}; use serde::de::DeserializeOwned; +use std::any::type_name; pub trait MapErr: Into> { fn convert_err(self) -> napi::Result { @@ -25,7 +26,14 @@ impl CtxtExt for CallContext<'_> { { let buffer = self.get::(index)?.into_value()?; let v = serde_json::from_slice(&buffer) - .with_context(|| format!("Argument at `{}` is not JsBuffer", index)) + .with_context(|| { + format!( + "Failed to deserialize argument at `{}` as {}\nJSON: {}", + index, + type_name::(), + String::from_utf8_lossy(&buffer) + ) + }) .convert_err()?; Ok(v) diff --git a/scripts/link.sh b/scripts/link.sh new file mode 100755 index 000000000000..eb4492f725c3 --- /dev/null +++ b/scripts/link.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -eu + +yarn run build:dev +yarn link + +(cd swr && yarn run build) \ No newline at end of file diff --git a/src/config/mod.rs b/src/config/mod.rs index 5c6425b7e585..b7e9f937dcb3 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -545,7 +545,88 @@ pub struct JsMinifyOptions { #[derive(Debug, Clone, Default, Serialize, Deserialize)] #[serde(deny_unknown_fields, rename_all = "camelCase")] pub struct JsMinifyFormatOptions { + /// Not implemented yet. + #[serde(default, alias = "ascii_only")] + pub ascii_only: bool, + + /// Not implemented yet. + #[serde(default)] + pub beautify: bool, + + /// Not implemented yet. + #[serde(default)] + pub braces: bool, + + #[serde(default)] pub comments: BoolOrObject, + + /// Not implemented yet. + #[serde(default)] + pub ecma: usize, + + /// Not implemented yet. + #[serde(default, alias = "indent_level")] + pub indent_level: usize, + + /// Not implemented yet. + #[serde(default, alias = "indent_start")] + pub indent_start: bool, + + /// Not implemented yet. + #[serde(default, alias = "inline_script")] + pub inline_script: bool, + + /// Not implemented yet. + #[serde(default, alias = "keep_numbers")] + pub keep_numbers: bool, + + /// Not implemented yet. + #[serde(default, alias = "keep_quoted_props")] + pub keep_quoted_props: bool, + + /// Not implemented yet. + #[serde(default, alias = "max_line_len")] + pub max_line_len: BoolOrObject, + + /// Not implemented yet. + #[serde(default)] + pub preamble: String, + + /// Not implemented yet. + #[serde(default, alias = "quote_keys")] + pub quote_keys: bool, + + /// Not implemented yet. + #[serde(default, alias = "quote_style")] + pub quote_style: usize, + + /// Not implemented yet. + #[serde(default, alias = "preserve_annotations")] + pub preserve_annotations: bool, + + /// Not implemented yet. + #[serde(default)] + pub safari10: bool, + + /// Not implemented yet. + #[serde(default)] + pub semicolons: bool, + + /// Not implemented yet. + #[serde(default)] + pub shebang: bool, + + /// Not implemented yet. + #[serde(default)] + pub webkit: bool, + + /// Not implemented yet. + #[serde(default, alias = "warp_iife")] + pub wrap_iife: bool, + + /// Not implemented yet. + #[serde(default, alias = "wrap_func_args")] + pub wrap_func_args: bool, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/src/config/util.rs b/src/config/util.rs index 5ec31639af69..108ed8acfa7b 100644 --- a/src/config/util.rs +++ b/src/config/util.rs @@ -1,8 +1,8 @@ -use serde::{Deserialize, Serialize}; - use super::Merge; +use serde::{Deserialize, Serialize}; -#[derive(Clone, Serialize, Deserialize, Debug)] +/// Note: `{}` (empty object) is treated as `true`. +#[derive(Clone, Serialize, Debug)] #[serde(untagged)] pub enum BoolOrObject { Bool(bool), @@ -57,3 +57,45 @@ where } } } + +impl<'de, T> Deserialize<'de> for BoolOrObject +where + T: Deserialize<'de>, +{ + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + #[derive(Deserialize)] + #[serde(untagged)] + enum Deser { + Bool(bool), + Obj(T), + EmptyObject(EmptyStruct), + } + + #[derive(Deserialize)] + #[serde(deny_unknown_fields)] + struct EmptyStruct {} + + let content = swc_common::private::serde::de::Content::deserialize(deserializer)?; + + let deserializer = + swc_common::private::serde::de::ContentRefDeserializer::::new(&content); + + let res = Deser::deserialize(deserializer); + + match res { + Ok(v) => Ok(match v { + Deser::Bool(v) => BoolOrObject::Bool(v), + Deser::Obj(v) => BoolOrObject::Obj(v), + Deser::EmptyObject(_) => BoolOrObject::Bool(true), + }), + Err(..) => { + let d = + swc_common::private::serde::de::ContentDeserializer::::new(content); + Ok(BoolOrObject::Obj(T::deserialize(d)?)) + } + } + } +}