Skip to content
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

catch block introduces extra var #5414

Open
STRd6 opened this issue Apr 22, 2022 · 2 comments
Open

catch block introduces extra var #5414

STRd6 opened this issue Apr 22, 2022 · 2 comments

Comments

@STRd6
Copy link
Contributor

STRd6 commented Apr 22, 2022

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.

@GeoffreyBooth
Copy link
Collaborator

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.

@STRd6
Copy link
Contributor Author

STRd6 commented Apr 23, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants