ts-morph
ts-morph copied to clipboard
Ability to insert/add clauses into a switch statement
Need to think this through...
const switchStatement = ...;
switchStatement.insertClause(0, {
caseLabel: "5",
body: "console.log(5);" // or writer => writer.writeLine(5);
});
switchStatement.insertClause(0, {
caseLabel: "9"
});
switchStatement.insertClause(0, {
isDefault: true // i don't really like this...
});
Any workarounds for achieving this today?
@zaach the workaround right now is to use what's outlined on this page or to use AST Transforms (both solutions are not very ideal... maybe using replaceWithText is your best bet).
I have the same goal (modifying a switch statement) I wasn't sure where to post my question, so I started a stackoverflow one. I appreciate your help.