Slight issue in formatted code with ObjectLiteralExpression.addPropertyAssignment()
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 238
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
**Describe the bug**
Trying to add a property assignment to an object literal which exists inside of a CallExpression, but seems the formatting gets an extra level of indentation when doing so.
Version: 6.0.2
**To Reproduce**
```ts
import { Project, SyntaxKind } from 'ts-morph';
const project = new Project();
const sourceFile = project.createSourceFile('test.ts', `
const obj = doSomething({});
`);
const objLiteral = sourceFile.getDescendantsOfKind(SyntaxKind.ObjectLiteralExpression)[0];
objLiteral.addPropertyAssignment({
name: 'myProp',
initializer: '42'
});
console.log('sourceFile: ', sourceFile.getFullText());
```
**Expected behavior**
Would expect the output source file to be formatted as:
```ts
const obj = doSomething({
myProp: 42
});
```
However it ends up being formatted as:
```ts
const obj = doSomething({
myProp: 42
});
```
Contributor guide
Research direction
Start with the TypeScript reproduction in the issue and trace ObjectLiteralExpression.addPropertyAssignment() when the object literal is inside a CallExpression. Compare sourceFile.getFullText() with the expected output; done means the added property and closing delimiter use the shown indentation without the extra level.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100