Skip to content

Commit

Permalink
fix: TypeScript codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Feb 2, 2024
1 parent 022c2bb commit 68759f0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 57 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

110 changes: 55 additions & 55 deletions crates/web_fmt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,69 +21,16 @@ struct Config {
style: Option<malva::config::FormatOptions>,
}

#[derive(Clone, Copy, Default, Deserialize)]
#[serde(rename_all = "snake_case")]
enum IndentStyle {
Tab,
#[default]
Space,
}

impl From<biome_fmt::IndentStyle> for IndentStyle {
fn from(value: biome_fmt::IndentStyle) -> Self {
match value {
biome_fmt::IndentStyle::Tab => Self::Tab,
biome_fmt::IndentStyle::Space => Self::Space,
}
}
}

impl From<IndentStyle> for biome_fmt::IndentStyle {
fn from(value: IndentStyle) -> Self {
match value {
IndentStyle::Tab => Self::Tab,
IndentStyle::Space => Self::Space,
}
}
}

impl From<IndentStyle> for bool {
fn from(value: IndentStyle) -> Self {
matches!(value, IndentStyle::Tab)
}
}

#[derive(Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub(crate) struct ConfigLayout {
indent_style: Option<IndentStyle>,
indent_width: Option<u8>,
line_width: Option<u16>,
}

#[derive(Deserialize, Default)]
#[serde(rename_all = "snake_case")]
struct ConfigDefault {
#[serde(flatten, default)]
default: ConfigLayout,
#[serde(default)]
markup: ConfigLayout,
#[serde(default)]
script: ConfigLayout,
#[serde(default)]
style: ConfigLayout,
}

#[wasm_bindgen(typescript_custom_section)]
const TS_Config: &'static str = r#"
export interface StyleConfig {
export interface Config {
indent_style?: "tab" | "space";
indent_width?: number;
line_width?: number;
markup?: MarkupConfig;
script?: ScriptConfig;
style: StyleConfig;
style?: StyleConfig;
}"#;

#[wasm_bindgen]
Expand Down Expand Up @@ -168,3 +115,56 @@ pub fn format(src: &str, filename: &str, config: Option<JSConfig>) -> Result<Str
_ => Err(format!("unsupported file extension: {}", filename)),
}
}

#[derive(Clone, Copy, Default, Deserialize)]
#[serde(rename_all = "snake_case")]
enum IndentStyle {
Tab,
#[default]
Space,
}

impl From<biome_fmt::IndentStyle> for IndentStyle {
fn from(value: biome_fmt::IndentStyle) -> Self {
match value {
biome_fmt::IndentStyle::Tab => Self::Tab,
biome_fmt::IndentStyle::Space => Self::Space,
}
}
}

impl From<IndentStyle> for biome_fmt::IndentStyle {
fn from(value: IndentStyle) -> Self {
match value {
IndentStyle::Tab => Self::Tab,
IndentStyle::Space => Self::Space,
}
}
}

impl From<IndentStyle> for bool {
fn from(value: IndentStyle) -> Self {
matches!(value, IndentStyle::Tab)
}
}

#[derive(Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub(crate) struct ConfigLayout {
indent_style: Option<IndentStyle>,
indent_width: Option<u8>,
line_width: Option<u16>,
}

#[derive(Deserialize, Default)]
#[serde(rename_all = "snake_case")]
struct ConfigDefault {
#[serde(flatten, default)]
default: ConfigLayout,
#[serde(default)]
markup: ConfigLayout,
#[serde(default)]
script: ConfigLayout,
#[serde(default)]
style: ConfigLayout,
}

0 comments on commit 68759f0

Please sign in to comment.