Commit 86ab13dd authored by Benjamin Woodruff's avatar Benjamin Woodruff

turbopack: fix(analyzer): The value of an assign expr is only equal to the RHS…

turbopack: fix(analyzer): The value of an assign expr is only equal to the RHS in simple assignments
parent 30e1c0e1
...@@ -802,7 +802,11 @@ impl EvalContext { ...@@ -802,7 +802,11 @@ impl EvalContext {
.. ..
}) => JsValue::WellKnownObject(WellKnownObjectKind::ImportMeta), }) => JsValue::WellKnownObject(WellKnownObjectKind::ImportMeta),
Expr::Assign(AssignExpr { right, .. }) => self.eval(right), Expr::Assign(AssignExpr {
right,
op: AssignOp::Assign,
..
}) => self.eval(right),
_ => JsValue::unknown_empty(true, "unsupported expression"), _ => JsValue::unknown_empty(true, "unsupported expression"),
} }
......
a (const after eval) = ("" | `${a}x`) a (const after eval) = ("" | `${a}x` | `${a}y`)
b (const after eval) = (0 | ???*0*) b (const after eval) = ???*0*
- *0* unsupported assign operation - *0* unsupported expression
⚠️ This value might have side effects ⚠️ This value might have side effects
c (const after eval) = (0 | ???*0*) c (const after eval) = (0 | ???*0*)
- *0* updated with update expression - *0* unsupported assign operation
⚠️ This value might have side effects ⚠️ This value might have side effects
d (const after eval) = (0 | 1) d (const after eval) = (0 | ???*0*)
- *0* updated with update expression
⚠️ This value might have side effects
e (const after eval) = (1 | 2) e (const after eval) = (0 | 1)
f (const after eval) = (1 | 2) f (const after eval) = (1 | 2)
g (const after eval) = (1 | 2)
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
( (
"a", "a",
Alternatives { Alternatives {
total_nodes: 5, total_nodes: 8,
values: [ values: [
Constant( Constant(
Str( Str(
...@@ -29,12 +29,38 @@ ...@@ -29,12 +29,38 @@
), ),
], ],
), ),
Concat(
3,
[
Variable(
(
"a",
#2,
),
),
Constant(
Str(
Atom(
"y",
),
),
),
],
),
], ],
logical_property: None, logical_property: None,
}, },
), ),
( (
"b", "b",
Unknown {
original_value: None,
reason: "unsupported expression",
has_side_effects: true,
},
),
(
"c",
Alternatives { Alternatives {
total_nodes: 3, total_nodes: 3,
values: [ values: [
...@@ -55,7 +81,7 @@ ...@@ -55,7 +81,7 @@
}, },
), ),
( (
"c", "d",
Alternatives { Alternatives {
total_nodes: 3, total_nodes: 3,
values: [ values: [
...@@ -76,7 +102,7 @@ ...@@ -76,7 +102,7 @@
}, },
), ),
( (
"d", "e",
Alternatives { Alternatives {
total_nodes: 3, total_nodes: 3,
values: [ values: [
...@@ -99,7 +125,7 @@ ...@@ -99,7 +125,7 @@
}, },
), ),
( (
"e", "f",
Alternatives { Alternatives {
total_nodes: 3, total_nodes: 3,
values: [ values: [
...@@ -122,7 +148,7 @@ ...@@ -122,7 +148,7 @@
}, },
), ),
( (
"f", "g",
Alternatives { Alternatives {
total_nodes: 3, total_nodes: 3,
values: [ values: [
......
let a = ""; let a = "";
a += "x"; a += "x";
let b = 0; let b = (a += "y");
b -= 1;
let c = 0; let c = 0;
c++; c -= 1;
let d = 0; let d = 0;
d ||= 1; d++;
let e = 1; let e = 0;
e &&= 2; e ||= 1;
let f = 1; let f = 1;
f ??= 2; f &&= 2;
let g = 1;
g ??= 2;
a = ("" | `${???*0*}x`) a = ("" | `${???*0*}x` | `${???*1*}y`)
- *0* a - *0* a
⚠️ circular variable reference ⚠️ circular variable reference
- *1* a
⚠️ circular variable reference
b = (0 | ???*0*) b = ???*0*
- *0* unsupported assign operation - *0* unsupported expression
⚠️ This value might have side effects ⚠️ This value might have side effects
c = (0 | ???*0*) c = (0 | ???*0*)
- *0* updated with update expression - *0* unsupported assign operation
⚠️ This value might have side effects ⚠️ This value might have side effects
d = (0 | 1) d = (0 | ???*0*)
- *0* updated with update expression
⚠️ This value might have side effects
e = (1 | 2) e = (0 | 1)
f = (1 | 2) f = (1 | 2)
g = (1 | 2)
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