mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(semantic): impl IntoIterator for &AstNodes (#5873)
Simple quality-of-life change.
This commit is contained in:
parent
1ccf2907be
commit
3d13c6d1f9
11 changed files with 19 additions and 10 deletions
|
|
@ -34,7 +34,7 @@ fn main() -> std::io::Result<()> {
|
|||
|
||||
let mut errors: Vec<OxcDiagnostic> = vec![];
|
||||
|
||||
for node in semantic_ret.semantic.nodes().iter() {
|
||||
for node in semantic_ret.semantic.nodes() {
|
||||
match node.kind() {
|
||||
AstKind::DebuggerStatement(stmt) => {
|
||||
errors.push(no_debugger(stmt.span));
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ impl Linter {
|
|||
}
|
||||
}
|
||||
|
||||
for node in semantic.nodes().iter() {
|
||||
for node in semantic.nodes() {
|
||||
for (rule, ctx) in &rules {
|
||||
rule.run(node, ctx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -372,7 +372,7 @@ impl Rule for FuncNames {
|
|||
fn run_once(&self, ctx: &LintContext<'_>) {
|
||||
let mut invalid_funcs: Vec<(&Function, &AstNode)> = vec![];
|
||||
|
||||
for node in ctx.nodes().iter() {
|
||||
for node in ctx.nodes() {
|
||||
match node.kind() {
|
||||
// check function if it invalid, do not report it because maybe later the function is calling itself
|
||||
AstKind::Function(func) => {
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ impl Rule for NoThisBeforeSuper {
|
|||
let mut wanted_nodes = Vec::new();
|
||||
let mut basic_blocks_with_super_called = HashSet::<BasicBlockId>::new();
|
||||
let mut basic_blocks_with_local_violations = HashMap::<BasicBlockId, Vec<NodeId>>::new();
|
||||
for node in semantic.nodes().iter() {
|
||||
for node in semantic.nodes() {
|
||||
match node.kind() {
|
||||
AstKind::Function(_) | AstKind::ArrowFunctionExpression(_) => {
|
||||
if Self::is_wanted_node(node, ctx).unwrap_or_default() {
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ impl Rule for NoUnreachable {
|
|||
_ => Control::Continue,
|
||||
});
|
||||
}
|
||||
for node in ctx.nodes().iter() {
|
||||
for node in ctx.nodes() {
|
||||
// exit early if we are not visiting a statement.
|
||||
if !node.kind().is_statement() {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ impl Rule for NoNamedAsDefaultMember {
|
|||
};
|
||||
};
|
||||
|
||||
for item in ctx.semantic().nodes().iter() {
|
||||
for item in ctx.semantic().nodes() {
|
||||
match item.kind() {
|
||||
AstKind::MemberExpression(member_expr) => process_member_expr(member_expr),
|
||||
AstKind::VariableDeclarator(decl) => {
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ impl Rule for PreferHooksInOrder {
|
|||
fn run_once(&self, ctx: &LintContext) {
|
||||
let mut hook_groups: FxHashMap<ScopeId, Vec<AstNode>> = FxHashMap::default();
|
||||
|
||||
for node in ctx.nodes().iter() {
|
||||
for node in ctx.nodes() {
|
||||
hook_groups.entry(node.scope_id()).or_default().push(*node);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ impl Rule for RequireReturns {
|
|||
|
||||
// Value of map: (AstNode, Span, Attrs: (isAsync, hasReturnValue))
|
||||
let mut functions_to_check = FxHashMap::default();
|
||||
'visit_node: for node in ctx.nodes().iter() {
|
||||
'visit_node: for node in ctx.nodes() {
|
||||
match node.kind() {
|
||||
AstKind::Function(func) => {
|
||||
functions_to_check.insert(node.id(), (node, func.span, (func.r#async, false)));
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ fn main() -> std::io::Result<()> {
|
|||
.expect("we set semantic to build the control flow (`with_cfg`) for us so it should always be `Some`");
|
||||
|
||||
let mut ast_nodes_by_block = HashMap::<_, Vec<_>>::new();
|
||||
for node in semantic.semantic.nodes().iter() {
|
||||
for node in semantic.semantic.nodes() {
|
||||
let block = node.cfg_id();
|
||||
let block_ix = cfg.graph.node_weight(block).unwrap();
|
||||
ast_nodes_by_block.entry(*block_ix).or_default().push(node);
|
||||
|
|
|
|||
|
|
@ -288,7 +288,7 @@ mod tests {
|
|||
";
|
||||
let allocator = Allocator::default();
|
||||
let semantic = get_semantic(&allocator, source, SourceType::default());
|
||||
for node in semantic.nodes().iter() {
|
||||
for node in semantic.nodes() {
|
||||
if let AstKind::IdentifierReference(id) = node.kind() {
|
||||
assert!(!semantic.is_reference_to_global_variable(id));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -266,6 +266,15 @@ impl<'a> AstNodes<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'ast, 'a> IntoIterator for &'ast AstNodes<'a> {
|
||||
type Item = &'ast AstNode<'a>;
|
||||
type IntoIter = std::slice::Iter<'ast, AstNode<'a>>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.nodes.iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AstNodeParentIter<'s, 'a> {
|
||||
current_node_id: Option<NodeId>,
|
||||
|
|
|
|||
Loading…
Reference in a new issue