-
Notifications
You must be signed in to change notification settings - Fork 2k
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
try/catch unnecessarily defines unused variable error
#4088
Comments
@vendethiel I suspected JScript may be at fault here; however v1.9.3 didn't define the additional variable: // Generated by CoffeeScript 1.9.3
(function() {
var main;
main = function() {
var e;
try {
throw new Error("Hello");
} catch (_error) {
e = _error;
console.log(e);
}
return console.log(e);
};
}).call(this); The only negative I can see to this approach is that on the faulty JScript it will define/clobber a global The v1.10.0 solution creates an ESLint error which, if disabled, will allow many more issues in a codebase to go undetected (defining a variable but never using it is often a sign that something's awry). Sadly the unused variable detection in CoffeeLint is not as powerful as that of ESLint so we tend to use both (we even wrote an ESLint formatter that reports the location of the issue honouring sourcemaps). I think this particular solution to the issue needs revisiting. |
Yes, it looks like a potential regression. I think the scoping was refactored a bit more recently. |
oh whoops, sorry again. I didn't look closely enough... my bad. |
Fix #4088: Don't declare caught variables
The CS code
Compiles to:
However
catch (error)
defineserror
within the scope of the catch block - defining it outside the scope of the catch block has no effect (and means there's a defined but unused variable which causes ESLint issues). This demonstrates thatvar error
is not used:which results in:
If I'm reading them right, section 12.14 of both v3 and v5 of the ECMA specs seem to imply that the catch block adds a new scope to the scope chain.
The text was updated successfully, but these errors were encountered: