dart-lang / code_builder

A fluent API for generating valid Dart source code
https://pub.dev/packages/code_builder
BSD 3-Clause "New" or "Revised" License
423 stars 66 forks source link

Add an example of generating an anonymous closure #384

Closed eseidel closed 1 year ago

eseidel commented 1 year ago

This fixes https://github.com/dart-lang/code_builder/issues/381.

eseidel commented 1 year ago

Amusingly if you leave off the ..body for Method it just produces '(a)' which is probably a separate bug. Also Code('') produces '{ }', note the space, which may also be a bug. 🤷

eseidel commented 1 year ago

I have no ability to merge, please do. :)

natebosch commented 1 year ago

if you leave off the ..body for Method it just produces '(a)' which is probably a separate bug

Yeah I do think we should fallback to an empty body. I'm not sure if there are other values that result in invalid code when omitted - we probably only cover the very common omissions.

note the space, which may also be a bug.

We don't make guarantees about whitespace in the output, but I can check it that's an easy space to omit.

natebosch commented 1 year ago

Thanks!