Skip to content

Commit c90537f

Browse files
committed
refactor(linter/only-used-in-recursion): improve implementation to remove using SymbolFlags::Export (#7413)
part of #7414
1 parent c8adc46 commit c90537f

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ declare_oxc_lint!(
6464
dangerous_fix
6565
);
6666

67+
fn is_exported(id: &BindingIdentifier<'_>, ctx: &LintContext<'_>) -> bool {
68+
let module_record = ctx.module_record();
69+
module_record.exported_bindings.contains_key(id.name.as_str())
70+
|| module_record.export_default.is_some_and(|default| default == id.span)
71+
}
72+
6773
impl Rule for OnlyUsedInRecursion {
6874
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
6975
let (function_id, function_parameters, function_span) = match node.kind() {
@@ -137,9 +143,8 @@ fn create_diagnostic(
137143
function_span: Span,
138144
) {
139145
let is_last_arg = arg_index == function_parameters.items.len() - 1;
140-
let is_exported = ctx.semantic().symbols().get_flags(function_id.symbol_id()).is_export();
141146

142-
let is_diagnostic_only = !is_last_arg || is_exported;
147+
let is_diagnostic_only = !is_last_arg || is_exported(function_id, ctx);
143148

144149
if is_diagnostic_only {
145150
return ctx.diagnostic(only_used_in_recursion_diagnostic(arg.span, arg.name.as_str()));
@@ -193,10 +198,8 @@ fn create_diagnostic_jsx(
193198
function_id: &BindingIdentifier,
194199
property: &BindingProperty,
195200
) {
196-
let is_exported = ctx.semantic().symbols().get_flags(function_id.symbol_id()).is_export();
197-
198201
let Some(property_name) = &property.key.static_name() else { return };
199-
if is_exported {
202+
if is_exported(function_id, ctx) {
200203
return ctx.diagnostic(only_used_in_recursion_diagnostic(property.span(), property_name));
201204
}
202205

@@ -783,8 +786,8 @@ function writeChunks(a,callac){writeChunks(m,callac)}writeChunks(i,{})",
783786
}
784787
export default test;
785788
",
786-
r"function test(a) {
787-
test(a)
789+
r"function test() {
790+
test()
788791
}
789792
export default test;
790793
",

0 commit comments

Comments
 (0)