Skip to content

Commit

Permalink
chore: 🤖 clean
Browse files Browse the repository at this point in the history
  • Loading branch information
IWANABETHATGUY committed Aug 20, 2024
1 parent a16a241 commit 03f0c0e
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions crates/oxc_minifier/src/plugins/replace_global_defines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pub struct ReplaceGlobalDefinesConfig(Arc<ReplaceGlobalDefinesConfigImpl>);

#[derive(Debug)]
struct ReplaceGlobalDefinesConfigImpl {
identifier_defines: Vec<(/* key */ CompactStr, /* value */ CompactStr)>,
dot_defines: Vec<DotDefine>,
meta_proeperty_defines: Vec<MetaPropertyDefine>,
identifier: Vec<(/* key */ CompactStr, /* value */ CompactStr)>,
dot: Vec<DotDefine>,
meta_proeperty: Vec<MetaPropertyDefine>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -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,
})))
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -218,15 +218,15 @@ 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;
return;
}
}
// 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);
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 03f0c0e

Please sign in to comment.