Skip to content

Commit 232615a

Browse files
committed
refactor(semantic): s/AstNodeId/NodeId
part of #5689
1 parent 953fe17 commit 232615a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+176
-188
lines changed

crates/oxc_cfg/src/builder/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod context;
22

33
use context::Ctx;
44
pub use context::{CtxCursor, CtxFlags};
5-
use oxc_syntax::node::AstNodeId;
5+
use oxc_syntax::node::NodeId;
66
use petgraph::Direction;
77

88
use super::{
@@ -107,11 +107,11 @@ impl<'a> ControlFlowGraphBuilder<'a> {
107107
self.graph.add_edge(a, b, weight);
108108
}
109109

110-
pub fn push_statement(&mut self, stmt: AstNodeId) {
110+
pub fn push_statement(&mut self, stmt: NodeId) {
111111
self.push_instruction(InstructionKind::Statement, Some(stmt));
112112
}
113113

114-
pub fn push_return(&mut self, kind: ReturnInstructionKind, node: AstNodeId) {
114+
pub fn push_return(&mut self, kind: ReturnInstructionKind, node: NodeId) {
115115
self.push_instruction(InstructionKind::Return(kind), Some(node));
116116
}
117117

@@ -166,20 +166,20 @@ impl<'a> ControlFlowGraphBuilder<'a> {
166166
);
167167
}
168168

169-
pub fn append_condition_to(&mut self, block: BasicBlockId, node: Option<AstNodeId>) {
169+
pub fn append_condition_to(&mut self, block: BasicBlockId, node: Option<NodeId>) {
170170
self.push_instruction_to(block, InstructionKind::Condition, node);
171171
}
172172

173-
pub fn append_iteration(&mut self, node: Option<AstNodeId>, kind: IterationInstructionKind) {
173+
pub fn append_iteration(&mut self, node: Option<NodeId>, kind: IterationInstructionKind) {
174174
self.push_instruction(InstructionKind::Iteration(kind), node);
175175
}
176176

177-
pub fn append_throw(&mut self, node: AstNodeId) {
177+
pub fn append_throw(&mut self, node: NodeId) {
178178
self.push_instruction(InstructionKind::Throw, Some(node));
179179
self.append_unreachable();
180180
}
181181

182-
pub fn append_break(&mut self, node: AstNodeId, label: Option<&'a str>) {
182+
pub fn append_break(&mut self, node: NodeId, label: Option<&'a str>) {
183183
let kind = match label {
184184
Some(_) => LabeledInstruction::Labeled,
185185
None => LabeledInstruction::Unlabeled,
@@ -193,7 +193,7 @@ impl<'a> ControlFlowGraphBuilder<'a> {
193193
self.ctx(label).r#break(bb);
194194
}
195195

196-
pub fn append_continue(&mut self, node: AstNodeId, label: Option<&'a str>) {
196+
pub fn append_continue(&mut self, node: NodeId, label: Option<&'a str>) {
197197
let kind = match label {
198198
Some(_) => LabeledInstruction::Labeled,
199199
None => LabeledInstruction::Unlabeled,
@@ -221,7 +221,7 @@ impl<'a> ControlFlowGraphBuilder<'a> {
221221

222222
/// # Panics
223223
#[inline]
224-
pub(self) fn push_instruction(&mut self, kind: InstructionKind, node_id: Option<AstNodeId>) {
224+
pub(self) fn push_instruction(&mut self, kind: InstructionKind, node_id: Option<NodeId>) {
225225
self.push_instruction_to(self.current_node_ix, kind, node_id);
226226
}
227227

@@ -230,12 +230,12 @@ impl<'a> ControlFlowGraphBuilder<'a> {
230230
&mut self,
231231
block: BasicBlockId,
232232
kind: InstructionKind,
233-
node_id: Option<AstNodeId>,
233+
node_id: Option<NodeId>,
234234
) {
235235
self.basic_block_mut(block).instructions.push(Instruction { kind, node_id });
236236
}
237237

238-
pub fn enter_statement(&mut self, stmt: AstNodeId) {
238+
pub fn enter_statement(&mut self, stmt: NodeId) {
239239
self.push_statement(stmt);
240240
}
241241
}

crates/oxc_cfg/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod dot;
33
pub mod visit;
44

55
use itertools::Itertools;
6-
use oxc_syntax::node::AstNodeId;
6+
use oxc_syntax::node::NodeId;
77
use petgraph::{
88
stable_graph::NodeIndex,
99
visit::{Control, DfsEvent, EdgeRef},
@@ -44,11 +44,11 @@ impl BasicBlock {
4444
#[derive(Debug, Clone)]
4545
pub struct Instruction {
4646
pub kind: InstructionKind,
47-
pub node_id: Option<AstNodeId>,
47+
pub node_id: Option<NodeId>,
4848
}
4949

5050
impl Instruction {
51-
pub fn new(kind: InstructionKind, node_id: Option<AstNodeId>) -> Self {
51+
pub fn new(kind: InstructionKind, node_id: Option<NodeId>) -> Self {
5252
Self { kind, node_id }
5353
}
5454
}

crates/oxc_cfg/tests/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use oxc_cfg::{ControlFlowGraphBuilder, CtxCursor};
2-
use oxc_syntax::node::AstNodeId;
2+
use oxc_syntax::node::NodeId;
33
/// same as but just the skeleton
44
/// ```js
55
/// A: {
@@ -29,7 +29,7 @@ fn labeled_statement_with_multiple_loops_continue_and_break() {
2929
cfg.ctx(None).default().allow_break().allow_continue();
3030
cfg.ctx(None).mark_break(c2).mark_continue(c2).resolve_with_upper_label();
3131

32-
cfg.append_break(AstNodeId::DUMMY, A);
32+
cfg.append_break(NodeId::DUMMY, A);
3333

3434
// labeled block end
3535
cfg.ctx(A).mark_break(labeled).resolve();

crates/oxc_linter/src/ast_util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use oxc_ast::{ast::BindingIdentifier, AstKind};
2-
use oxc_semantic::{AstNode, AstNodeId, IsGlobalReference, SymbolId};
2+
use oxc_semantic::{AstNode, IsGlobalReference, NodeId, SymbolId};
33
use oxc_span::{GetSpan, Span};
44
use oxc_syntax::operator::{AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator};
55

@@ -246,7 +246,7 @@ pub fn nth_outermost_paren_parent<'a, 'b>(
246246
/// [`Expression::get_inner_expression`].
247247
pub fn iter_outer_expressions<'a, 'ctx>(
248248
ctx: &'ctx LintContext<'a>,
249-
node_id: AstNodeId,
249+
node_id: NodeId,
250250
) -> impl Iterator<Item = &'ctx AstNode<'a>> + 'ctx {
251251
ctx.nodes().iter_parents(node_id).skip(1).filter(|parent| {
252252
!matches!(

crates/oxc_linter/src/rules/eslint/func_names.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use oxc_ast::{
99
};
1010
use oxc_diagnostics::OxcDiagnostic;
1111
use oxc_macros::declare_oxc_lint;
12-
use oxc_semantic::AstNodeId;
12+
use oxc_semantic::NodeId;
1313
use oxc_span::{Atom, GetSpan, Span};
1414
use oxc_syntax::identifier::is_identifier_name;
1515
use phf::phf_set;
@@ -479,7 +479,7 @@ impl Rule for FuncNames {
479479
}
480480
}
481481

482-
fn guess_function_name<'a>(ctx: &LintContext<'a>, parent_id: AstNodeId) -> Option<Cow<'a, str>> {
482+
fn guess_function_name<'a>(ctx: &LintContext<'a>, parent_id: NodeId) -> Option<Cow<'a, str>> {
483483
for parent_kind in ctx.nodes().iter_parents(parent_id).map(AstNode::kind) {
484484
match parent_kind {
485485
AstKind::ParenthesizedExpression(_)

crates/oxc_linter/src/rules/eslint/no_constructor_return.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use oxc_ast::{
44
};
55
use oxc_diagnostics::OxcDiagnostic;
66
use oxc_macros::declare_oxc_lint;
7-
use oxc_semantic::AstNodeId;
7+
use oxc_semantic::NodeId;
88
use oxc_span::Span;
99

1010
use crate::{context::LintContext, rule::Rule, AstNode};
@@ -65,7 +65,7 @@ fn is_constructor(node: &AstNode<'_>) -> bool {
6565
)
6666
}
6767

68-
fn is_definitely_in_constructor(ctx: &LintContext, node_id: AstNodeId) -> bool {
68+
fn is_definitely_in_constructor(ctx: &LintContext, node_id: NodeId) -> bool {
6969
ctx.nodes()
7070
.ancestors(node_id)
7171
.map(|id| ctx.nodes().get_node(id))

crates/oxc_linter/src/rules/eslint/no_import_assign.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use oxc_ast::{ast::Expression, AstKind};
22
use oxc_diagnostics::OxcDiagnostic;
33
use oxc_macros::declare_oxc_lint;
4-
use oxc_semantic::{AstNodeId, SymbolId};
4+
use oxc_semantic::{NodeId, SymbolId};
55
use oxc_span::{GetSpan, Span};
66
use oxc_syntax::operator::UnaryOperator;
77
use phf::phf_set;
@@ -106,7 +106,7 @@ impl Rule for NoImportAssign {
106106
/// - `Reflect.deleteProperty`
107107
/// - `Reflect.set`
108108
/// - `Reflect.setPrototypeOf`
109-
fn is_argument_of_well_known_mutation_function(node_id: AstNodeId, ctx: &LintContext<'_>) -> bool {
109+
fn is_argument_of_well_known_mutation_function(node_id: NodeId, ctx: &LintContext<'_>) -> bool {
110110
let current_node = ctx.nodes().get_node(node_id);
111111
let call_expression_node =
112112
ctx.nodes().parent_node(node_id).and_then(|node| ctx.nodes().parent_kind(node.id()));

crates/oxc_linter/src/rules/eslint/no_multi_str.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use oxc_ast::AstKind;
22
use oxc_diagnostics::OxcDiagnostic;
33
use oxc_macros::declare_oxc_lint;
4-
use oxc_semantic::AstNodeId;
4+
use oxc_semantic::NodeId;
55
use oxc_span::Span;
66

77
use crate::{context::LintContext, rule::Rule, AstNode};
@@ -52,7 +52,7 @@ impl Rule for NoMultiStr {
5252
}
5353
}
5454

55-
fn is_within_jsx_attribute_item(id: AstNodeId, ctx: &LintContext) -> bool {
55+
fn is_within_jsx_attribute_item(id: NodeId, ctx: &LintContext) -> bool {
5656
if matches!(ctx.nodes().parent_kind(id), Some(AstKind::JSXAttributeItem(_))) {
5757
return true;
5858
}

crates/oxc_linter/src/rules/eslint/no_this_before_super.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use oxc_cfg::{
1010
};
1111
use oxc_diagnostics::OxcDiagnostic;
1212
use oxc_macros::declare_oxc_lint;
13-
use oxc_semantic::AstNodeId;
13+
use oxc_semantic::NodeId;
1414
use oxc_span::{GetSpan, Span};
1515

1616
use crate::{context::LintContext, rule::Rule, AstNode};
@@ -62,7 +62,7 @@ impl Rule for NoThisBeforeSuper {
6262
// first pass -> find super calls and local violations
6363
let mut wanted_nodes = Vec::new();
6464
let mut basic_blocks_with_super_called = HashSet::<BasicBlockId>::new();
65-
let mut basic_blocks_with_local_violations = HashMap::<BasicBlockId, Vec<AstNodeId>>::new();
65+
let mut basic_blocks_with_local_violations = HashMap::<BasicBlockId, Vec<NodeId>>::new();
6666
for node in semantic.nodes().iter() {
6767
match node.kind() {
6868
AstKind::Function(_) | AstKind::ArrowFunctionExpression(_) => {
@@ -153,7 +153,7 @@ impl NoThisBeforeSuper {
153153
cfg: &ControlFlowGraph,
154154
id: BasicBlockId,
155155
basic_blocks_with_super_called: &HashSet<BasicBlockId>,
156-
basic_blocks_with_local_violations: &HashMap<BasicBlockId, Vec<AstNodeId>>,
156+
basic_blocks_with_local_violations: &HashMap<BasicBlockId, Vec<NodeId>>,
157157
follow_join: bool,
158158
) -> Vec<DefinitelyCallsThisBeforeSuper> {
159159
neighbors_filtered_by_edge_weight(
@@ -212,7 +212,7 @@ impl NoThisBeforeSuper {
212212
cfg: &ControlFlowGraph,
213213
output: Vec<DefinitelyCallsThisBeforeSuper>,
214214
basic_blocks_with_super_called: &HashSet<BasicBlockId>,
215-
basic_blocks_with_local_violations: &HashMap<BasicBlockId, Vec<AstNodeId>>,
215+
basic_blocks_with_local_violations: &HashMap<BasicBlockId, Vec<NodeId>>,
216216
) -> bool {
217217
// Deciding whether we definitely call this before super in all
218218
// codepaths is as simple as seeing if any individual codepath

crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use itertools::Itertools;
22
use oxc_ast::AstKind;
33
use oxc_diagnostics::OxcDiagnostic;
44
use oxc_macros::declare_oxc_lint;
5-
use oxc_semantic::{AstNode, AstNodeId, AstNodes};
5+
use oxc_semantic::{AstNode, AstNodes, NodeId};
66
use oxc_span::Span;
77
use oxc_syntax::class::ElementKind;
88

@@ -114,7 +114,7 @@ impl Rule for NoUnusedPrivateClassMembers {
114114
}
115115
}
116116

117-
fn is_read(current_node_id: AstNodeId, nodes: &AstNodes) -> bool {
117+
fn is_read(current_node_id: NodeId, nodes: &AstNodes) -> bool {
118118
for (curr, parent) in nodes
119119
.iter_parents(nodes.parent_id(current_node_id).unwrap_or(current_node_id))
120120
.tuple_windows::<(&AstNode<'_>, &AstNode<'_>)>()

crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! consider variables ignored by name pattern, but by where they are declared.
33
#[allow(clippy::wildcard_imports)]
44
use oxc_ast::{ast::*, AstKind};
5-
use oxc_semantic::{AstNode, AstNodeId, Semantic};
5+
use oxc_semantic::{AstNode, NodeId, Semantic};
66
use oxc_span::GetSpan;
77

88
use super::{options::ArgsOption, NoUnusedVars, Symbol};
@@ -154,7 +154,7 @@ impl NoUnusedVars {
154154
pub(super) fn is_allowed_type_parameter(
155155
&self,
156156
symbol: &Symbol<'_, '_>,
157-
declaration_id: AstNodeId,
157+
declaration_id: NodeId,
158158
) -> bool {
159159
matches!(symbol.nodes().parent_kind(declaration_id), Some(AstKind::TSMappedType(_)))
160160
}
@@ -234,15 +234,15 @@ impl NoUnusedVars {
234234
.any(|p| p.has_modifier() || p.pattern.has_any_used_binding(ctx))
235235
}
236236

237-
/// `params_id` is the [`AstNodeId`] to a [`AstKind::FormalParameters`] node.
237+
/// `params_id` is the [`NodeId`] to a [`AstKind::FormalParameters`] node.
238238
///
239239
/// The following allowed conditions are handled:
240240
/// 1. setter parameters - removing them causes a syntax error.
241241
/// 2. TS constructor property definitions - they declare class members.
242242
fn is_allowed_param_because_of_method<'a>(
243243
semantic: &Semantic<'a>,
244244
param: &FormalParameter<'a>,
245-
params_id: AstNodeId,
245+
params_id: NodeId,
246246
) -> bool {
247247
let mut parents_iter = semantic.nodes().iter_parents(params_id).skip(1).map(AstNode::kind);
248248

crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/fix_vars.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use oxc_ast::{
22
ast::{Expression, VariableDeclarator},
33
AstKind,
44
};
5-
use oxc_semantic::{AstNode, AstNodeId};
5+
use oxc_semantic::{AstNode, NodeId};
66
use oxc_span::CompactStr;
77
use regex::Regex;
88

@@ -28,7 +28,7 @@ impl NoUnusedVars {
2828
fixer: RuleFixer<'_, 'a>,
2929
symbol: &Symbol<'_, 'a>,
3030
decl: &VariableDeclarator<'a>,
31-
decl_id: AstNodeId,
31+
decl_id: NodeId,
3232
) -> RuleFix<'a> {
3333
if decl.init.as_ref().is_some_and(|init| is_skipped_init(symbol, init)) {
3434
return fixer.noop();

crates/oxc_linter/src/rules/eslint/no_unused_vars/symbol.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use oxc_ast::{
88
AstKind,
99
};
1010
use oxc_semantic::{
11-
AstNode, AstNodeId, AstNodes, Reference, ScopeId, ScopeTree, Semantic, SymbolFlags, SymbolId,
11+
AstNode, AstNodes, NodeId, Reference, ScopeId, ScopeTree, Semantic, SymbolFlags, SymbolId,
1212
SymbolTable,
1313
};
1414
use oxc_span::{GetSpan, Span};
@@ -77,7 +77,7 @@ impl<'s, 'a> Symbol<'s, 'a> {
7777
}
7878

7979
#[inline]
80-
fn declaration_id(&self) -> AstNodeId {
80+
fn declaration_id(&self) -> NodeId {
8181
self.symbols().get_declaration(self.id)
8282
}
8383

@@ -107,14 +107,14 @@ impl<'s, 'a> Symbol<'s, 'a> {
107107

108108
pub fn iter_relevant_parents(
109109
&self,
110-
node_id: AstNodeId,
110+
node_id: NodeId,
111111
) -> impl Iterator<Item = &AstNode<'a>> + Clone + '_ {
112112
self.nodes().iter_parents(node_id).skip(1).filter(|n| Self::is_relevant_kind(n.kind()))
113113
}
114114

115115
pub fn iter_relevant_parent_and_grandparent_kinds(
116116
&self,
117-
node_id: AstNodeId,
117+
node_id: NodeId,
118118
) -> impl Iterator<Item = (/* parent */ AstKind<'a>, /* grandparent */ AstKind<'a>)> + Clone + '_
119119
{
120120
let parents_iter = self

crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
#[allow(clippy::wildcard_imports)]
55
use oxc_ast::{ast::*, AstKind};
6-
use oxc_semantic::{AstNode, AstNodeId, Reference, ScopeId, SymbolFlags, SymbolId};
6+
use oxc_semantic::{AstNode, NodeId, Reference, ScopeId, SymbolFlags, SymbolId};
77
use oxc_span::{GetSpan, Span};
88

99
use super::{ignored::FoundStatus, NoUnusedVars, Symbol};
@@ -427,7 +427,7 @@ impl<'s, 'a> Symbol<'s, 'a> {
427427
}
428428

429429
/// Check if a [`AstNode`] is within a return statement or implicit return.
430-
fn is_in_return_statement(&self, node_id: AstNodeId) -> bool {
430+
fn is_in_return_statement(&self, node_id: NodeId) -> bool {
431431
for parent in self.iter_relevant_parents(node_id).map(AstNode::kind) {
432432
match parent {
433433
AstKind::ReturnStatement(_) => return true,
@@ -660,7 +660,7 @@ impl<'s, 'a> Symbol<'s, 'a> {
660660

661661
/// Find the [`SymbolId`] for the nearest function declaration or expression
662662
/// that is a parent of `node_id`.
663-
fn get_nearest_function(&self, node_id: AstNodeId) -> Option<SymbolId> {
663+
fn get_nearest_function(&self, node_id: NodeId) -> Option<SymbolId> {
664664
// set to `true` when we find an arrow function and we want to get its
665665
// name from the variable its assigned to.
666666
let mut needs_variable_identifier = false;

0 commit comments

Comments
 (0)