-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/minifier): Check type of assignment target before merging assi…
…gnments (#9617) **Description:** Collect types of vars, maybe other optimization could benefit from this: `merged_var_type: Option<Value<Type>>` When the variable is reassigned, the we merge the types with some simple rules: `None` + `None` = `None` `None` + `Some(ty)` = `Some(ty)` `Some(ty1)` + `Some(ty2)` if `ty1` == `ty2` = `Some(ty1)` Otherwise = Unknown **Related issue:** - Closes #8718
- Loading branch information
Showing
22 changed files
with
141 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
swc_ecma_minifier: patch | ||
swc_ecma_utils: patch | ||
swc_ecma_usage_analyzer: patch | ||
--- | ||
|
||
fix(es/minifier): Check type of assignment target before merging assignments |
2 changes: 1 addition & 1 deletion
2
crates/swc/tests/tsc-references/compoundAdditionAssignmentLHSCanBeAssigned.2.minified.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
crates/swc/tests/tsc-references/compoundAdditionAssignmentWithInvalidOperands.2.minified.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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
//// [compoundAdditionAssignmentWithInvalidOperands.ts] | ||
var E, a, x1, x2, x3, x4, x5, E1 = ((E = E1 || {})[E.a = 0] = "a", E[E.b = 1] = "b", E); | ||
x1 += a, x1 += !0, x1 += 0, x1 += {}, x1 += null, x1 += void 0, x2 += a, x2 += !0, x2 += 0, x2 += {}, x2 += null, x2 += void 0, x3 += a, x3 += !0, x3 += 0, x3 += {}, x3 += null, x3 += void 0, x4 += a, x4 += !0, x4 += {}, x5 += a, x5 += !0; | ||
x1 += a, x1 += !0, x1 += 0, x1 += 0, x1 += {}, x1 += null, x1 += void 0, x2 += a, x2 += !0, x2 += 0, x2 += 0, x2 += {}, x2 += null, x2 += void 0, x3 += a, x3 += !0, x3 += 0, x3 += 0, x3 += {}, x3 += null, x3 += void 0, x4 += a, x4 += !0, x4 += {}, x5 += a, x5 += !0; |
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
2 changes: 2 additions & 0 deletions
2
crates/swc_ecma_minifier/tests/fixture/issues/8718/1/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,2 @@ | ||
let a = ""; | ||
console.log(((a += 1), (a += 2))); |
2 changes: 2 additions & 0 deletions
2
crates/swc_ecma_minifier/tests/fixture/issues/8718/1/output.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,2 @@ | ||
let a = ""; | ||
console.log((a += 1, a += 2)); |
3 changes: 3 additions & 0 deletions
3
crates/swc_ecma_minifier/tests/fixture/issues/8718/2/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,3 @@ | ||
let a = 0; | ||
a = ""; | ||
console.log(((a += 1), (a += 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("12"); |
8 changes: 8 additions & 0 deletions
8
crates/swc_ecma_minifier/tests/fixture/issues/8718/3/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,8 @@ | ||
let a; | ||
function f() { | ||
a = "123"; | ||
console.log(a); | ||
} | ||
|
||
f(); | ||
console.log(((a += 1), (a += 2))); |
2 changes: 2 additions & 0 deletions
2
crates/swc_ecma_minifier/tests/fixture/issues/8718/3/output.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,2 @@ | ||
let a; | ||
console.log(a = "123"), console.log((a += 1, a += 2)); |
11 changes: 11 additions & 0 deletions
11
crates/swc_ecma_minifier/tests/fixture/issues/8718/4/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,11 @@ | ||
let a; | ||
function g() { | ||
a = "123"; | ||
console.log(a); | ||
} | ||
function f() { | ||
// a = "123"; | ||
console.log(a); | ||
} | ||
f(), g(); | ||
console.log(((a += 1), (a += 2))); |
3 changes: 3 additions & 0 deletions
3
crates/swc_ecma_minifier/tests/fixture/issues/8718/4/output.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,3 @@ | ||
let a; | ||
// a = "123"; | ||
console.log(a), console.log(a = "123"), console.log((a += 1, a += 2)); |
7 changes: 7 additions & 0 deletions
7
crates/swc_ecma_minifier/tests/fixture/issues/8718/5/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,7 @@ | ||
let a = 0; | ||
function f() { | ||
a = "123"; | ||
console.log(a); | ||
} | ||
|
||
console.log(((a += 1), (a += 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log(3); |
10 changes: 10 additions & 0 deletions
10
crates/swc_ecma_minifier/tests/fixture/issues/8718/6/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,10 @@ | ||
let a = 0; | ||
function g() { | ||
a = "123"; | ||
console.log(a); | ||
} | ||
function f() { | ||
// a = "123"; | ||
console.log(a); | ||
} | ||
console.log(((a += 1), (a += 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log(3); |
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.