From af6d240559b94d97e8027f58f37e90d1d708f4c1 Mon Sep 17 00:00:00 2001 From: DonIsaac <22823424+DonIsaac@users.noreply.github.com> Date: Mon, 9 Sep 2024 01:21:49 +0000 Subject: [PATCH] fix(linter): panic in consistent-function-scoping (#5613) Closes #5608 --- .../unicorn/consistent_function_scoping.rs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) 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 85d61eae8a387..e2bb20760ad65 100644 --- a/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs +++ b/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs @@ -185,21 +185,23 @@ impl Rule for ConsistentFunctionScoping { }), ) } else if let Some(function_id) = &function.id { - (function_id.symbol_id.get().unwrap(), function_body, function_id.span()) + let Some(symbol_id) = function_id.symbol_id.get() else { + return; + }; + (symbol_id, function_body, function_id.span()) } else { return; } } AstKind::ArrowFunctionExpression(arrow_function) if self.check_arrow_functions => { - if let Some(binding_ident) = get_function_like_declaration(node, ctx) { - ( - binding_ident.symbol_id.get().unwrap(), - &arrow_function.body, - binding_ident.span(), - ) - } else { + let Some(binding_ident) = get_function_like_declaration(node, ctx) else { return; - } + }; + let Some(symbol_id) = binding_ident.symbol_id.get() else { + return; + }; + + (symbol_id, &arrow_function.body, binding_ident.span()) } _ => return, }; @@ -586,6 +588,7 @@ fn test() { ("module.exports = function foo() {};", None), ("module.exports.foo = function foo() {};", None), ("foo.bar.func = function foo() {};", None), + ("if(f) function f(){}", None), ]; let fail = vec![