From d345b84a7281d21f94cdaeb5ae2fb4d3524d9034 Mon Sep 17 00:00:00 2001
From: rzvxa <3788964+rzvxa@users.noreply.github.com>
Date: Sat, 20 Jul 2024 12:22:26 +0000
Subject: [PATCH] feat(ast): add `#[ast]` attribute to non-visited AST types.
(#4309)
Mark everything mentioned in https://github.com/oxc-project/oxc/pull/3815#issuecomment-2186736258 as AST.
We now error on the occurrence of non-ast items in the source of truth. It doesn't make sure that all fields and variants are `#[ast]` and therefore `repr_stable` but there are only a handful of non-AST types used here(mainly Atom and Span). Since we don't have access to the external types we can't make sure of it unless we find a way to const assert it.
The best we can do until then is to check all field/variant types to be either `#[ast]` or in a white list. I can add this check to the codegen in an upcoming PR.
---
crates/oxc_ast/src/ast/js.rs | 10 ++++++++++
crates/oxc_ast/src/ast/jsx.rs | 2 ++
crates/oxc_ast/src/ast/literal.rs | 2 ++
crates/oxc_ast/src/ast/ts.rs | 6 ++++++
tasks/ast_codegen/src/schema.rs | 2 +-
5 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs
index 4c516b713..616db7148 100644
--- a/crates/oxc_ast/src/ast/js.rs
+++ b/crates/oxc_ast/src/ast/js.rs
@@ -322,6 +322,7 @@ pub enum PropertyKey<'a> {
}
}
+#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(rename_all = "lowercase"))]
@@ -369,6 +370,7 @@ pub struct TemplateElement<'a> {
}
/// See [template-strings-cooked-vs-raw](https://exploringjs.com/impatient-js/ch_template-literals.html#template-strings-cooked-vs-raw)
+#[ast]
#[derive(Debug, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
pub struct TemplateElementValue<'a> {
@@ -1012,6 +1014,7 @@ pub struct VariableDeclaration<'a> {
pub declare: bool,
}
+#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(rename_all = "lowercase"))]
@@ -1475,6 +1478,7 @@ pub struct Function<'a> {
pub scope_id: Cell