-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: replace environmental variable with in binary expression #7954
Feature: replace environmental variable with in binary expression #7954
Conversation
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, | ||
})); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the if by doing
return Expr::Lit(Lit::Bool(Bool {
value: self.env.contains_key(&left.value),
span: DUMMY_SP,
}));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly! Thanks! 👍 9b66c82
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" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use the match_member_expr
utility to match process.env
as below?
…h of binary in expression
2f1c460
to
d4ffae8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I did a little simplification to the code, hope you don't mind. 😄
I misunderstood that |
↪️ Pull Request
Fixes: #7904
I implemented the feature to replace
in
binary expression ,whose right branch isprocess.env
and left branch is string literal value, with boolean literal value.💻 Examples
into
🚨 Test instructions
prepare the test case to cover this.
✔️ PR Todo