Formatting removed from VariableDeclaration when changing it's kind
- Dominant language
- TypeScript
- Stars
- 5.3k
- Forks
- 363
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 3
Description
When running the following program:
``` js
var recast = require('recast');
var ast = recast.parse(
'var a = 1,\n' +
' b = 2,\n' +
' c = 3;'
);
ast.program.body[0].kind = 'let';
console.log(recast.print(ast).code);
```
I would expect this output:
``` js
let a = 1,
b = 2,
c = 3;
```
But instead I get:
``` js
let a = 1, b = 2, c = 3;
```
Somehow changing the `kind` of a VariableDeclaration removes all the indentation.
However, when I change `declarations` of VariableDeclaration in all kinds of ways (without changing the number of items), the formatting is preserved correctly.
Interestingly when I add a comment between the declarations, and then change the `kind`, the formatting is preserved.
Contributor guide
No contributing guide indexed for this repository
Research direction
Run the provided recast.parse and recast.print reproduction, then trace how a VariableDeclaration is printed after its kind changes. Compare that path with changing declarations and with the commented example; done means changing var to let preserves the original line breaks and indentation.
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
- 45/100