Recast printer not preserving identity with inline comments
- Dominant language
- TypeScript
- Stars
- 5.3k
- Forks
- 363
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 3
Description
The following assertion fails, as the parentheses are incorrectly moved by the recast printer, breaking the guaranteed identity of non-modified code:
```
const recast = require('recast');
const assert = require('assert');
const input = 'foo + (/** @type {number} */(bar) - baz);'
const output = recast.print(recast.parse(input)).code;
assert.equal(input, output);
```
Actual output:
`foo + (/** @type {number} */(bar - baz));`
Expected output:
`foo + (/** @type {number} */(bar) - baz);'`
This actually breaks my build, as the closure compiler cast is now being applied to the result of `bar - baz` instead of solely on `bar`.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the provided recast.parse and recast.print reproduction, then inspect the printer handling of inline comments and parentheses. Done means the assertion passes and the input remains unchanged when printing this code.
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
- Clearly specified
- Newbie friendliness
- 48/100