Skip to content
Merged
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
29 changes: 29 additions & 0 deletions crates/oxc_ast/src/ast_kind_impl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use oxc_span::Atom;
use oxc_syntax::scope::ScopeId;

use super::{ast::*, AstKind};

Expand Down Expand Up @@ -93,6 +94,34 @@ impl<'a> AstKind<'a> {
}
}

/// If this node is a container, get the [`ScopeId`] it creates.
///
/// Will always be none if semantic analysis has not been run.
pub fn get_container_scope_id(self) -> Option<ScopeId> {
match self {
Self::Program(p) => p.scope_id.get(),
Self::BlockStatement(b) => b.scope_id.get(),
Self::ForStatement(f) => f.scope_id.get(),
Self::ForInStatement(f) => f.scope_id.get(),
Self::ForOfStatement(f) => f.scope_id.get(),
Self::SwitchStatement(switch) => switch.scope_id.get(),
Self::CatchClause(catch) => catch.scope_id.get(),
Self::Function(f) => f.scope_id.get(),
Self::ArrowFunctionExpression(f) => f.scope_id.get(),
Self::Class(class) => class.scope_id.get(),
Self::StaticBlock(b) => b.scope_id.get(),
Self::TSEnumDeclaration(e) => e.scope_id.get(),
Self::TSConditionalType(e) => e.scope_id.get(),
Self::TSTypeAliasDeclaration(e) => e.scope_id.get(),
Self::TSInterfaceDeclaration(e) => e.scope_id.get(),
Self::TSMethodSignature(e) => e.scope_id.get(),
Self::TSConstructSignatureDeclaration(e) => e.scope_id.get(),
Self::TSModuleDeclaration(e) => e.scope_id.get(),
Self::TSMappedType(e) => e.scope_id.get(),
_ => None,
}
}

pub fn from_expression(e: &'a Expression<'a>) -> Self {
match e {
Expression::BooleanLiteral(e) => Self::BooleanLiteral(e),
Expand Down