This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
v2.3.0
- Using
equalsDart
and expectingdartfmt
by default is deprecated. This
requires this package to have a direct dependency on specific versions of
dart_style
(and transitivelyanalyzer
), which is problematic just for
testing infrastructure. To future proof, we've exposed theEqualsDart
class
with aformat
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
andExpression.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 anyExpression
as
a metadata annotation toClass
,Method
,Field,
andParameter
. In
3.0.0
, theAnnotation
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
andConstructor.lambda
. If not
explicitly provided and the body of the function originated from an
Expression
thenlambda
is inferred to be true. This is not a breaking
change yet, as it requires an explicitnull
value. In3.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
toExpression
to access properties with?.
- Added
conditional
toExpression
to use the ternary operator? :
- Methods taking
positionalArguments
acceptIterable<Expression>
- BUG FIX: Parameters can take a
FunctionType
as atype
.
Reference.type
now returns aReference
. Note that this change is
technically breaking but should not impacts most clients.