Skip to content

Commit 9798ef1

Browse files
committed
fix(linter): stack overflow in no-async-endpoint-handlers (#11317)
fixes #11316
1 parent 08eb1eb commit 9798ef1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

crates/oxc_linter/src/rules/oxc/no_async_endpoint_handlers.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
use std::ops::Deref;
22

3+
use oxc_allocator::{Address, GetAddress};
34
use oxc_ast::{
45
AstKind,
56
ast::{Argument, ArrowFunctionExpression, Expression, Function},
67
};
78
use oxc_diagnostics::{LabeledSpan, OxcDiagnostic};
89
use oxc_macros::declare_oxc_lint;
910
use oxc_span::{CompactStr, Span};
11+
use rustc_hash::FxHashSet;
1012
use serde_json::Value;
1113

1214
use crate::{AstNode, context::LintContext, rule::Rule, utils};
@@ -199,7 +201,8 @@ impl Rule for NoAsyncEndpointHandlers {
199201

200202
impl NoAsyncEndpointHandlers {
201203
fn check_endpoint_arg<'a>(&self, ctx: &LintContext<'a>, arg: &Expression<'a>) {
202-
self.check_endpoint_expr(ctx, None, None, arg);
204+
let mut visited = FxHashSet::default();
205+
self.check_endpoint_expr(ctx, None, None, arg, &mut visited);
203206
}
204207

205208
fn check_endpoint_expr<'a>(
@@ -208,7 +211,13 @@ impl NoAsyncEndpointHandlers {
208211
id_name: Option<&str>,
209212
registered_at: Option<Span>,
210213
arg: &Expression<'a>,
214+
visited: &mut FxHashSet<Address>,
211215
) {
216+
let expr_ptr = arg.address();
217+
if !visited.insert(expr_ptr) {
218+
return;
219+
}
220+
212221
match arg {
213222
Expression::Identifier(handler) => {
214223
// Unresolved reference? Nothing we can do.
@@ -240,7 +249,7 @@ impl NoAsyncEndpointHandlers {
240249
return;
241250
}
242251
}
243-
self.check_endpoint_expr(ctx, id_name, registered_at, init);
252+
self.check_endpoint_expr(ctx, id_name, registered_at, init, visited);
244253
}
245254
}
246255
_ => {}
@@ -351,6 +360,7 @@ fn test() {
351360
",
352361
None,
353362
),
363+
("{const{r}=r;e.delete(r)}", None),
354364
];
355365

356366
let fail = vec![

0 commit comments

Comments
 (0)