dsherret / dsherret/ts-morph

Feaure request: Ability to defer manipulations and generate TextChange[] or FileTextChanges[]

Open
#1,464 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

**Is your feature request related to a problem? Please describe.**

I'm writing a script that automatically add JSDoc for more than 1k enum members in a single file.
It takes more than 15 seconds to `addJSDoc` for every enum members. And editing the structure cannot preserve the indentation.

**Describe the solution you'd like**

Add a method such as:
```typescript
const textChanges = sourceFile.defered(() => {
for (const enumMember of enumNode.getMembers()) {
enumMember.addJsDoc('balabala');
}
});
sourceFile.applyTextChanges(textChanges);
```

**Describe alternatives you've considered**

Manually generate TextChange objects, and then apply them, which will only cost about 300ms, much less than 15000ms+!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.