ts-morph icon indicating copy to clipboard operation
ts-morph copied to clipboard

Ability to insert/add clauses into a switch statement

Open dsherret opened this issue 7 years ago • 3 comments

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...
});

dsherret avatar Jan 10 '18 04:01 dsherret

Any workarounds for achieving this today?

zaach avatar Apr 24 '20 22:04 zaach

@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).

dsherret avatar Apr 26 '20 22:04 dsherret

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.

Nilegfx avatar Mar 06 '23 13:03 Nilegfx