From 9ad8f895d35a53404c9ac89dcb0f41a9dd576734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Mon, 26 Feb 2024 05:25:17 +0100 Subject: [PATCH] Fix few serialization issues (#2506) Re: #2463 --- crates/oxc_ast/src/ast/js.rs | 5 +++-- crates/oxc_ast/src/ast/ts.rs | 9 +++++---- napi/parser/index.d.ts | 2 +- napi/parser/src/lib.rs | 1 + 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index abc8ea0bcb0e0..d79cfd88bc3c1 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -557,7 +557,7 @@ impl<'a> TemplateLiteral<'a> { } #[derive(Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))] #[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] pub struct TaggedTemplateExpression<'a> { #[cfg_attr(feature = "serde", serde(flatten))] @@ -780,7 +780,7 @@ impl<'a> CallExpression<'a> { /// New Expression #[derive(Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))] #[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] pub struct NewExpression<'a> { #[cfg_attr(feature = "serde", serde(flatten))] @@ -1849,6 +1849,7 @@ impl<'a> FunctionBody<'a> { #[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))] #[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] pub struct ArrowFunctionExpression<'a> { + #[cfg_attr(feature = "serde", serde(flatten))] pub span: Span, /// Is the function body an arrow expression? i.e. `() => expr` instead of `() => {}` pub expression: bool, diff --git a/crates/oxc_ast/src/ast/ts.rs b/crates/oxc_ast/src/ast/ts.rs index 6c0b9b7e9f2a1..4769446e6838d 100644 --- a/crates/oxc_ast/src/ast/ts.rs +++ b/crates/oxc_ast/src/ast/ts.rs @@ -41,6 +41,7 @@ pub struct TSEnumDeclaration<'a> { #[cfg_attr(feature = "serde", serde(flatten))] pub span: Span, pub id: BindingIdentifier, + #[cfg_attr(feature = "serde", serde(flatten))] pub body: TSEnumBody<'a>, /// Valid Modifiers: `const`, `export`, `declare` pub modifiers: Modifiers<'a>, @@ -49,10 +50,10 @@ pub struct TSEnumDeclaration<'a> { /// /// A scope must be created on the enum body so this abstraction exists #[derive(Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(Serialize))] #[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] pub struct TSEnumBody<'a> { - #[cfg_attr(feature = "serde", serde(flatten))] + #[cfg_attr(feature = "serde", serde(skip_serializing))] pub span: Span, pub members: Vec<'a, TSEnumMember<'a>>, } @@ -203,7 +204,7 @@ pub struct TSIntersectionType<'a> { /// /// #[derive(Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))] #[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] pub struct TSTypeOperator<'a> { #[cfg_attr(feature = "serde", serde(flatten))] @@ -1058,7 +1059,7 @@ pub struct TSInstantiationExpression<'a> { } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))] +#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))] #[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] pub enum ImportOrExportKind { Value, diff --git a/napi/parser/index.d.ts b/napi/parser/index.d.ts index 416aaf7d93c10..2727dce5db192 100644 --- a/napi/parser/index.d.ts +++ b/napi/parser/index.d.ts @@ -19,7 +19,7 @@ export interface ParseResult { } export interface Comment { type: string - value: string + value: 'Line' | 'Block' start: number end: number } diff --git a/napi/parser/src/lib.rs b/napi/parser/src/lib.rs index b02f903f4d8a9..f4c5d15cc520a 100644 --- a/napi/parser/src/lib.rs +++ b/napi/parser/src/lib.rs @@ -35,6 +35,7 @@ pub struct ParseResult { #[napi(object)] pub struct Comment { pub r#type: &'static str, + #[napi(ts_type = "'Line' | 'Block'")] pub value: String, pub start: u32, pub end: u32,