forked from vercel/turbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ecmascript): eval assignop to the ident (vercel#4609)
### Description - closes WEB-889 When there is a variable with `+=` assignop only to the given ident ``` var css = ''; for (var i = 0; i < length; i++) { var partRule = this.rules[i]; if (typeof partRule === 'string') { css += partRule; } else if (partRule) { css += partString; } } if (css) { .... } ``` evaluated result becomes ``` var css = ''; for(var i = 0; i < length; i++){ var partRule = this.rules[i]; if (typeof partRule === 'string') { css += partRule; } else if (partRule) { css += partString; } } if ("TURBOPACK compile-time falsy", 0) { "TURBOPACK unreachable"; } ``` so `if (css)` condition never executed even though it can be executed depends on the runtime assignop condition. PR attempts to evaluate if assignop is for the ident to prevent this. --------- Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
- Loading branch information
1 parent
26d3a3c
commit fcc351a
Showing
23 changed files
with
3,365 additions
and
2,427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
crates/turbopack-ecmascript/tests/analyzer/graph/assign/graph-effects.snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
13 changes: 13 additions & 0 deletions
13
crates/turbopack-ecmascript/tests/analyzer/graph/assign/graph-explained.snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
a = ("" | `${a}x`) | ||
|
||
b = (0 | ???*0*) | ||
- *0* unsupported assign operation | ||
|
||
c = (0 | ???*0*) | ||
- *0* updated with update expression | ||
|
||
d = (0 | 1) | ||
|
||
e = (1 | 2) | ||
|
||
f = (1 | 2) |
139 changes: 139 additions & 0 deletions
139
crates/turbopack-ecmascript/tests/analyzer/graph/assign/graph.snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
[ | ||
( | ||
"a", | ||
Alternatives( | ||
5, | ||
[ | ||
Constant( | ||
Str( | ||
Word( | ||
Atom('' type=static), | ||
), | ||
), | ||
), | ||
Concat( | ||
3, | ||
[ | ||
Variable( | ||
( | ||
Atom('a' type=static), | ||
#2, | ||
), | ||
), | ||
Constant( | ||
Str( | ||
Word( | ||
Atom('x' type=static), | ||
), | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
( | ||
"b", | ||
Alternatives( | ||
3, | ||
[ | ||
Constant( | ||
Num( | ||
ConstantNumber( | ||
0.0, | ||
), | ||
), | ||
), | ||
Unknown( | ||
None, | ||
"unsupported assign operation", | ||
), | ||
], | ||
), | ||
), | ||
( | ||
"c", | ||
Alternatives( | ||
3, | ||
[ | ||
Constant( | ||
Num( | ||
ConstantNumber( | ||
0.0, | ||
), | ||
), | ||
), | ||
Unknown( | ||
None, | ||
"updated with update expression", | ||
), | ||
], | ||
), | ||
), | ||
( | ||
"d", | ||
Alternatives( | ||
3, | ||
[ | ||
Constant( | ||
Num( | ||
ConstantNumber( | ||
0.0, | ||
), | ||
), | ||
), | ||
Constant( | ||
Num( | ||
ConstantNumber( | ||
1.0, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
( | ||
"e", | ||
Alternatives( | ||
3, | ||
[ | ||
Constant( | ||
Num( | ||
ConstantNumber( | ||
1.0, | ||
), | ||
), | ||
), | ||
Constant( | ||
Num( | ||
ConstantNumber( | ||
2.0, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
( | ||
"f", | ||
Alternatives( | ||
3, | ||
[ | ||
Constant( | ||
Num( | ||
ConstantNumber( | ||
1.0, | ||
), | ||
), | ||
), | ||
Constant( | ||
Num( | ||
ConstantNumber( | ||
2.0, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
] |
12 changes: 12 additions & 0 deletions
12
crates/turbopack-ecmascript/tests/analyzer/graph/assign/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
let a = ""; | ||
a += "x"; | ||
let b = 0; | ||
b -= 1; | ||
let c = 0; | ||
c++; | ||
let d = 0; | ||
d ||= 1; | ||
let e = 1; | ||
e &&= 2; | ||
let f = 1; | ||
f ??= 2; |
Empty file.
17 changes: 17 additions & 0 deletions
17
crates/turbopack-ecmascript/tests/analyzer/graph/assign/resolved-explained.snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
a = ("" | `${("" | ???*0*)}x`) | ||
- *0* `${???*1*}x` | ||
⚠️ nested operation | ||
- *1* a | ||
⚠️ circular variable reference | ||
|
||
b = (0 | ???*0*) | ||
- *0* unsupported assign operation | ||
|
||
c = (0 | ???*0*) | ||
- *0* updated with update expression | ||
|
||
d = (0 | 1) | ||
|
||
e = (1 | 2) | ||
|
||
f = (1 | 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.