Repository: parcel-bundler/parcel
File: packages/transformers/js/core/src/env_replacer.rs (Rust)

Code before:
              })));
              return Expr::Assign(res);
            }
          }
        }
      }
    }

    if let Expr::Bin(ref binary) = node {
      if let Expr::Member(ref member) = &*binary.right {
        if let Expr::Lit(Lit::Str(ref left)) = &*binary.left {
          if let Expr::Ident(ref ident) = &*member.obj {
            if !self.decls.contains(&id!(ident)) && &ident.sym == "process" {
              if let MemberProp::Ident(ref prop) = member.prop {
                if &prop.sym == "env" {
                  if self.env.contains_key(&left.value) {
                    return Expr::Lit(Lit::Bool(Bool {
                      value: true,
                      span: DUMMY_SP,
                    }));
                  } else {
                    return Expr::Lit(Lit::Bool(Bool {
                      value: false,
                      span: DUMMY_SP,
                    }));
                  }
                }
              }
            }
          }
        }
      }
    }

    if let Expr::Member(ref member) = node {
      if self.is_browser && match_member_expr(member, vec!["process", "browser"], self.decls) {
        return Expr::Lit(Lit::Bool(Bool {
          value: true,
          span: DUMMY_SP,
        }));
      }

      if !self.replace_env {
        return node.fold_children_with(self);
      }

      if let Expr::Member(obj) = &*member.obj {
        if match_member_expr(obj, vec!["process", "env"], self.decls) {
          if let Some((sym, _)) = match_property_name(member) {
            if let Some(replacement) = self.replace(&sym, true) {
              return replacement;

Review comment (suggestion):
You can remove the if by doing
```rust
					return Expr::Lit(Lit::Bool(Bool {
                      value: self.env.contains_key(&left.value),
                      span: DUMMY_SP,
                    }));
```

Code after:
              return Expr::Assign(res);
            }
          }
        }
      }
    }

    // Replace `'foo' in process.env` with a boolean.
    match &node {
      Expr::Bin(binary) if binary.op == BinaryOp::In => {
        if let (Expr::Lit(Lit::Str(left)), Expr::Member(member)) = (&*binary.left, &*binary.right) {
          if match_member_expr(member, vec!["process", "env"], self.decls) {
            return Expr::Lit(Lit::Bool(Bool {
              value: self.env.contains_key(&left.value),
              span: DUMMY_SP,
            }));
          }
        }
      }
      _ => {}
    }

    if let Expr::Member(ref member) = node {
      if self.is_browser && match_member_expr(member, vec!["process", "browser"], self.decls) {
        return Expr::Lit(Lit::Bool(Bool {
          value: true,
          span: DUMMY_SP,
        }));
      }

      if !self.replace_env {
        return node.fold_children_with(self);
      }

      if let Expr::Member(obj) = &*member.obj {
        if match_member_expr(obj, vec!["process", "env"], self.decls) {
          if let Some((sym, _)) = match_property_name(member) {
            if let Some(replacement) = self.replace(&sym, true) {
              return replacement;
            }
          }
        }
      }
    }

    if let Expr::Assign(assign) = &node {
      if !self.replace_env {
        return node.fold_children_with(self);
      }

      let expr = match &assign.left {