Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ast): add GetAddress trait #6652

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions crates/oxc_ast/src/address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! Defines the `GetAddress` trait for getting the memory address of AST.

use oxc_allocator::Address;

use crate::ast::Statement;

/// Trait for getting the memory address of AST.
pub trait GetAddress {
fn address(&self) -> Address;
}

impl<'a> GetAddress for Statement<'a> {
fn address(&self) -> Address {
match self {
Statement::BlockStatement(s) => s.address(),
Statement::BreakStatement(s) => s.address(),
Statement::ContinueStatement(s) => s.address(),
Statement::DebuggerStatement(s) => s.address(),
Statement::DoWhileStatement(s) => s.address(),
Statement::EmptyStatement(s) => s.address(),
Statement::ExpressionStatement(s) => s.address(),
Statement::ForInStatement(s) => s.address(),
Statement::ForOfStatement(s) => s.address(),
Statement::ForStatement(s) => s.address(),
Statement::IfStatement(s) => s.address(),
Statement::LabeledStatement(s) => s.address(),
Statement::ReturnStatement(s) => s.address(),
Statement::SwitchStatement(s) => s.address(),
Statement::ThrowStatement(s) => s.address(),
Statement::TryStatement(s) => s.address(),
Statement::WhileStatement(s) => s.address(),
Statement::WithStatement(s) => s.address(),
Statement::VariableDeclaration(s) => s.address(),
Statement::FunctionDeclaration(s) => s.address(),
Statement::ClassDeclaration(s) => s.address(),
Statement::TSTypeAliasDeclaration(s) => s.address(),
Statement::TSInterfaceDeclaration(s) => s.address(),
Statement::TSEnumDeclaration(s) => s.address(),
Statement::TSModuleDeclaration(s) => s.address(),
Statement::TSImportEqualsDeclaration(s) => s.address(),
Statement::ImportDeclaration(s) => s.address(),
Statement::ExportAllDeclaration(s) => s.address(),
Statement::ExportDefaultDeclaration(s) => s.address(),
Statement::ExportNamedDeclaration(s) => s.address(),
Statement::TSExportAssignment(s) => s.address(),
Statement::TSNamespaceExportDeclaration(s) => s.address(),
}
}
}
1 change: 1 addition & 0 deletions crates/oxc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#[cfg(feature = "serialize")]
mod serialize;

pub mod address;
pub mod ast;
mod ast_builder_impl;
mod ast_impl;
Expand Down
Loading