diff --git a/crates/oxc_ast/src/ast_kind_impl.rs b/crates/oxc_ast/src/ast_kind_impl.rs index 11387e4d6..57763e901 100644 --- a/crates/oxc_ast/src/ast_kind_impl.rs +++ b/crates/oxc_ast/src/ast_kind_impl.rs @@ -1,4 +1,5 @@ use oxc_span::Atom; +use oxc_syntax::scope::ScopeId; use super::{ast::*, AstKind}; @@ -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 { + 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),