From 5525206dc557003a06d1b75408a0a37bf43fd9bc Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Thu, 3 Apr 2025 10:47:25 +0000 Subject: [PATCH] refactor(ast/estree): simplify static converters (#10197) Pure refactor. Simplify the converters which produce static values e.g. `null`. They can contain a `T` rather than a `&T` - `T` is generic, so can be a `&` itself. #10192 made me realize this was more complex than it needed to be. --- crates/oxc_ast/src/serialize.rs | 48 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/crates/oxc_ast/src/serialize.rs b/crates/oxc_ast/src/serialize.rs index 1f52f96981d7a..50e448017dc37 100644 --- a/crates/oxc_ast/src/serialize.rs +++ b/crates/oxc_ast/src/serialize.rs @@ -136,9 +136,9 @@ impl ESTree for ProgramConverter<'_, '_> { /// Serialized as `null`. #[ast_meta] #[estree(ts_type = "null", raw_deser = "null")] -pub struct Null<'b, T>(#[expect(dead_code)] pub &'b T); +pub struct Null(pub T); -impl ESTree for Null<'_, T> { +impl ESTree for Null { fn serialize(&self, serializer: S) { ().serialize(serializer); } @@ -147,9 +147,9 @@ impl ESTree for Null<'_, T> { #[ast_meta] #[estree(ts_type = "null", raw_deser = "null")] #[ts] -pub struct TsNull<'b, T>(#[expect(dead_code)] pub &'b T); +pub struct TsNull(pub T); -impl ESTree for TsNull<'_, T> { +impl ESTree for TsNull { fn serialize(&self, serializer: S) { ().serialize(serializer); } @@ -158,9 +158,9 @@ impl ESTree for TsNull<'_, T> { /// Serialized as `true`. #[ast_meta] #[estree(ts_type = "true", raw_deser = "true")] -pub struct True<'b, T>(#[expect(dead_code)] pub &'b T); +pub struct True(pub T); -impl ESTree for True<'_, T> { +impl ESTree for True { fn serialize(&self, serializer: S) { true.serialize(serializer); } @@ -169,9 +169,9 @@ impl ESTree for True<'_, T> { /// Serialized as `false`. #[ast_meta] #[estree(ts_type = "false", raw_deser = "false")] -pub struct False<'b, T>(#[expect(dead_code)] pub &'b T); +pub struct False(pub T); -impl ESTree for False<'_, T> { +impl ESTree for False { fn serialize(&self, serializer: S) { false.serialize(serializer); } @@ -180,9 +180,9 @@ impl ESTree for False<'_, T> { #[ast_meta] #[estree(ts_type = "false", raw_deser = "false")] #[ts] -pub struct TsFalse<'b, T>(#[expect(dead_code)] pub &'b T); +pub struct TsFalse(pub T); -impl ESTree for TsFalse<'_, T> { +impl ESTree for TsFalse { fn serialize(&self, serializer: S) { false.serialize(serializer); } @@ -192,9 +192,9 @@ impl ESTree for TsFalse<'_, T> { #[ast_meta] #[estree(ts_type = "'value'", raw_deser = "'value'")] #[ts] -pub struct TsValue<'b, T>(#[expect(dead_code)] pub &'b T); +pub struct TsValue(pub T); -impl ESTree for TsValue<'_, T> { +impl ESTree for TsValue { fn serialize(&self, serializer: S) { JsonSafeString("value").serialize(serializer); } @@ -203,9 +203,9 @@ impl ESTree for TsValue<'_, T> { /// Serialized as `"in"`. #[ast_meta] #[estree(ts_type = "'in'", raw_deser = "'in'")] -pub struct In<'b, T>(#[expect(dead_code)] pub &'b T); +pub struct In(pub T); -impl ESTree for In<'_, T> { +impl ESTree for In { fn serialize(&self, serializer: S) { JsonSafeString("in").serialize(serializer); } @@ -214,9 +214,9 @@ impl ESTree for In<'_, T> { /// Serialized as `"init"`. #[ast_meta] #[estree(ts_type = "'init'", raw_deser = "'init'")] -pub struct Init<'b, T>(#[expect(dead_code)] pub &'b T); +pub struct Init(pub T); -impl ESTree for Init<'_, T> { +impl ESTree for Init { fn serialize(&self, serializer: S) { JsonSafeString("init").serialize(serializer); } @@ -225,9 +225,9 @@ impl ESTree for Init<'_, T> { /// Serialized as `"this"`. #[ast_meta] #[estree(ts_type = "'this'", raw_deser = "'this'")] -pub struct This<'b, T>(#[expect(dead_code)] pub &'b T); +pub struct This(pub T); -impl ESTree for This<'_, T> { +impl ESTree for This { fn serialize(&self, serializer: S) { JsonSafeString("this").serialize(serializer); } @@ -236,9 +236,9 @@ impl ESTree for This<'_, T> { /// Serialized as `[]`. #[ast_meta] #[estree(ts_type = "[]", raw_deser = "[]")] -pub struct EmptyArray<'b, T>(#[expect(dead_code)] pub &'b T); +pub struct EmptyArray(pub T); -impl ESTree for EmptyArray<'_, T> { +impl ESTree for EmptyArray { fn serialize(&self, serializer: S) { [(); 0].serialize(serializer); } @@ -247,9 +247,9 @@ impl ESTree for EmptyArray<'_, T> { #[ast_meta] #[estree(ts_type = "[]", raw_deser = "[]")] #[ts] -pub struct TsEmptyArray<'b, T>(#[expect(dead_code)] pub &'b T); +pub struct TsEmptyArray(pub T); -impl ESTree for TsEmptyArray<'_, T> { +impl ESTree for TsEmptyArray { fn serialize(&self, serializer: S) { [(); 0].serialize(serializer); } @@ -532,8 +532,8 @@ impl ESTree for FormalParametersRest<'_, '_> { state.serialize_field("argument", &rest.argument.kind); state.serialize_ts_field("typeAnnotation", &rest.argument.type_annotation); state.serialize_ts_field("optional", &rest.argument.optional); - state.serialize_ts_field("decorators", &EmptyArray(&())); - state.serialize_ts_field("value", &Null(&())); + state.serialize_ts_field("decorators", &EmptyArray(())); + state.serialize_ts_field("value", &Null(())); state.end(); } }