Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure the initializer of hoisted variables is deoptimized (#4149)
* Make sure the initializer of hoisted variables is deoptimized * Also deoptimize var initializers when force deoptimizing via flag * Do not check types on Windows
- Loading branch information
1 parent
6eaecf3
commit 6260def
Showing
11 changed files
with
76 additions
and
13 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
3 changes: 3 additions & 0 deletions
3
test/form/samples/deoptimize-var-in-hoisted-scopes/_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: 'deoptimizes var variables in hoisted scopes' | ||
}; |
15 changes: 15 additions & 0 deletions
15
test/form/samples/deoptimize-var-in-hoisted-scopes/_expected.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,15 @@ | ||
const obj1 = { flag: false }; | ||
{ | ||
var foo = obj1; | ||
foo.flag = true; | ||
} | ||
if (obj1.flag) console.log('retained'); | ||
|
||
const obj2 = { flag: false }; | ||
try { | ||
throw new Error(); | ||
} catch { | ||
var foo = obj2; | ||
foo.flag = true; | ||
} | ||
if (obj2.flag) console.log('retained'); |
15 changes: 15 additions & 0 deletions
15
test/form/samples/deoptimize-var-in-hoisted-scopes/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,15 @@ | ||
const obj1 = { flag: false }; | ||
{ | ||
var foo = obj1; | ||
foo.flag = true; | ||
} | ||
if (obj1.flag) console.log('retained'); | ||
|
||
const obj2 = { flag: false }; | ||
try { | ||
throw new Error(); | ||
} catch { | ||
var foo = obj2; | ||
foo.flag = true; | ||
} | ||
if (obj2.flag) console.log('retained'); |
6 changes: 6 additions & 0 deletions
6
test/function/samples/correct-var-before-declaration-deopt/_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,6 @@ | ||
module.exports = { | ||
description: 'adds necessary deoptimizations when using treeshake.correctVarBeforeDeclaration', | ||
options: { | ||
treeshake: { correctVarValueBeforeDeclaration: true } | ||
} | ||
}; |
15 changes: 15 additions & 0 deletions
15
test/function/samples/correct-var-before-declaration-deopt/_expected.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,15 @@ | ||
const obj1 = { flag: false }; | ||
{ | ||
var foo = obj1; | ||
foo.flag = true; | ||
} | ||
if (obj1.flag) console.log('retained'); | ||
|
||
const obj2 = { flag: false }; | ||
try { | ||
throw new Error(); | ||
} catch { | ||
var foo = obj2; | ||
foo.flag = true; | ||
} | ||
if (obj2.flag) console.log('retained'); |
7 changes: 7 additions & 0 deletions
7
test/function/samples/correct-var-before-declaration-deopt/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,7 @@ | ||
const obj = { flag: false }; | ||
var foo = obj; | ||
foo.flag = true; | ||
assert.ok(obj.flag ? true : false, 'init deoptimization'); | ||
|
||
assert.ok(bar ? false : true, 'value deoptimization'); | ||
var bar = true; |