jashkenas / jashkenas/coffeescript

`catch` block introduces extra var

Open
#5,414 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
CoffeeScript
Stars
16.6k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

```coffee
try
catch e
```

Actual:

```js
// Generated by CoffeeScript 2.6.1
var e;

try {

} catch (error) {
e = error;
}
```

Expected:

```js
// 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.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the CoffeeScript input `try\ncatch e` and inspect the compiler path that generates the shown JavaScript. Compare the output with the expected form, including cases where the catch variable is referenced outside the block. Done means an unused catch variable is not emitted as an extra hoisted `var`, while required outer references retain the documented behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
coffeescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.