jashkenas / jashkenas/coffeescript
Bug: comment after else moved within JSX body
- Dominant language
- CoffeeScript
- Stars
- 16.6k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
### Bug report
### Input Code
```coffee
Component = ->
if x
else # not x
```
### Expected Behavior
I would have expected the comment to stay on the `else` line, or to disappear if this is too much trouble:
```js
var Component;
Component = function() {
if (x) {
return
;
} else { // not x
return
;
}
};
```
### Current Behavior
Instead it renders within the ``, which ends up in the HTML output:
```js
var Component;
Component = function() {
if (x) {
return // not x
;
} else {
return
;
}
};
```
### Possibly Related Issue
#5325 seems likely caused by the same problem, but should result in another test at least.
### Environment
[Demo version](https://coffeescript.org/#try:Component%20%3D%20-%3E%0A%20%20if%20x%0A%20%20%20%20%3Cbutton%3E%0A%20%20%20%20%3C%2Fbutton%3E%0A%20%20else%20%23%20not%20x%0A%20%20%20%20%3Cinput%3E%0A%20%20%20%20%3C%2Finput%3E)
### Workaround
For those running into this problem, a workaround for the above example is to put the comment on its own line:
```coffee
Component = ->
if x
else
# not x
```
## Harder Example
### Input Code
```coffee
Component = ->
{if x
else # not x
}
```
### Current Behavior
```js
var Component;
Component = function() {
return
{x ? // not x
:
}
};
```
### Desired Behavior
```js
var Component;
Component = function() {
return
{x ?
// not x
:
}
};
```
Contributor guide
Research direction
Start with the minimal and harder CoffeeScript JSX examples in the issue and reproduce them through the linked compiler demo. Trace how an inline comment after `else` is attached during compilation, then verify that the comment no longer appears inside the preceding JSX output and that the harder example has the expected placement.
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
- 45/100