dsherret / dsherret/ts-morph

[question] Get thenStatement body text

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

Description

Hi, here is another question.
(Would be nice to start documenting all of that) ;-)

I am doing static computations and I would like to unwrap this statement (replace the original `IFStatement` with one of those block conditions
```
if( "a" === "a"){
console.log("yes");
else {
console.log("no");
}
```

`node.getThenStatement()` gives me a BlockStatement, therefore `node.replaceWithText(thenStatement.getText());` adds `{` and `}` to the code.

What I am trying to do is, get the child's index and inject the contents, but I haven't found a working solution just yet.

Do you have any idea on how to replace that elegantly?

Thanks

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.