coffeescript
coffeescript copied to clipboard
`catch` block introduces extra var
try
catch e
Actual:
// Generated by CoffeeScript 2.6.1
var e;
try {
} catch (error) {
e = error;
}
Expected:
// Generated by CoffeeScript 2.6.1
try {
} catch (e) {
}
I understand that in cases where the catch variable is referenced outside of the catch block it must be var
scoped as all variables in CoffeeScript are but in cases where the variable is not referenced at all outside of the block I don't feel that it should be hoisted.
You might want to dig a little to find where this behavior was added, and why. There might be something particular about catch
blocks that led to this, as it’s not like the actual behavior was easier to implement than the expected.
I expect that it is to handle cases where the variable is used later outside of the catch
block. The issue is that it is also added in cases where the variable is unused outside of the block.