Skip to content

v2.3.0

Compare
Choose a tag to compare
@matanlurey matanlurey released this 27 Nov 04:00
· 173 commits to master since this release
0ff897d
  • Using equalsDart and expecting dartfmt by default is deprecated. This
    requires this package to have a direct dependency on specific versions of
    dart_style (and transitively analyzer), which is problematic just for
    testing infrastructure. To future proof, we've exposed the EqualsDart class
    with a format override:
// Copyright (c) 2017, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:code_builder/code_builder.dart';
import 'package:dart_style/dart_style.dart';

final DartFormatter _dartfmt = new DartFormatter();
String _format(String source) {
  try {
    return _dartfmt.format(source);
  } on FormatException catch (_) {
    return _dartfmt.formatStatement(source);
  }
}

/// Should be invoked in `main()` of every test in `test/**_test.dart`.
void useDartfmt() => EqualsDart.format = _format;
  • Added Expression.isA and Expression.isNotA:
void main() {
  test('should emit an is check', () {
    expect(
      refer('foo').isA(refer('String')),
      equalsDart('foo is String'),
    );
  });
}
  • Deprecated Annotation. It is now legal to simply pass any Expression as
    a metadata annotation to Class, Method, Field, and Parameter. In
    3.0.0, the Annotation class will be completely removed:
void main() {
  test('should create a class with a annotated constructor', () {
    expect(
      new Class((b) => b
        ..name = 'Foo'
        ..constructors.add(
          new Constructor((b) => b..annotations.add(refer('deprecated'))))),
      equalsDart(r'''
        class Foo {
          @deprecated
          Foo();
        }
      '''),
    );
  });
}
  • Added inference support for Method.lambda and Constructor.lambda. If not
    explicitly provided and the body of the function originated from an
    Expression then lambda is inferred to be true. This is not a breaking
    change yet, as it requires an explicit null value. In 3.0.0 this will be
    the default:
void main() {
  final animal = new Class((b) => b
    ..name = 'Animal'
    ..extend = refer('Organism')
    ..methods.add(new Method.returnsVoid((b) => b
      ..name = 'eat'
      // In 3.0.0, this may be omitted and still is inferred.
      ..lambda = null
      ..body = refer('print').call([literalString('Yum!')]).code)));
  final emitter = new DartEmitter();
  print(new DartFormatter().format('${animal.accept(emitter)}'));
}
  • Added nullSafeProperty to Expression to access properties with ?.
  • Added conditional to Expression to use the ternary operator ? :
  • Methods taking positionalArguments accept Iterable<Expression>
  • BUG FIX: Parameters can take a FunctionType as a type.
    Reference.type now returns a Reference. Note that this change is
    technically breaking but should not impacts most clients.