From a45d749630df8761678b7bd86f60f40d6d9ef942 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Thu, 10 Jul 2025 00:39:54 +0000 Subject: [PATCH] style(transformer/styled_components): reduce indentation (#12174) Follow-on after #12066. Pure refactor. Just make the code less deeply nested. --- .../src/plugins/styled_components.rs | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/crates/oxc_transformer/src/plugins/styled_components.rs b/crates/oxc_transformer/src/plugins/styled_components.rs index 47291f101e88f..f5bbd5e51a409 100644 --- a/crates/oxc_transformer/src/plugins/styled_components.rs +++ b/crates/oxc_transformer/src/plugins/styled_components.rs @@ -480,35 +480,32 @@ impl<'a> StyledComponents<'a, '_> { fn collect_styled_bindings(&mut self, program: &Program<'a>, _ctx: &mut TraverseCtx<'a>) { for statement in &program.body { let Statement::ImportDeclaration(import) = &statement else { continue }; + let Some(specifiers) = &import.specifiers else { continue }; + if !is_valid_styled_component_source(&import.source.value) { + continue; + } - if let Some(specifiers) = &import.specifiers { - if !is_valid_styled_component_source(&import.source.value) { - continue; - } - - for specifier in specifiers { - match specifier { - ImportDeclarationSpecifier::ImportSpecifier(specifier) => { - let symbol_id = specifier.local.symbol_id(); - let imported_name = specifier.imported.name(); - match imported_name.as_str() { - "default" => { - self.styled_bindings.styled = Some(symbol_id); - } - name => { - if let Some(helper) = StyledComponentsHelper::from_str(name) { - self.styled_bindings - .set_helper_symbol_id(helper, symbol_id); - } + for specifier in specifiers { + match specifier { + ImportDeclarationSpecifier::ImportSpecifier(specifier) => { + let symbol_id = specifier.local.symbol_id(); + let imported_name = specifier.imported.name(); + match imported_name.as_str() { + "default" => { + self.styled_bindings.styled = Some(symbol_id); + } + name => { + if let Some(helper) = StyledComponentsHelper::from_str(name) { + self.styled_bindings.set_helper_symbol_id(helper, symbol_id); } } } - ImportDeclarationSpecifier::ImportDefaultSpecifier(specifier) => { - self.styled_bindings.styled = Some(specifier.local.symbol_id()); - } - ImportDeclarationSpecifier::ImportNamespaceSpecifier(specifier) => { - self.styled_bindings.namespace = Some(specifier.local.symbol_id()); - } + } + ImportDeclarationSpecifier::ImportDefaultSpecifier(specifier) => { + self.styled_bindings.styled = Some(specifier.local.symbol_id()); + } + ImportDeclarationSpecifier::ImportNamespaceSpecifier(specifier) => { + self.styled_bindings.namespace = Some(specifier.local.symbol_id()); } } }