New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not tear apart declarations in loop or if bodies #3947
Merged
lukastaegert
merged 1 commit into
master
from
partially-tree-shaken-loop-body-declarations
Feb 2, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is it different from
this.left.include(context, true);
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a special string value for
includeChildrenRecursively
that is liketrue
but also includes "related" code. Something we use to deoptimize try-catch statements.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would need to do something rather nonsensical like this to get a change from that:
https://rollupjs.org/repl/?version=2.38.4&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmZ1bmN0aW9uJTIwdGVzdChjYWxsYmFjayklMjAlN0IlNUNuJTIwJTIwdHJ5JTIwJTdCJTVDbiUyMCUyMCUyMCUyMGZvciUyMCglN0Jmb28lMjAlM0QlMjBjYWxsYmFjaygpJTdEJTIwaW4lMjAlN0JiYXIlM0ElMjAxJTdEKSUyMCU3QiU3RCUzQiU1Q24lMjAlMjAlN0QlMjBjYXRjaCUyMCU3QiU3RCU1Q24lN0QlNUNuJTVDbnRlc3QoKCklMjAlM0QlM0UlMjAlN0IlNUNuJTVDdCUyRiUyRiUyMFRoaXMlMjBpcyUyMG9ubHklMjByZXRhaW5lZCUyMGJlY2F1c2UlMjBvZiUyMHRoZSUyMHNwZWNpYWwlMjBwYXJhbWV0ZXIlMjB2YWx1ZSU1Q24lMjAlMjBPYmplY3QuY3JlYXRlKG51bGwpJTVDbiU3RCklM0IlMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSU3RCU1RCUyQyUyMm9wdGlvbnMlMjIlM0ElN0IlMjJmb3JtYXQlMjIlM0ElMjJlcyUyMiUyQyUyMm5hbWUlMjIlM0ElMjJteUJ1bmRsZSUyMiUyQyUyMmFtZCUyMiUzQSU3QiUyMmlkJTIyJTNBJTIyJTIyJTdEJTJDJTIyZ2xvYmFscyUyMiUzQSU3QiU3RCU3RCUyQyUyMmV4YW1wbGUlMjIlM0FudWxsJTdE