refactor(ast): use scope_id etc methods (#7130)

Utilize the methods added in #7127 in `oxc_ast`.
This commit is contained in:
overlookmotel 2024-11-05 02:25:28 +00:00
parent cacfb9b326
commit fac5042afa
2 changed files with 21 additions and 21 deletions

View file

@ -970,10 +970,10 @@ impl<'a> Function<'a> {
/// Get the [`SymbolId`] this [`Function`] is bound to.
///
/// Returns [`None`] for anonymous functions, or if semantic analysis was skipped.
/// Returns [`None`] for anonymous functions.
#[inline]
pub fn symbol_id(&self) -> Option<SymbolId> {
self.id.as_ref().and_then(|id| id.symbol_id.get())
self.id.as_ref().map(BindingIdentifier::symbol_id)
}
/// `true` for overload signatures and `declare function` statements.

View file

@ -100,25 +100,25 @@ impl<'a> AstKind<'a> {
/// 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(),
Self::Program(p) => Some(p.scope_id()),
Self::BlockStatement(b) => Some(b.scope_id()),
Self::ForStatement(f) => Some(f.scope_id()),
Self::ForInStatement(f) => Some(f.scope_id()),
Self::ForOfStatement(f) => Some(f.scope_id()),
Self::SwitchStatement(switch) => Some(switch.scope_id()),
Self::CatchClause(catch) => Some(catch.scope_id()),
Self::Function(f) => Some(f.scope_id()),
Self::ArrowFunctionExpression(f) => Some(f.scope_id()),
Self::Class(class) => Some(class.scope_id()),
Self::StaticBlock(b) => Some(b.scope_id()),
Self::TSEnumDeclaration(e) => Some(e.scope_id()),
Self::TSConditionalType(e) => Some(e.scope_id()),
Self::TSTypeAliasDeclaration(e) => Some(e.scope_id()),
Self::TSInterfaceDeclaration(e) => Some(e.scope_id()),
Self::TSMethodSignature(e) => Some(e.scope_id()),
Self::TSConstructSignatureDeclaration(e) => Some(e.scope_id()),
Self::TSModuleDeclaration(e) => Some(e.scope_id()),
Self::TSMappedType(e) => Some(e.scope_id()),
_ => None,
}
}