From ebd11fb5e9ce876072c916cb6e73eb4f802e4060 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Tue, 3 Dec 2024 07:46:00 +0000 Subject: [PATCH] refactor(transformer/class-properties): exit `transform_class` faster if nothing to do (#7586) Small optimization. Class properties transform doesn't have to do anything if the class has no properties, which will often be the case. Exit sooner in this case. --- .../src/es2022/class_properties/class.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/oxc_transformer/src/es2022/class_properties/class.rs b/crates/oxc_transformer/src/es2022/class_properties/class.rs index b1527c6eba8cb..c3692456c8af0 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/class.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/class.rs @@ -339,6 +339,13 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { index_not_including_removed += 1; } + // Exit if nothing to transform + if instance_prop_count == 0 && !has_static_prop_or_static_block { + self.private_props_stack.push(None); + return; + } + + // Add entry to `private_props_stack` if private_props.is_empty() { self.private_props_stack.push(None); } else { @@ -353,11 +360,6 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { })); } - // Exit if nothing to transform - if instance_prop_count == 0 && !has_static_prop_or_static_block { - return; - } - // Extract properties and static blocks from class body + substitute computed method keys let mut instance_inits = Vec::with_capacity(instance_prop_count); class.body.body.retain_mut(|element| {