-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle hoisted variables in dead branches of nested if statements
- Loading branch information
1 parent
022770a
commit f3d7a27
Showing
5 changed files
with
61 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,9 @@ if (foo) { | |
} | ||
|
||
{ | ||
var bar = true; | ||
var bar; { | ||
bar = true; | ||
} | ||
} | ||
|
||
if (bar) { | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'handles hoisted variables in chained if statements', | ||
exports(exports) { | ||
exports.test(true); | ||
assert.strictEqual(exports.result, 'first'); | ||
exports.test(false); | ||
assert.strictEqual(exports.result, 'third'); | ||
} | ||
}; |
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,19 @@ | ||
export let result; | ||
|
||
export function test(value) { | ||
if (value) { | ||
v = 'first'; | ||
result = v; | ||
} else if (false) { | ||
var v, w; | ||
result = 'second'; | ||
} else { | ||
v = 'third'; | ||
result = v; | ||
} | ||
|
||
for (var foo of []) if (false) var x; else { | ||
x = 'fourth'; | ||
result = x; | ||
} | ||
} |