Skip to content

Commit 93276f5

Browse files
mattrberrymosuem
andauthored
Support newInstanceNamed with empty name (#1194)
Co-authored-by: Moritz <[email protected]>
1 parent 4a28415 commit 93276f5

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

pkgs/code_builder/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Upgrade `dart_style` and `source_gen` to remove `package:macros` dependency.
44
* Require Dart `^3.6.0` due to the upgrades.
5+
* Support `Expression.newInstanceNamed` with empty name
56

67
## 4.10.1
78

pkgs/code_builder/lib/src/specs/expression.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,10 @@ abstract mixin class ExpressionEmitter
578578
final out = output ??= StringBuffer();
579579
return _writeConstExpression(out, expression.isConst, () {
580580
expression.target.accept(this, out);
581-
if (expression.name != null) {
581+
if (expression.name case final name? when name.isNotEmpty) {
582582
out
583583
..write('.')
584-
..write(expression.name);
584+
..write(name);
585585
}
586586
if (expression.typeArguments.isNotEmpty) {
587587
out.write('<');

pkgs/code_builder/test/specs/code/expression_test.dart

+7
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ void main() {
251251
);
252252
});
253253

254+
test('should emit invoking unnamed constructor when name is empty', () {
255+
expect(
256+
refer('Foo').newInstanceNamed('', []),
257+
equalsDart('Foo()'),
258+
);
259+
});
260+
254261
test('should emit invoking const Type()', () {
255262
expect(
256263
refer('Object').constInstance([]),

0 commit comments

Comments
 (0)