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
427 stars 66 forks source link

Add declareVar/Final/Const #363

Closed natebosch closed 2 years ago

natebosch commented 2 years ago

Closes #343

These utilities serve as a replacement for assignVar/Final/Const which have an inverted responsibility - the variable is told about it's assignment, rather than an assignment being told about the variable it is assigned to. Unifies the interaction with Expression.assign.

Use named instead of positional optional arguments. Add an optional argument for a late prefix for the final and var declarations. Const variables may not be late.

Will deprecate the assign* methods in a followup after doing some cleanup of internal usage.