jashkenas / jashkenas/coffeescript
Bug: Invalid indentation allowed after `do`
- Dominant language
- CoffeeScript
- Stars
- 16.6k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
Bug report (minor)
### Input Code
```coffee
foo = do
bar = getBar()
indented
indented
notIndented
notIndented
```
### Expected Behavior
Compilation error: unexpected indentation of `indented` on line 3
### Current Behavior
```js
var bar, foo;
foo = (bar = getBar())();
indented;
indented;
notIndented;
notIndented;
```
### Analysis
The token stream incorrectly has no `DEDENT` token:
`[IDENTIFIER foo] [= =] [DO do] [IDENTIFIER bar] [= =] [IDENTIFIER getBar] [CALL_START (] [CALL_END )] [TERMINATOR \n] [IDENTIFIER indented] [TERMINATOR \n] [IDENTIFIER notIndented] [TERMINATOR \n]`
Hopefully not too hard a fix...
### Context
The current behavior (pointed out by a user) could lead users to write buggy code, because it seems like the indented code is executed "within" the `do`, but it isn't. (Unlike e.g. if the `do` was followed by `->` as is usual.)
### Environment
* CoffeeScript version: 2.7.0
* Node.js version: 19.9.0
Contributor guide
Research direction
Start by reproducing the CoffeeScript 2.7.0 example and inspecting the token stream around `do`, indentation, and `DEDENT`. The fix is complete when the shown input produces a compilation error for the unexpected indentation instead of compiling the indented statements, with regression coverage for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- coffeescript, nodejs
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100