Created
July 24, 2014 18:16
-
-
Save rodyhaddad/57e060cc3100fab8bf53 to your computer and use it in GitHub Desktop.
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
function test() { | |
let a = 4; | |
if (true) { | |
const x = 1; | |
var y = 2; | |
let a = 3; | |
a = x + y; | |
} | |
console.log(a); | |
if (typeof a === "undefined") { | |
console.log('a should change to the top-level one', a); | |
} | |
if (typeof x === "undefined") { | |
console.log('should stay as x in the typeof'); | |
} | |
} | |
// becomes | |
function test() { | |
var $__0; | |
var $__1; | |
var $__2; | |
$__0 = 4; | |
if (true) { | |
$__1 = 1; | |
var y = 2; | |
$__2 = 3; | |
$__2 = $__1 + y; | |
} | |
console.log($__0); | |
if (typeof $__0 === "undefined") { | |
console.log('a should change to the top-level one', $__0); | |
} | |
if (typeof x === "undefined") { | |
console.log('should stay as x in the typeof'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A cleaner output might look like:
Or rename the vars to something that has the original name in to make it easier to reason about
I'm not sure how safe a renaming like that would be. We could do a more sophisticated temp var scheme at some later point. Don't let that block you.