ReturnStatement with comment moves the comment
- Dominant language
- TypeScript
- Stars
- 5.3k
- Forks
- 363
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 3
Description
If a `ReturnStatement` has a leading comment, the comment will be moved inside the parentheses. This can be problematic for code using JSDoc `@type` annotations because the comment must be outside the parens. This happens [in the printer](https://github.com/benjamn/recast/blob/master/lib/printer.js#L611) where the line is checked for a leading comment, and wrapped in parentheses if it has one.
I created [this example](http://astexplorer.net/#/gist/0a3ad62148aeacd8efce2c2228a1bd07/dc9689a4317695d3d6615bfa89413ce9028495f2) to reproduce the issue using `jscodeshift` to transform the code.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at lib/printer.js around line 611 and reproduce the behavior with the linked AST Explorer example using jscodeshift. Confirm that a ReturnStatement's leading comment, including a JSDoc @type annotation, stays outside the parentheses after printing; the issue does not mention a test file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100