Skip to content

Commit

Permalink
feat(ast, syntax, ast_tools): Introduce GetNodeId trait.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Sep 16, 2024
1 parent f5344f9 commit 41cd11d
Show file tree
Hide file tree
Showing 12 changed files with 4,045 additions and 229 deletions.
1 change: 1 addition & 0 deletions .github/.generated_ast_watch_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ src:
- 'crates/oxc_ast/src/generated/derive_clone_in.rs'
- 'crates/oxc_regular_expression/src/generated/derive_clone_in.rs'
- 'crates/oxc_syntax/src/generated/derive_clone_in.rs'
- 'crates/oxc_ast/src/generated/derive_get_node_id.rs'
- 'crates/oxc_ast/src/generated/derive_get_span.rs'
- 'crates/oxc_ast/src/generated/derive_get_span_mut.rs'
- 'crates/oxc_ast/src/generated/derive_content_eq.rs'
Expand Down
233 changes: 117 additions & 116 deletions crates/oxc_ast/src/ast/js.rs

Large diffs are not rendered by default.

41 changes: 21 additions & 20 deletions crates/oxc_ast/src/ast/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use oxc_allocator::{Box, CloneIn, Vec};
use oxc_ast_macros::ast;
use oxc_span::{cmp::ContentEq, hash::ContentHash, Atom, GetSpan, GetSpanMut, Span};
use oxc_syntax::node::GetNodeId;
#[cfg(feature = "serialize")]
use serde::Serialize;
#[cfg(feature = "serialize")]
Expand Down Expand Up @@ -38,7 +39,7 @@ use super::{inherit_variants, js::*, literal::*, ts::*};
/// See: [JSX Syntax](https://facebook.github.io/jsx/)
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type", rename_all = "camelCase")]
pub struct JSXElement<'a> {
Expand Down Expand Up @@ -69,7 +70,7 @@ pub struct JSXElement<'a> {
/// ```
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type", rename_all = "camelCase")]
pub struct JSXOpeningElement<'a> {
Expand Down Expand Up @@ -103,7 +104,7 @@ pub struct JSXOpeningElement<'a> {
/// ```
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct JSXClosingElement<'a> {
Expand All @@ -122,7 +123,7 @@ pub struct JSXClosingElement<'a> {
/// See: [`React.Fragment`](https://react.dev/reference/react/Fragment)
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type", rename_all = "camelCase")]
pub struct JSXFragment<'a> {
Expand Down Expand Up @@ -161,7 +162,7 @@ pub struct JSXClosingFragment {
/// JSX Element Name
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(untagged)]
pub enum JSXElementName<'a> {
Expand All @@ -186,7 +187,7 @@ pub enum JSXElementName<'a> {
/// ```
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct JSXNamespacedName<'a> {
Expand Down Expand Up @@ -215,7 +216,7 @@ pub struct JSXNamespacedName<'a> {
/// [`member expression`]: JSXMemberExpressionObject::MemberExpression
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct JSXMemberExpression<'a> {
Expand All @@ -229,7 +230,7 @@ pub struct JSXMemberExpression<'a> {

#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(untagged)]
pub enum JSXMemberExpressionObject<'a> {
Expand All @@ -253,7 +254,7 @@ pub enum JSXMemberExpressionObject<'a> {
/// ```
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct JSXExpressionContainer<'a> {
Expand All @@ -272,7 +273,7 @@ inherit_variants! {
/// [`ast` module docs]: `super`
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(untagged)]
pub enum JSXExpression<'a> {
Expand All @@ -285,7 +286,7 @@ pub enum JSXExpression<'a> {
/// An empty JSX expression (`{}`)
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct JSXEmptyExpression {
Expand All @@ -306,7 +307,7 @@ pub struct JSXEmptyExpression {
/// ```
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(untagged)]
pub enum JSXAttributeItem<'a> {
Expand All @@ -329,7 +330,7 @@ pub enum JSXAttributeItem<'a> {
/// // name ^^^ ^^^^ value
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct JSXAttribute<'a> {
Expand All @@ -352,7 +353,7 @@ pub struct JSXAttribute<'a> {
/// ```
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct JSXSpreadAttribute<'a> {
Expand All @@ -378,7 +379,7 @@ pub struct JSXSpreadAttribute<'a> {
/// ```
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(untagged)]
pub enum JSXAttributeName<'a> {
Expand Down Expand Up @@ -408,7 +409,7 @@ pub enum JSXAttributeName<'a> {
/// ```
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(untagged)]
pub enum JSXAttributeValue<'a> {
Expand All @@ -425,7 +426,7 @@ pub enum JSXAttributeValue<'a> {
/// [`IdentifierName`]: super::IdentifierName
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct JSXIdentifier<'a> {
Expand All @@ -442,7 +443,7 @@ pub struct JSXIdentifier<'a> {
/// Part of a [`JSXElement`].
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(untagged)]
pub enum JSXChild<'a> {
Expand All @@ -463,7 +464,7 @@ pub enum JSXChild<'a> {
/// Variant of [`JSXChild`] that represents an object spread (`{...expression}`).
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct JSXSpreadChild<'a> {
Expand All @@ -485,7 +486,7 @@ pub struct JSXSpreadChild<'a> {
/// ```
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct JSXText<'a> {
Expand Down
17 changes: 10 additions & 7 deletions crates/oxc_ast/src/ast/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use oxc_allocator::{Box, CloneIn};
use oxc_ast_macros::ast;
use oxc_regular_expression::ast::Pattern;
use oxc_span::{cmp::ContentEq, hash::ContentHash, Atom, GetSpan, GetSpanMut, Span};
use oxc_syntax::number::{BigintBase, NumberBase};
use oxc_syntax::{
node::GetNodeId,
number::{BigintBase, NumberBase},
};
#[cfg(feature = "serialize")]
use serde::Serialize;
#[cfg(feature = "serialize")]
Expand All @@ -25,7 +28,7 @@ use tsify::Tsify;
/// <https://tc39.es/ecma262/#prod-BooleanLiteral>
#[ast(visit)]
#[derive(Debug, Clone)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct BooleanLiteral {
Expand All @@ -39,7 +42,7 @@ pub struct BooleanLiteral {
/// <https://tc39.es/ecma262/#sec-null-literals>
#[ast(visit)]
#[derive(Debug, Clone)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct NullLiteral {
Expand All @@ -52,7 +55,7 @@ pub struct NullLiteral {
/// <https://tc39.es/ecma262/#sec-literals-numeric-literals>
#[ast(visit)]
#[derive(Debug, Clone)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct NumericLiteral<'a> {
Expand All @@ -70,7 +73,7 @@ pub struct NumericLiteral<'a> {
/// BigInt literal
#[ast(visit)]
#[derive(Debug, Clone)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct BigIntLiteral<'a> {
Expand All @@ -88,7 +91,7 @@ pub struct BigIntLiteral<'a> {
/// <https://tc39.es/ecma262/#sec-literals-regular-expression-literals>
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct RegExpLiteral<'a> {
Expand Down Expand Up @@ -144,7 +147,7 @@ pub struct EmptyObject;
/// <https://tc39.es/ecma262/#sec-literals-string-literals>
#[ast(visit)]
#[derive(Debug, Clone)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[generate_derive(CloneIn, GetNodeId, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
pub struct StringLiteral<'a> {
Expand Down
Loading

0 comments on commit 41cd11d

Please sign in to comment.