diff --git a/Cargo.lock b/Cargo.lock
index 227354b5e..2e135b0a9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1356,6 +1356,7 @@ dependencies = [
"num-bigint",
"oxc_allocator",
"oxc_index",
+ "oxc_macros",
"oxc_span",
"oxc_syntax",
"ryu-js",
@@ -1699,6 +1700,7 @@ dependencies = [
"oxc_ast",
"oxc_diagnostics",
"oxc_index",
+ "oxc_macros",
"oxc_parser",
"oxc_span",
"oxc_syntax",
@@ -1717,6 +1719,7 @@ version = "0.9.0"
dependencies = [
"compact_str",
"miette",
+ "oxc_macros",
"serde",
"tsify",
"wasm-bindgen",
@@ -1730,6 +1733,7 @@ dependencies = [
"dashmap",
"indexmap",
"oxc_index",
+ "oxc_macros",
"oxc_span",
"phf",
"rustc-hash",
diff --git a/crates/oxc_ast/Cargo.toml b/crates/oxc_ast/Cargo.toml
index 2960124ef..8869d6664 100644
--- a/crates/oxc_ast/Cargo.toml
+++ b/crates/oxc_ast/Cargo.toml
@@ -22,6 +22,7 @@ oxc_allocator = { workspace = true }
oxc_span = { workspace = true }
oxc_syntax = { workspace = true }
oxc_index = { workspace = true }
+oxc_macros = { workspace = true }
bitflags = { workspace = true }
num-bigint = { workspace = true }
diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs
index 75f1303bd..077ad4933 100644
--- a/crates/oxc_ast/src/ast/js.rs
+++ b/crates/oxc_ast/src/ast/js.rs
@@ -1,6 +1,7 @@
use std::{cell::Cell, fmt, hash::Hash};
use oxc_allocator::{Box, Vec};
+use oxc_macros::SerAttrs;
use oxc_span::{Atom, CompactStr, SourceType, Span};
use oxc_syntax::{
operator::{
@@ -33,11 +34,12 @@ export interface FormalParameterRest extends Span {
}
"#;
-#[derive(Debug, Hash)]
-#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))]
+#[derive(Debug, Hash, SerAttrs)]
+#[cfg_attr(feature = "serde", derive(Serialize))]
#[cfg_attr(feature = "wasm", derive(Tsify))]
+#[serde(tag = "type", rename_all = "camelCase")]
pub struct Program<'a> {
- #[cfg_attr(feature = "serde", serde(flatten))]
+ #[serde(flatten)]
pub span: Span,
pub source_type: SourceType,
pub directives: Vec<'a, Directive<'a>>,
@@ -58,9 +60,10 @@ impl<'a> Program<'a> {
}
/// Expression
-#[derive(Debug, Hash)]
-#[cfg_attr(feature = "serde", derive(Serialize), serde(untagged))]
+#[derive(Debug, Hash, SerAttrs)]
+#[cfg_attr(feature = "serde", derive(Serialize))]
#[cfg_attr(feature = "wasm", derive(Tsify))]
+#[serde(untagged)]
pub enum Expression<'a> {
BooleanLiteral(Box<'a, BooleanLiteral>),
NullLiteral(Box<'a, NullLiteral>),
@@ -316,10 +319,11 @@ impl<'a> Expression<'a> {
}
/// Identifier Name
-#[derive(Debug, Clone, Hash)]
-#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename = "Identifier"))]
+#[derive(Debug, Clone, Hash, SerAttrs)]
+#[cfg_attr(feature = "serde", derive(Serialize))]
+#[serde(tag = "type", rename = "Identifier")]
pub struct IdentifierName<'a> {
- #[cfg_attr(feature = "serde", serde(flatten))]
+ #[serde(flatten)]
pub span: Span,
pub name: Atom<'a>,
}
@@ -331,15 +335,16 @@ impl<'a> IdentifierName<'a> {
}
/// Identifier Reference
-#[derive(Debug, Clone)]
-#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename = "Identifier"))]
+#[derive(Debug, Clone, SerAttrs)]
+#[cfg_attr(feature = "serde", derive(Serialize))]
+#[serde(tag = "type", rename = "Identifier")]
pub struct IdentifierReference<'a> {
- #[cfg_attr(feature = "serde", serde(flatten))]
+ #[serde(flatten)]
pub span: Span,
pub name: Atom<'a>,
- #[cfg_attr(feature = "serde", serde(skip))]
+ #[serde(skip)]
pub reference_id: Cell