diff --git a/crates/oxc_linter/src/ast_util.rs b/crates/oxc_linter/src/ast_util.rs index 61475e80d0aed..6fd3e2abbe84d 100644 --- a/crates/oxc_linter/src/ast_util.rs +++ b/crates/oxc_linter/src/ast_util.rs @@ -284,7 +284,7 @@ pub fn get_declaration_of_variable<'a, 'b>( ) -> Option<&'b AstNode<'a>> { let symbol_id = get_symbol_id_of_variable(ident, semantic)?; let symbol_table = semantic.scoping(); - Some(semantic.nodes().get_node(symbol_table.get_symbol_declaration(symbol_id))) + Some(semantic.nodes().get_node(symbol_table.symbol_declaration(symbol_id))) } pub fn get_declaration_from_reference_id<'a, 'b>( @@ -293,7 +293,7 @@ pub fn get_declaration_from_reference_id<'a, 'b>( ) -> Option<&'b AstNode<'a>> { let symbol_table = semantic.scoping(); let symbol_id = symbol_table.get_reference(reference_id).symbol_id()?; - Some(semantic.nodes().get_node(symbol_table.get_symbol_declaration(symbol_id))) + Some(semantic.nodes().get_node(symbol_table.symbol_declaration(symbol_id))) } pub fn get_symbol_id_of_variable( @@ -569,7 +569,7 @@ pub fn could_be_error(ctx: &LintContext, expr: &Expression) -> bool { let Some(symbol_id) = reference.symbol_id() else { return true; }; - let decl = ctx.nodes().get_node(ctx.scoping().get_symbol_declaration(symbol_id)); + let decl = ctx.nodes().get_node(ctx.scoping().symbol_declaration(symbol_id)); match decl.kind() { AstKind::VariableDeclarator(decl) => { if let Some(init) = &decl.init { diff --git a/crates/oxc_linter/src/rules/eslint/no_func_assign.rs b/crates/oxc_linter/src/rules/eslint/no_func_assign.rs index 642982de6f6e4..24af0b4f7cf08 100644 --- a/crates/oxc_linter/src/rules/eslint/no_func_assign.rs +++ b/crates/oxc_linter/src/rules/eslint/no_func_assign.rs @@ -68,7 +68,7 @@ declare_oxc_lint!( impl Rule for NoFuncAssign { fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext<'_>) { let symbol_table = ctx.scoping(); - let decl = symbol_table.get_symbol_declaration(symbol_id); + let decl = symbol_table.symbol_declaration(symbol_id); if let AstKind::Function(_) = ctx.nodes().kind(decl) { for reference in symbol_table.get_resolved_references(symbol_id) { if reference.is_write() { diff --git a/crates/oxc_linter/src/rules/eslint/no_import_assign.rs b/crates/oxc_linter/src/rules/eslint/no_import_assign.rs index 2317ee6073868..134a22a95f623 100644 --- a/crates/oxc_linter/src/rules/eslint/no_import_assign.rs +++ b/crates/oxc_linter/src/rules/eslint/no_import_assign.rs @@ -54,7 +54,7 @@ impl Rule for NoImportAssign { fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext<'_>) { let symbol_table = ctx.scoping(); if symbol_table.symbol_flags(symbol_id).is_import() { - let kind = ctx.nodes().kind(symbol_table.get_symbol_declaration(symbol_id)); + let kind = ctx.nodes().kind(symbol_table.symbol_declaration(symbol_id)); let is_namespace_specifier = matches!(kind, AstKind::ImportNamespaceSpecifier(_)); for reference in symbol_table.get_resolved_references(symbol_id) { if is_namespace_specifier { diff --git a/crates/oxc_linter/src/rules/eslint/no_obj_calls.rs b/crates/oxc_linter/src/rules/eslint/no_obj_calls.rs index 701d79e3b2ff6..13fa2b8cebb15 100644 --- a/crates/oxc_linter/src/rules/eslint/no_obj_calls.rs +++ b/crates/oxc_linter/src/rules/eslint/no_obj_calls.rs @@ -99,7 +99,7 @@ fn resolve_global_binding<'a, 'b: 'a>( return None; }; - let decl = nodes.get_node(symbols.get_symbol_declaration(binding_id)); + let decl = nodes.get_node(symbols.symbol_declaration(binding_id)); match decl.kind() { AstKind::VariableDeclarator(parent_decl) => { if !parent_decl.id.kind.is_binding_identifier() { diff --git a/crates/oxc_linter/src/rules/eslint/no_redeclare.rs b/crates/oxc_linter/src/rules/eslint/no_redeclare.rs index 9376fad35a4c7..c877093040c60 100644 --- a/crates/oxc_linter/src/rules/eslint/no_redeclare.rs +++ b/crates/oxc_linter/src/rules/eslint/no_redeclare.rs @@ -62,13 +62,13 @@ impl Rule for NoRedeclare { fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext) { let symbol_table = ctx.scoping(); - let decl_node_id = symbol_table.get_symbol_declaration(symbol_id); + let decl_node_id = symbol_table.symbol_declaration(symbol_id); match ctx.nodes().kind(decl_node_id) { AstKind::VariableDeclarator(var) => { if let BindingPatternKind::BindingIdentifier(ident) = &var.id.kind { let symbol_name = symbol_table.symbol_name(symbol_id); if symbol_name == ident.name.as_str() { - for span in ctx.scoping().get_symbol_redeclarations(symbol_id) { + for span in ctx.scoping().symbol_redeclarations(symbol_id) { self.report_diagnostic(ctx, *span, ident); } } @@ -78,7 +78,7 @@ impl Rule for NoRedeclare { if let BindingPatternKind::BindingIdentifier(ident) = ¶m.pattern.kind { let symbol_name = symbol_table.symbol_name(symbol_id); if symbol_name == ident.name.as_str() { - for span in ctx.scoping().get_symbol_redeclarations(symbol_id) { + for span in ctx.scoping().symbol_redeclarations(symbol_id) { self.report_diagnostic(ctx, *span, ident); } } diff --git a/crates/oxc_linter/src/rules/eslint/no_shadow_restricted_names.rs b/crates/oxc_linter/src/rules/eslint/no_shadow_restricted_names.rs index 1b9b30bfb0084..d942fa6829ce5 100644 --- a/crates/oxc_linter/src/rules/eslint/no_shadow_restricted_names.rs +++ b/crates/oxc_linter/src/rules/eslint/no_shadow_restricted_names.rs @@ -85,7 +85,7 @@ impl Rule for NoShadowRestrictedNames { if name == "undefined" { // Allow to declare `undefined` variable but not allow to assign value to it. - let node_id = ctx.scoping().get_symbol_declaration(symbol_id); + let node_id = ctx.scoping().symbol_declaration(symbol_id); if let AstKind::VariableDeclarator(declarator) = ctx.nodes().kind(node_id) { if declarator.init.is_none() && ctx @@ -101,7 +101,7 @@ impl Rule for NoShadowRestrictedNames { let span = ctx.scoping().symbol_span(symbol_id); ctx.diagnostic(no_shadow_restricted_names_diagnostic(name, span)); - for &span in ctx.scoping().get_symbol_redeclarations(symbol_id) { + for &span in ctx.scoping().symbol_redeclarations(symbol_id) { ctx.diagnostic(no_shadow_restricted_names_diagnostic(name, span)); } } diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/symbol.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/symbol.rs index 8c8c17a6cab6e..8fe89189c9a65 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/symbol.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/symbol.rs @@ -57,7 +57,7 @@ impl<'s, 'a> Symbol<'s, 'a> { #[inline] pub fn scope_id(&self) -> ScopeId { - self.scoping().get_symbol_scope_id(self.id) + self.scoping().symbol_scope_id(self.id) } #[inline] @@ -79,12 +79,12 @@ impl<'s, 'a> Symbol<'s, 'a> { /// Is this [`Symbol`] declared in the root scope? pub fn is_root(&self) -> bool { - self.scoping().get_symbol_scope_id(self.id) == self.scoping().root_scope_id() + self.scoping().symbol_scope_id(self.id) == self.scoping().root_scope_id() } #[inline] fn declaration_id(&self) -> NodeId { - self.scoping().get_symbol_declaration(self.id) + self.scoping().symbol_declaration(self.id) } #[inline] diff --git a/crates/oxc_linter/src/rules/nextjs/no_duplicate_head.rs b/crates/oxc_linter/src/rules/nextjs/no_duplicate_head.rs index 21d464d962d9a..592f05be28070 100644 --- a/crates/oxc_linter/src/rules/nextjs/no_duplicate_head.rs +++ b/crates/oxc_linter/src/rules/nextjs/no_duplicate_head.rs @@ -58,7 +58,7 @@ impl Rule for NoDuplicateHead { return; } - let scope_id = symbols.get_symbol_scope_id(symbol_id); + let scope_id = symbols.symbol_scope_id(symbol_id); if scope_id != ctx.scoping().root_scope_id() { return; } diff --git a/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs b/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs index 2cea1435a7458..db11507495e36 100644 --- a/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs +++ b/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs @@ -140,7 +140,7 @@ impl Rule for NoAccumulatingSpread { let Some(referenced_symbol_id) = reference.symbol_id() else { return; }; - let declaration_id = symbols.get_symbol_declaration(referenced_symbol_id); + let declaration_id = symbols.symbol_declaration(referenced_symbol_id); let Some(declaration) = ctx.nodes().parent_node(declaration_id) else { return; }; diff --git a/crates/oxc_linter/src/rules/oxc/no_async_endpoint_handlers.rs b/crates/oxc_linter/src/rules/oxc/no_async_endpoint_handlers.rs index 0ec83530b2cfc..ab416750cbd85 100644 --- a/crates/oxc_linter/src/rules/oxc/no_async_endpoint_handlers.rs +++ b/crates/oxc_linter/src/rules/oxc/no_async_endpoint_handlers.rs @@ -224,7 +224,7 @@ impl NoAsyncEndpointHandlers { return; } - let decl_id = ctx.scoping().get_symbol_declaration(symbol_id); + let decl_id = ctx.scoping().symbol_declaration(symbol_id); let decl_node = ctx.nodes().get_node(decl_id); let registered_at = registered_at.or(Some(handler.span)); match decl_node.kind() { diff --git a/crates/oxc_linter/src/rules/oxc/no_map_spread.rs b/crates/oxc_linter/src/rules/oxc/no_map_spread.rs index 83f59866b4c64..d60a54a295b96 100644 --- a/crates/oxc_linter/src/rules/oxc/no_map_spread.rs +++ b/crates/oxc_linter/src/rules/oxc/no_map_spread.rs @@ -423,7 +423,7 @@ impl NoMapSpread { } if self.ignore_args { - let declaration = ctx.nodes().get_node(ctx.scoping().get_symbol_declaration(symbol_id)); + let declaration = ctx.nodes().get_node(ctx.scoping().symbol_declaration(symbol_id)); if matches!(declaration.kind(), AstKind::FormalParameter(_)) { return true; } @@ -677,7 +677,7 @@ where else { return; }; - let declaration_scope = self.ctx.scoping().get_symbol_scope_id(symbol_id); + let declaration_scope = self.ctx.scoping().symbol_scope_id(symbol_id); // symbol is not declared within the mapper callback if !self @@ -691,7 +691,7 @@ where // walk the declaration let declaration_node = - self.ctx.nodes().get_node(self.ctx.scoping().get_symbol_declaration(symbol_id)); + self.ctx.nodes().get_node(self.ctx.scoping().symbol_declaration(symbol_id)); self.visit_kind(declaration_node.kind()); } _ => {} diff --git a/crates/oxc_linter/src/rules/react/exhaustive_deps.rs b/crates/oxc_linter/src/rules/react/exhaustive_deps.rs index cd9f426d8ed0b..2eadb2a7bd4ca 100644 --- a/crates/oxc_linter/src/rules/react/exhaustive_deps.rs +++ b/crates/oxc_linter/src/rules/react/exhaustive_deps.rs @@ -477,7 +477,7 @@ impl Rule for ExhaustiveDeps { for dependency in &declared_dependencies { if let Some(symbol_id) = dependency.symbol_id { - let dependency_scope_id = ctx.scoping().get_symbol_scope_id(symbol_id); + let dependency_scope_id = ctx.scoping().symbol_scope_id(symbol_id); if !(ctx .semantic() .scoping() diff --git a/crates/oxc_linter/src/rules/typescript/no_non_null_asserted_nullish_coalescing.rs b/crates/oxc_linter/src/rules/typescript/no_non_null_asserted_nullish_coalescing.rs index e4feaf27268b4..099c198fe1b4f 100644 --- a/crates/oxc_linter/src/rules/typescript/no_non_null_asserted_nullish_coalescing.rs +++ b/crates/oxc_linter/src/rules/typescript/no_non_null_asserted_nullish_coalescing.rs @@ -98,7 +98,7 @@ fn has_assignment_before_node( } } - let declaration_id = symbol_table.get_symbol_declaration(symbol_id); + let declaration_id = symbol_table.symbol_declaration(symbol_id); let AstKind::VariableDeclarator(decl) = ctx.nodes().kind(declaration_id) else { return false; }; diff --git a/crates/oxc_linter/src/rules/typescript/no_unsafe_declaration_merging.rs b/crates/oxc_linter/src/rules/typescript/no_unsafe_declaration_merging.rs index 8a0a01945d52a..b5e945e9ef59d 100644 --- a/crates/oxc_linter/src/rules/typescript/no_unsafe_declaration_merging.rs +++ b/crates/oxc_linter/src/rules/typescript/no_unsafe_declaration_merging.rs @@ -82,7 +82,7 @@ fn check_and_diagnostic( } fn get_symbol_kind<'a>(symbol_id: SymbolId, ctx: &LintContext<'a>) -> AstKind<'a> { - ctx.nodes().get_node(ctx.scoping().get_symbol_declaration(symbol_id)).kind() + ctx.nodes().get_node(ctx.scoping().symbol_declaration(symbol_id)).kind() } #[test] diff --git a/crates/oxc_linter/src/rules/unicorn/consistent_existence_index_check.rs b/crates/oxc_linter/src/rules/unicorn/consistent_existence_index_check.rs index 933cab44bc00f..9dcec305d3014 100644 --- a/crates/oxc_linter/src/rules/unicorn/consistent_existence_index_check.rs +++ b/crates/oxc_linter/src/rules/unicorn/consistent_existence_index_check.rs @@ -91,7 +91,7 @@ impl Rule for ConsistentExistenceIndexCheck { return; }; - let declaration_node_id = ctx.scoping().get_symbol_declaration(symbol_id); + let declaration_node_id = ctx.scoping().symbol_declaration(symbol_id); let node = ctx.nodes().get_node(declaration_node_id); if let AstKind::VariableDeclarator(variables_declarator) = node.kind() { diff --git a/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs b/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs index 53f84ab548df5..1d4253b8d74f9 100644 --- a/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs +++ b/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs @@ -145,56 +145,55 @@ impl Rule for ConsistentFunctionScoping { } fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - let (function_declaration_symbol_id, function_body, reporter_span) = match node.kind() { - AstKind::Function(function) => { - if function.is_typescript_syntax() { - return; - } - - let func_scope_id = function.scope_id(); - if let Some(parent_scope_id) = ctx.scoping().get_scope_parent_id(func_scope_id) { - // Example: const foo = function bar() {}; - // The bar function scope id is 1. In order to ignore this rule, - // its parent's scope id (in this case `foo`'s scope id is 0 and is equal to root scope id) - // should be considered. - if parent_scope_id == ctx.scoping().root_scope_id() { + let (function_declaration_symbol_id, function_body, reporter_span) = + match node.kind() { + AstKind::Function(function) => { + if function.is_typescript_syntax() { return; } - } - // NOTE: function.body will always be some here because of - // checks in `is_typescript_syntax` - let Some(function_body) = &function.body else { return }; - - if let Some(binding_ident) = get_function_like_declaration(node, ctx) { - ( - binding_ident.symbol_id(), - function_body, - function - .id - .as_ref() - .map_or(Span::sized(function.span.start, 8), |func_binding_ident| { - func_binding_ident.span - }), - ) - } else if let Some(function_id) = &function.id { - (function_id.symbol_id(), function_body, function_id.span()) - } else { - return; + let func_scope_id = function.scope_id(); + if let Some(parent_scope_id) = ctx.scoping().scope_parent_id(func_scope_id) { + // Example: const foo = function bar() {}; + // The bar function scope id is 1. In order to ignore this rule, + // its parent's scope id (in this case `foo`'s scope id is 0 and is equal to root scope id) + // should be considered. + if parent_scope_id == ctx.scoping().root_scope_id() { + return; + } + } + + // NOTE: function.body will always be some here because of + // checks in `is_typescript_syntax` + let Some(function_body) = &function.body else { return }; + + if let Some(binding_ident) = get_function_like_declaration(node, ctx) { + ( + binding_ident.symbol_id(), + function_body, + function.id.as_ref().map_or( + Span::sized(function.span.start, 8), + |func_binding_ident| func_binding_ident.span, + ), + ) + } else if let Some(function_id) = &function.id { + (function_id.symbol_id(), function_body, function_id.span()) + } else { + return; + } } - } - AstKind::ArrowFunctionExpression(arrow_function) if self.check_arrow_functions => { - let Some(binding_ident) = get_function_like_declaration(node, ctx) else { - return; - }; + AstKind::ArrowFunctionExpression(arrow_function) if self.check_arrow_functions => { + let Some(binding_ident) = get_function_like_declaration(node, ctx) else { + return; + }; - (binding_ident.symbol_id(), &arrow_function.body, binding_ident.span()) - } - _ => return, - }; + (binding_ident.symbol_id(), &arrow_function.body, binding_ident.span()) + } + _ => return, + }; // if the function is declared at the root scope, we don't need to check anything - if ctx.scoping().get_symbol_scope_id(function_declaration_symbol_id) + if ctx.scoping().symbol_scope_id(function_declaration_symbol_id) == ctx.scoping().root_scope_id() { return; @@ -224,10 +223,10 @@ impl Rule for ConsistentFunctionScoping { let parent_scope_ids = { let mut current_scope_id = - ctx.scoping().get_symbol_scope_id(function_declaration_symbol_id); + ctx.scoping().symbol_scope_id(function_declaration_symbol_id); let mut parent_scope_ids = FxHashSet::default(); parent_scope_ids.insert(current_scope_id); - while let Some(parent_scope_id) = ctx.scoping().get_scope_parent_id(current_scope_id) { + while let Some(parent_scope_id) = ctx.scoping().scope_parent_id(current_scope_id) { parent_scope_ids.insert(parent_scope_id); current_scope_id = parent_scope_id; } @@ -237,7 +236,7 @@ impl Rule for ConsistentFunctionScoping { for reference_id in function_body_var_references { let reference = ctx.scoping().get_reference(reference_id); let Some(symbol_id) = reference.symbol_id() else { continue }; - let scope_id = ctx.scoping().get_symbol_scope_id(symbol_id); + let scope_id = ctx.scoping().symbol_scope_id(symbol_id); if parent_scope_ids.contains(&scope_id) && symbol_id != function_declaration_symbol_id { return; } diff --git a/crates/oxc_linter/src/rules/unicorn/no_invalid_fetch_options.rs b/crates/oxc_linter/src/rules/unicorn/no_invalid_fetch_options.rs index e6630b9c38d85..4a6f8d0a679e3 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_invalid_fetch_options.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_invalid_fetch_options.rs @@ -169,7 +169,7 @@ fn is_invalid_fetch_options<'a>( continue; }; - let decl = ctx.nodes().get_node(symbols.get_symbol_declaration(symbol_id)); + let decl = ctx.nodes().get_node(symbols.symbol_declaration(symbol_id)); match decl.kind() { AstKind::VariableDeclarator(declarator) => match &declarator.init { diff --git a/crates/oxc_linter/src/rules/unicorn/no_thenable.rs b/crates/oxc_linter/src/rules/unicorn/no_thenable.rs index 147239d9b7536..b78ba9fb73adb 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_thenable.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_thenable.rs @@ -239,7 +239,7 @@ fn check_expression(expr: &Expression, ctx: &LintContext<'_>) -> Option bool { Expression::Identifier(ident) => { if let Some(symbol_id) = ast_util::get_symbol_id_of_variable(ident, ctx) { let symbol_table = ctx.scoping(); - let node = ctx.nodes().get_node(symbol_table.get_symbol_declaration(symbol_id)); + let node = ctx.nodes().get_node(symbol_table.symbol_declaration(symbol_id)); if let AstKind::VariableDeclarator(variable_declarator) = node.kind() { if let Some(ref_expr) = &variable_declarator.init { diff --git a/crates/oxc_linter/src/utils/jest.rs b/crates/oxc_linter/src/utils/jest.rs index 02413755c2eb3..9a4439c790e83 100644 --- a/crates/oxc_linter/src/utils/jest.rs +++ b/crates/oxc_linter/src/utils/jest.rs @@ -212,7 +212,7 @@ fn collect_ids_referenced_to_import<'a, 'c>( .filter_map(|(symbol_id, reference_ids)| { let symbol_id = SymbolId::from_usize(symbol_id); if semantic.scoping().symbol_flags(symbol_id).is_import() { - let id = semantic.scoping().get_symbol_declaration(symbol_id); + let id = semantic.scoping().symbol_declaration(symbol_id); let Some(AstKind::ImportDeclaration(import_decl)) = semantic.nodes().parent_kind(id) else { diff --git a/crates/oxc_linter/src/utils/react_perf.rs b/crates/oxc_linter/src/utils/react_perf.rs index ab28b00cc4300..615e850471128 100644 --- a/crates/oxc_linter/src/utils/react_perf.rs +++ b/crates/oxc_linter/src/utils/react_perf.rs @@ -100,12 +100,11 @@ where // Symbols declared at the root scope won't (or, at least, shouldn't) be // re-assigned inside component render functions, so we can safely // ignore them. - if ctx.scoping().get_symbol_scope_id(symbol_id) == ctx.scoping().root_scope_id() { + if ctx.scoping().symbol_scope_id(symbol_id) == ctx.scoping().root_scope_id() { return; } - let declaration_node = - ctx.nodes().get_node(ctx.scoping().get_symbol_declaration(symbol_id)); + let declaration_node = ctx.nodes().get_node(ctx.scoping().symbol_declaration(symbol_id)); if let Some((decl_span, init_span)) = self.check_for_violation_on_ast_kind(&declaration_node.kind(), symbol_id) { diff --git a/crates/oxc_mangler/src/lib.rs b/crates/oxc_mangler/src/lib.rs index 188608cfca808..c93b79b1acb80 100644 --- a/crates/oxc_mangler/src/lib.rs +++ b/crates/oxc_mangler/src/lib.rs @@ -258,7 +258,7 @@ impl Mangler { // parent, so we need to include the scope where it is declared. // (for cases like `function foo() { { var x; let y; } }`) let declared_scope_id = - ast_nodes.get_node(scoping.get_symbol_declaration(symbol_id)).scope_id(); + ast_nodes.get_node(scoping.symbol_declaration(symbol_id)).scope_id(); // Calculate the scope ids that this symbol is alive in. let lived_scope_ids = scoping @@ -377,7 +377,7 @@ impl Mangler { for (symbol_id, slot) in slots.iter().copied().enumerate() { let symbol_id = SymbolId::from_usize(symbol_id); - if scoping.get_symbol_scope_id(symbol_id) == root_scope_id + if scoping.symbol_scope_id(symbol_id) == root_scope_id && (!self.options.top_level || exported_symbols.contains(&symbol_id)) { continue; diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index 7f961fd95de90..394307c1c753d 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -559,7 +559,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> { // `get_parent_id` always returns `Some` because this method is not called for `Program`. // So we could `.unwrap()` here. But that seems to produce a small perf impact, probably because // `leave_scope` then doesn't get inlined because of its larger size due to the panic code. - let parent_id = self.scoping.get_scope_parent_id(self.current_scope_id); + let parent_id = self.scoping.scope_parent_id(self.current_scope_id); debug_assert!(parent_id.is_some()); if let Some(parent_id) = parent_id { diff --git a/crates/oxc_semantic/src/lib.rs b/crates/oxc_semantic/src/lib.rs index c19b4568c0e6b..739d9f37c73ee 100644 --- a/crates/oxc_semantic/src/lib.rs +++ b/crates/oxc_semantic/src/lib.rs @@ -184,7 +184,7 @@ impl<'a> Semantic<'a> { /// Find which scope a symbol is declared in pub fn symbol_scope(&self, symbol_id: SymbolId) -> ScopeId { - self.scoping.get_symbol_scope_id(symbol_id) + self.scoping.symbol_scope_id(symbol_id) } /// Get all resolved references for a symbol @@ -196,7 +196,7 @@ impl<'a> Semantic<'a> { } pub fn symbol_declaration(&self, symbol_id: SymbolId) -> &AstNode<'a> { - self.nodes.get_node(self.scoping.get_symbol_declaration(symbol_id)) + self.nodes.get_node(self.scoping.symbol_declaration(symbol_id)) } pub fn is_reference_to_global_variable(&self, ident: &IdentifierReference) -> bool { diff --git a/crates/oxc_semantic/src/scoping.rs b/crates/oxc_semantic/src/scoping.rs index 83fe190791c43..050c90ecfa369 100644 --- a/crates/oxc_semantic/src/scoping.rs +++ b/crates/oxc_semantic/src/scoping.rs @@ -211,7 +211,7 @@ impl Scoping { } #[inline] - pub fn get_symbol_redeclarations(&self, symbol_id: SymbolId) -> &[Span] { + pub fn symbol_redeclarations(&self, symbol_id: SymbolId) -> &[Span] { if let Some(redeclaration_id) = self.symbol_redeclarations[symbol_id] { &self.cell.borrow_dependent().redeclaration_spans[redeclaration_id.index()] } else { @@ -231,7 +231,7 @@ impl Scoping { } #[inline] - pub fn get_symbol_scope_id(&self, symbol_id: SymbolId) -> ScopeId { + pub fn symbol_scope_id(&self, symbol_id: SymbolId) -> ScopeId { self.symbol_scope_ids[symbol_id] } @@ -246,7 +246,7 @@ impl Scoping { /// [`BindingIdentifier`]: oxc_ast::ast::BindingIdentifier /// [`BindingPattern`]: oxc_ast::ast::BindingPattern #[inline] - pub fn get_symbol_declaration(&self, symbol_id: SymbolId) -> NodeId { + pub fn symbol_declaration(&self, symbol_id: SymbolId) -> NodeId { self.symbol_declarations[symbol_id] } @@ -521,7 +521,7 @@ impl Scoping { } #[inline] - pub fn get_scope_parent_id(&self, scope_id: ScopeId) -> Option { + pub fn scope_parent_id(&self, scope_id: ScopeId) -> Option { self.scope_parent_ids[scope_id] } diff --git a/crates/oxc_semantic/tests/conformance/test_symbol_declaration.rs b/crates/oxc_semantic/tests/conformance/test_symbol_declaration.rs index 3386a37c1b7d2..b134fa344c4aa 100644 --- a/crates/oxc_semantic/tests/conformance/test_symbol_declaration.rs +++ b/crates/oxc_semantic/tests/conformance/test_symbol_declaration.rs @@ -75,7 +75,7 @@ impl ConformanceTest for SymbolDeclarationTest { symbol_id: oxc_semantic::SymbolId, semantic: &Semantic<'_>, ) -> TestResult { - let declaration_id = semantic.scoping().get_symbol_declaration(symbol_id); + let declaration_id = semantic.scoping().symbol_declaration(symbol_id); let declaration = semantic.nodes().get_node(declaration_id); let span = semantic.scoping().symbol_span(symbol_id); diff --git a/crates/oxc_semantic/tests/integration/scopes.rs b/crates/oxc_semantic/tests/integration/scopes.rs index b589584ebab46..26fc5d997589a 100644 --- a/crates/oxc_semantic/tests/integration/scopes.rs +++ b/crates/oxc_semantic/tests/integration/scopes.rs @@ -23,7 +23,7 @@ fn test_only_program() { // ancestors assert_eq!(scopes.scope_ancestors(root).count(), 1); - assert!(scopes.get_scope_parent_id(root).is_none()); + assert!(scopes.scope_parent_id(root).is_none()); } #[test] @@ -101,7 +101,7 @@ fn test_function_level_strict() { .is_in_scope(ScopeFlags::StrictMode | ScopeFlags::Function) .expect(|(semantic, symbol_id)| -> Result<(), &'static str> { let scope_id = semantic.symbol_scope(symbol_id); - let Some(parent_scope_id) = semantic.scoping().get_scope_parent_id(scope_id) else { + let Some(parent_scope_id) = semantic.scoping().scope_parent_id(scope_id) else { return Err("Expected x's scope to have a parent"); }; let parent_flags = semantic.scoping().scope_flags(parent_scope_id); diff --git a/crates/oxc_semantic/tests/main.rs b/crates/oxc_semantic/tests/main.rs index 707eb5bf9d716..93aa82987cc70 100644 --- a/crates/oxc_semantic/tests/main.rs +++ b/crates/oxc_semantic/tests/main.rs @@ -30,7 +30,7 @@ fn get_scope_snapshot(semantic: &Semantic, scopes: impl Iterator .scoping() .scope_descendants_from_root() .filter(|id| { - scope_tree.get_scope_parent_id(*id).is_some_and(|parent_id| parent_id == scope_id) + scope_tree.scope_parent_id(*id).is_some_and(|parent_id| parent_id == scope_id) }) .collect::>(); result.push_str("\"children\":"); @@ -65,7 +65,7 @@ fn get_scope_snapshot(semantic: &Semantic, scopes: impl Iterator "\"node\": {:?},", semantic .nodes() - .kind(semantic.scoping().get_symbol_declaration(symbol_id)) + .kind(semantic.scoping().symbol_declaration(symbol_id)) .debug_name() ) .as_str(), diff --git a/crates/oxc_transformer/src/common/arrow_function_converter.rs b/crates/oxc_transformer/src/common/arrow_function_converter.rs index dd36762c6cb1f..91ea6a936bc97 100644 --- a/crates/oxc_transformer/src/common/arrow_function_converter.rs +++ b/crates/oxc_transformer/src/common/arrow_function_converter.rs @@ -875,7 +875,7 @@ impl<'a> ArrowFunctionConverter<'a> { binding: &BoundIdentifier<'a>, ctx: &mut TraverseCtx<'a>, ) { - let original_scope_id = ctx.scoping().get_symbol_scope_id(binding.symbol_id); + let original_scope_id = ctx.scoping().symbol_scope_id(binding.symbol_id); if target_scope_id != original_scope_id { ctx.scoping_mut().set_symbol_scope_id(binding.symbol_id, target_scope_id); ctx.scoping_mut().move_binding(original_scope_id, target_scope_id, &binding.name); @@ -1014,7 +1014,7 @@ impl<'a> ArrowFunctionConverter<'a> { /// Rename the `arguments` symbol to a new name. fn rename_arguments_symbol(symbol_id: SymbolId, name: CompactStr, ctx: &mut TraverseCtx<'a>) { - let scope_id = ctx.scoping().get_symbol_scope_id(symbol_id); + let scope_id = ctx.scoping().symbol_scope_id(symbol_id); ctx.rename_symbol(symbol_id, scope_id, name); } diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index b094546b52bf0..a129c5fa33b73 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -899,7 +899,7 @@ impl<'a> Visit<'a> for BindingMover<'a, '_> { fn visit_binding_identifier(&mut self, ident: &BindingIdentifier<'a>) { let symbols = self.ctx.scoping(); let symbol_id = ident.symbol_id(); - let current_scope_id = symbols.get_symbol_scope_id(symbol_id); + let current_scope_id = symbols.symbol_scope_id(symbol_id); let scopes = self.ctx.scoping_mut(); scopes.move_binding(current_scope_id, self.target_scope_id, ident.name.as_str()); let symbols = self.ctx.scoping_mut(); diff --git a/crates/oxc_transformer/src/es2018/object_rest_spread.rs b/crates/oxc_transformer/src/es2018/object_rest_spread.rs index 074e90dd878e0..d3631d0464510 100644 --- a/crates/oxc_transformer/src/es2018/object_rest_spread.rs +++ b/crates/oxc_transformer/src/es2018/object_rest_spread.rs @@ -811,7 +811,7 @@ impl<'a> ObjectRestSpread<'a, '_> { let symbols = ctx.scoping(); decl.id.bound_names(&mut |ident| { let symbol_id = ident.symbol_id(); - scope_id = symbols.get_symbol_scope_id(symbol_id); + scope_id = symbols.symbol_scope_id(symbol_id); symbol_flags.insert(symbols.symbol_flags(symbol_id)); }); diff --git a/crates/oxc_transformer/src/es2022/class_properties/instance_prop_init.rs b/crates/oxc_transformer/src/es2022/class_properties/instance_prop_init.rs index 0603ad01bb03b..a010f9fbffdac 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/instance_prop_init.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/instance_prop_init.rs @@ -126,7 +126,7 @@ impl<'a> InstanceInitializerVisitor<'a, '_> { // This is an improvement over Babel. let reference_id = ident.reference_id(); if let Some(ident_symbol_id) = self.ctx.scoping().get_reference(reference_id).symbol_id() { - let scope_id = self.ctx.scoping().get_symbol_scope_id(ident_symbol_id); + let scope_id = self.ctx.scoping().symbol_scope_id(ident_symbol_id); if self.scope_ids_stack.contains(&scope_id) { return; } diff --git a/crates/oxc_transformer/src/jsx/refresh.rs b/crates/oxc_transformer/src/jsx/refresh.rs index 4fa414728d341..d67f029a8e991 100644 --- a/crates/oxc_transformer/src/jsx/refresh.rs +++ b/crates/oxc_transformer/src/jsx/refresh.rs @@ -339,7 +339,7 @@ impl<'a> Traverse<'a> for ReactRefresh<'a, '_> { self.non_builtin_hooks_callee.entry(current_scope_id).or_default().push( ctx.scoping() .find_binding( - ctx.scoping().get_scope_parent_id(ctx.current_scope_id()).unwrap(), + ctx.scoping().scope_parent_id(ctx.current_scope_id()).unwrap(), binding_name.as_str(), ) .map(|symbol_id| { diff --git a/crates/oxc_transformer/src/typescript/enum.rs b/crates/oxc_transformer/src/typescript/enum.rs index a5de15050bc66..1cc9ccf01c49e 100644 --- a/crates/oxc_transformer/src/typescript/enum.rs +++ b/crates/oxc_transformer/src/typescript/enum.rs @@ -573,7 +573,7 @@ impl IdentifierReferenceRename<'_, '_> { return true; }; - let symbol_scope_id = scoping.get_symbol_scope_id(symbol_id); + let symbol_scope_id = scoping.symbol_scope_id(symbol_id); // Don't need to rename the identifier when it references a nested enum member: // // ```ts diff --git a/crates/oxc_transformer/src/typescript/namespace.rs b/crates/oxc_transformer/src/typescript/namespace.rs index ec67811ec7c16..c475234807078 100644 --- a/crates/oxc_transformer/src/typescript/namespace.rs +++ b/crates/oxc_transformer/src/typescript/namespace.rs @@ -467,7 +467,7 @@ impl<'a> TypeScriptNamespace<'a, '_> { // namespace Foo {} // namespace Foo {} // is redeclaration // ``` - let redeclarations = ctx.scoping().get_symbol_redeclarations(symbol_id); + let redeclarations = ctx.scoping().symbol_redeclarations(symbol_id); !redeclarations.is_empty() && redeclarations.contains(&id.span) } } diff --git a/crates/oxc_traverse/src/context/scoping.rs b/crates/oxc_traverse/src/context/scoping.rs index 4fa67f9753afc..da93c87be6870 100644 --- a/crates/oxc_traverse/src/context/scoping.rs +++ b/crates/oxc_traverse/src/context/scoping.rs @@ -152,7 +152,7 @@ impl TraverseScoping { let child_ids = collector.scope_ids; if !child_ids.is_empty() { - let parent_id = self.scoping.get_scope_parent_id(scope_id); + let parent_id = self.scoping.scope_parent_id(scope_id); for child_id in child_ids { self.scoping.set_scope_parent_id(child_id, parent_id); } diff --git a/crates/oxc_wasm/src/lib.rs b/crates/oxc_wasm/src/lib.rs index 363a0834307e7..cdfa18768134a 100644 --- a/crates/oxc_wasm/src/lib.rs +++ b/crates/oxc_wasm/src/lib.rs @@ -469,7 +469,7 @@ impl Oxc { span: scoping.symbol_span(symbol_id), name: scoping.symbol_name(symbol_id).into(), flags: scoping.symbol_flags(symbol_id), - scope_id: scoping.get_symbol_scope_id(symbol_id), + scope_id: scoping.symbol_scope_id(symbol_id), resolved_references: scoping .get_resolved_reference_ids(symbol_id) .iter() diff --git a/tasks/transform_checker/src/lib.rs b/tasks/transform_checker/src/lib.rs index c1a8318fff462..0ab84e9d60cce 100644 --- a/tasks/transform_checker/src/lib.rs +++ b/tasks/transform_checker/src/lib.rs @@ -354,7 +354,7 @@ impl PostTransformChecker<'_, '_> { } // Check parents match - let parent_ids = self.get_pair(scope_ids, Scoping::get_scope_parent_id); + let parent_ids = self.get_pair(scope_ids, Scoping::scope_parent_id); let is_match = match parent_ids.into_parts() { (Some(parent_id_after_transform), Some(parent_id_rebuilt)) => { let parent_ids = Pair::new(parent_id_after_transform, parent_id_rebuilt); @@ -406,7 +406,7 @@ impl PostTransformChecker<'_, '_> { } // Check scope IDs match - let scope_ids = self.get_pair(symbol_ids, Scoping::get_symbol_scope_id); + let scope_ids = self.get_pair(symbol_ids, Scoping::symbol_scope_id); if self.remap_scope_ids(scope_ids).is_mismatch() { self.errors.push_mismatch(&mismatch_title("scope ID"), symbol_ids, scope_ids); } @@ -427,7 +427,7 @@ impl PostTransformChecker<'_, '_> { // Check redeclarations match let redeclaration_spans = self.get_pair(symbol_ids, |scoping, symbol_id| { - let mut spans = scoping.get_symbol_redeclarations(symbol_id).to_vec(); + let mut spans = scoping.symbol_redeclarations(symbol_id).to_vec(); spans.sort_unstable(); spans });