From 03f0c0e561d5ee3fa8ffd0a5907702b89a6eb56d Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Tue, 20 Aug 2024 23:35:18 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20clean?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/plugins/replace_global_defines.rs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/oxc_minifier/src/plugins/replace_global_defines.rs b/crates/oxc_minifier/src/plugins/replace_global_defines.rs index 010a55314f8967..77d92827a4f448 100644 --- a/crates/oxc_minifier/src/plugins/replace_global_defines.rs +++ b/crates/oxc_minifier/src/plugins/replace_global_defines.rs @@ -19,9 +19,9 @@ pub struct ReplaceGlobalDefinesConfig(Arc); #[derive(Debug)] struct ReplaceGlobalDefinesConfigImpl { - identifier_defines: Vec<(/* key */ CompactStr, /* value */ CompactStr)>, - dot_defines: Vec, - meta_proeperty_defines: Vec, + identifier: Vec<(/* key */ CompactStr, /* value */ CompactStr)>, + dot: Vec, + meta_proeperty: Vec, } #[derive(Debug)] @@ -104,9 +104,9 @@ impl ReplaceGlobalDefinesConfig { } }); Ok(Self(Arc::new(ReplaceGlobalDefinesConfigImpl { - identifier_defines, - dot_defines, - meta_proeperty_defines, + identifier: identifier_defines, + dot: dot_defines, + meta_proeperty: meta_proeperty_defines, }))) } @@ -143,9 +143,9 @@ impl ReplaceGlobalDefinesConfig { }) // StaticMemberExpression with postfix wildcard } else if normalized_parts_len != parts.len() { - Err(vec![OxcDiagnostic::error(format!( - "postfix wildcard is only allowed for `import.meta`." - ))]) + Err(vec![OxcDiagnostic::error( + "postfix wildcard is only allowed for `import.meta`.".to_string(), + )]) } else { Ok(IdentifierType::DotDefines { parts: parts @@ -204,7 +204,7 @@ impl<'a> ReplaceGlobalDefines<'a> { fn replace_identifier_defines(&self, expr: &mut Expression<'a>) { if let Expression::Identifier(ident) = expr { - for (key, value) in &self.config.0.identifier_defines { + for (key, value) in &self.config.0.identifier { if ident.name.as_str() == key { let value = self.parse_value(value); *expr = value; @@ -218,7 +218,7 @@ impl<'a> ReplaceGlobalDefines<'a> { let Expression::StaticMemberExpression(member) = expr else { return; }; - for dot_define in &self.config.0.dot_defines { + for dot_define in &self.config.0.dot { if Self::is_dot_define(dot_define, member) { let value = self.parse_value(&dot_define.value); *expr = value; @@ -226,7 +226,7 @@ impl<'a> ReplaceGlobalDefines<'a> { } } // dbg!(&member); - for meta_proeperty_define in &self.config.0.meta_proeperty_defines { + for meta_proeperty_define in &self.config.0.meta_proeperty { let ret = Self::is_meta_property_define(meta_proeperty_define, member); if ret { let value = self.parse_value(&meta_proeperty_define.value); @@ -240,7 +240,7 @@ impl<'a> ReplaceGlobalDefines<'a> { meta_define: &MetaPropertyDefine, member: &StaticMemberExpression<'a>, ) -> bool { - debug_assert!(meta_define.parts.len() >= 1); + debug_assert!(!meta_define.parts.is_empty()); let mut current_part_member_expression = Some(member); let mut cur_part_name = &member.property.name; @@ -249,7 +249,9 @@ impl<'a> ReplaceGlobalDefines<'a> { loop { let part = &meta_define.parts[i]; let matched = cur_part_name.as_str() == part; - if !matched { + if matched { + has_matched_part = true; + } else { // Considering import.meta.env.* // ```js // import.meta.env.test // should matched @@ -260,8 +262,6 @@ impl<'a> ReplaceGlobalDefines<'a> { if !meta_define.postfix_wildcard || has_matched_part { return false; } - } else { - has_matched_part = true; } current_part_member_expression = if let Some(member) = current_part_member_expression {