Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not tear apart declarations in loop or if bodies (#3947)
- Loading branch information
1 parent
683cf48
commit 6705fdc
Showing
25 changed files
with
111 additions
and
44 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
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
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
4 changes: 4 additions & 0 deletions
4
test/function/samples/unused-do-while-loop-declaration/_config.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,4 @@ | ||
module.exports = { | ||
description: | ||
'does not partially tree-shake unused declarations with side-effects in do-while loop bodies' | ||
}; |
8 changes: 8 additions & 0 deletions
8
test/function/samples/unused-do-while-loop-declaration/main.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 result = 3; | ||
var b = 3; | ||
|
||
do var b = b - 1, unused = result--, unused2 = 0; | ||
while (b > 0); | ||
|
||
assert.strictEqual(b, 0); | ||
assert.strictEqual(result, 0); |
4 changes: 4 additions & 0 deletions
4
test/function/samples/unused-for-in-loop-declaration/_config.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,4 @@ | ||
module.exports = { | ||
description: | ||
'does not partially tree-shake unused declarations with side-effects in for-in loop bodies' | ||
}; |
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 result = 3; | ||
var b = 3; | ||
|
||
for (var x in {foo: 1, bar: 2}) var b = b - 1, unused = result--, unused2 = 0; | ||
|
||
assert.strictEqual(b, 1); | ||
assert.strictEqual(result, 1); |
4 changes: 4 additions & 0 deletions
4
test/function/samples/unused-for-loop-body-declaration/_config.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,4 @@ | ||
module.exports = { | ||
description: | ||
'does not partially tree-shake unused declarations with side-effects in for loop bodies' | ||
}; |
6 changes: 6 additions & 0 deletions
6
test/function/samples/unused-for-loop-body-declaration/main.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,6 @@ | ||
let result = 3; | ||
|
||
for (var a = 0; a < 3; a++) var b = a, unused = result--; | ||
|
||
assert.strictEqual(b, 2); | ||
assert.strictEqual(result, 0); |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...mples/unused-for-loop-declaration/main.js → .../unused-for-loop-init-declaration/main.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
4 changes: 4 additions & 0 deletions
4
test/function/samples/unused-for-of-loop-declaration/_config.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,4 @@ | ||
module.exports = { | ||
description: | ||
'does not partially tree-shake unused declarations with side-effects in for-of loop bodies' | ||
}; |
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 result = 3; | ||
var b = 3; | ||
|
||
for (var x of [1, 2]) var b = b - 1, unused = result--, unused2 = 0; | ||
|
||
assert.strictEqual(b, 1); | ||
assert.strictEqual(result, 1); |
3 changes: 3 additions & 0 deletions
3
test/function/samples/unused-if-statement-declaration/_config.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 @@ | ||
module.exports = { | ||
description: 'does not partially tree-shake unused declarations with side-effects in for loops' | ||
}; |
12 changes: 12 additions & 0 deletions
12
test/function/samples/unused-if-statement-declaration/main.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 result; | ||
|
||
export function testStatement(condition) { | ||
if (condition) var a = 1, b = result = 1, unused1 = 3; | ||
else var a = 2, c = result = 2, unused2 = 3; | ||
return a; | ||
} | ||
|
||
assert.strictEqual(testStatement(true), 1); | ||
assert.strictEqual(result, 1); | ||
assert.strictEqual(testStatement(false), 2); | ||
assert.strictEqual(result, 2); |
4 changes: 4 additions & 0 deletions
4
test/function/samples/unused-while-loop-declaration/_config.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,4 @@ | ||
module.exports = { | ||
description: | ||
'does not partially tree-shake unused declarations with side-effects in while loop bodies' | ||
}; |
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 result = 3; | ||
var b = 3; | ||
|
||
while (b > 0) | ||
var b = b - 1, unused = result--, unused2 = 0; | ||
|
||
assert.strictEqual(b, 0); | ||
assert.strictEqual(result, 0); |