Unverified Commit a1339ec6 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

Turbopack: Clean up some of the logic in visit_assign_expr (#81636)

It should be equivalent, but it's clearer that the LHS is always visited
parent d48daff8
...@@ -1332,32 +1332,26 @@ impl VisitAstPath for Analyzer<'_> { ...@@ -1332,32 +1332,26 @@ impl VisitAstPath for Analyzer<'_> {
if let Some(key) = n.left.as_ident() { if let Some(key) = n.left.as_ident() {
let value = match n.op { let value = match n.op {
AssignOp::AndAssign | AssignOp::OrAssign | AssignOp::NullishAssign => { AssignOp::AndAssign | AssignOp::OrAssign | AssignOp::NullishAssign => {
let right = self.eval_context.eval(&n.right);
// We can handle the right value as alternative to the existing // We can handle the right value as alternative to the existing
// value // value
Some(right) self.eval_context.eval(&n.right)
} }
AssignOp::AddAssign => { AssignOp::AddAssign => {
let left = self.eval_context.eval(&Expr::Ident(key.clone().into())); let left = self.eval_context.eval(&Expr::Ident(key.clone().into()));
let right = self.eval_context.eval(&n.right); let right = self.eval_context.eval(&n.right);
Some(JsValue::add(vec![left, right])) JsValue::add(vec![left, right])
} }
_ => Some(JsValue::unknown_empty(true, "unsupported assign operation")), _ => JsValue::unknown_empty(true, "unsupported assign operation"),
}; };
if let Some(value) = value {
// We should visit this to handle `+=` like // We should visit this to handle `+=` like
// //
// clientComponentLoadTimes += performance.now() - startTime // clientComponentLoadTimes += performance.now() - startTime
self.current_value = Some(value); self.current_value = Some(value);
n.left.visit_children_with_ast_path(self, &mut ast_path); n.left.visit_children_with_ast_path(self, &mut ast_path);
self.current_value = None; self.current_value = None;
} } else {
}
if n.left.as_ident().is_none() {
n.left.visit_children_with_ast_path(self, &mut ast_path); n.left.visit_children_with_ast_path(self, &mut ast_path);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment