benjamn / benjamn/recast

Reprinting file causes line break changes

Open
#215 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
5.3k
Forks
364
Avg merge
3d 8h
Merged PRs (30d)
3

Description

Parsing and reprinting

``` js
// I have a parent
newNode.parent
&& (
(// Or I did but its different than the one I have now.
!originalNode.parent ||
newNode.parent.key !== originalNode.parent.key
)
)
```

outputs

``` js
// I have a parent
newNode.parent
&& (
(// Or I did but its different than the one I have now.
(!originalNode.parent || newNode.parent.key !== originalNode.parent.key)
)
)
```

which is inconvenient for codemods. Verified using 0.10.32 by running

```
console.log(recast.print(recast.parse("// I have a parent\nnewNode.parent\n && (\n (// Or I did but its different than the one I have now.\n !originalNode.parent ||\n newNode.parent.key !== originalNode.parent.key\n )\n )")).code)
```

in node.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the provided Node.js reproduction with recast.parse and recast.print, comparing its output with the original source. Trace the printing behavior responsible for the changed line breaks, and consider the issue resolved when this example preserves the original breaks around the logical expression.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.