dsherret/code-block-writer

Lazily evaluate conditional writes

lazarljubenovic opened this issue · 5 comments

Currently, the following throws (naturally) if foo is null.

this.conditionalWrite(foo != null, foo.bar)

However, this would not throw if the function was evaluated only after the conditional check has been passed:

this.conditionalWrite(foo != null, () => foo.bar)

We could still support the old one, of course, so it can be done as a non-breaking change.

@lazarljubenovic this one is good too!

If you'd like to submit a pull request then feel free, but if not then I'll get to it soon.

Glad to help! I'll fiddle around with it tomorrow ✨

Thanks a lot once again! This is released in v6.14.0.

@lazarljubenovic by the way, I'm happy you're using this. I've been slowly converting the internals of ts-simple-ast over to using it and it's made everything much better.

And I am so happy it exists. Just thinking about handling indentation and trying to nail indentation with multiline strings makes me feel pain.