recast generates invalid code when printing destructuring assignment expressions preceded by comments
- Dominant language
- TypeScript
- Stars
- 5.3k
- Forks
- 363
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 3
Description
Using recast 0.17.3:
```js
const recast = require('recast');
const ast = recast.parse('(/**/{foo} = 1)');
const assignmentExpressionText = recast.print(ast.program.body[0].expression).code;
console.log(assignmentExpressionText);
```
Expected output: something like `(/**/{foo} = 1)` or `{foo} = 1`
Actual output: `(/**/)({foo} = 1)`
The output is invalid code because the initial parentheses are only surrounding a comment and nothing else.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by running the recast.parse and recast.print reproduction in the issue and compare the printed code with the expected valid forms. Trace how the expression from ast.program.body[0].expression is printed when a leading comment appears before the destructuring assignment, then add coverage showing that the output is valid JavaScript and no longer becomes `(/**/)({foo} = 1)`.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100