|
| 1 | +## 2.0.0 |
| 2 | + |
| 3 | +Re-released without a direct dependency on `package:analyzer`! |
| 4 | + |
| 5 | +For users of the `1.x` branch of `code_builder`, this is a pretty big breaking |
| 6 | +change but ultimately is for the better - it's easier to evolve this library |
| 7 | +now and even add your own builders on top of the library. |
| 8 | + |
| 9 | +```dart |
| 10 | +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 11 | +// for details. All rights reserved. Use of this source code is governed by a |
| 12 | +// BSD-style license that can be found in the LICENSE file. |
| 13 | +
|
| 14 | +import 'package:code_builder/code_builder.dart'; |
| 15 | +import 'package:dart_style/dart_style.dart'; |
| 16 | +
|
| 17 | +void main() { |
| 18 | + final animal = new Class((b) => b |
| 19 | + ..name = 'Animal' |
| 20 | + ..extend = refer('Organism') |
| 21 | + ..methods.add(new Method.returnsVoid((b) => b |
| 22 | + ..name = 'eat' |
| 23 | + ..lambda = true |
| 24 | + ..body = const Code('print(\'Yum\')')))); |
| 25 | + final emitter = new DartEmitter(); |
| 26 | + print(new DartFormatter().format('${animal.accept(emitter)}')); |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +...outputs... |
| 31 | + |
| 32 | +```dart |
| 33 | +class Animal extends Organism { |
| 34 | + void eat() => print('Yum!'); |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +**Major changes**: |
| 39 | + |
| 40 | +* Builders now use `built_value`, and have a more consistent, friendly API. |
| 41 | +* Builders are now consistent - they don't any work until code is emitted. |
| 42 | +* It's possible to overwrite the built-in code emitting, formatting, etc by |
| 43 | + providing your own visitors. See `DartEmitter` as an example of the built-in |
| 44 | + visitor/emitter. |
| 45 | +* Most of the expression and statement level helpers were removed; in practice |
| 46 | + they were difficult to write and maintain, and many users commonly asked for |
| 47 | + opt-out type APIs. See the `Code` example below: |
| 48 | + |
| 49 | +```dart |
| 50 | +void main() { |
| 51 | + var code = new Code('x + y = z'); |
| 52 | + code.expression; |
| 53 | + code.statement; |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +See the commit log, examples, and tests for full details. While we want to try |
| 58 | +and avoid breaking changes, suggestions, new features, and incremental updates |
| 59 | +are welcome! |
| 60 | + |
1 | 61 | ## 2.0.0-beta |
2 | 62 |
|
3 | 63 | * Added `lazySpec` and `lazyCode` to lazily create code on visit [#145](https://github.com/dart-lang/code_builder/issues/145). |
|
0 commit comments