From 8df6231f31cf2b3804aad40d62cb074ce431c509 Mon Sep 17 00:00:00 2001 From: Matthew Berry Date: Tue, 12 Nov 2024 10:41:47 -0800 Subject: [PATCH 1/2] Support newInstanceNamed with empty name --- pkgs/code_builder/lib/src/specs/expression.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/code_builder/lib/src/specs/expression.dart b/pkgs/code_builder/lib/src/specs/expression.dart index b9193e6f3..529cd42dd 100644 --- a/pkgs/code_builder/lib/src/specs/expression.dart +++ b/pkgs/code_builder/lib/src/specs/expression.dart @@ -578,7 +578,7 @@ abstract mixin class ExpressionEmitter final out = output ??= StringBuffer(); return _writeConstExpression(out, expression.isConst, () { expression.target.accept(this, out); - if (expression.name != null) { + if (expression.name case final name? when name.isNotEmpty) { out ..write('.') ..write(expression.name); From 40ecf3bc71213c418cb0c32c7d451450584e9017 Mon Sep 17 00:00:00 2001 From: Matthew Berry Date: Tue, 12 Nov 2024 10:44:16 -0800 Subject: [PATCH 2/2] Update expression_test.dart --- pkgs/code_builder/test/specs/code/expression_test.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/code_builder/test/specs/code/expression_test.dart b/pkgs/code_builder/test/specs/code/expression_test.dart index 4ce9ebaf5..7a424fd8e 100644 --- a/pkgs/code_builder/test/specs/code/expression_test.dart +++ b/pkgs/code_builder/test/specs/code/expression_test.dart @@ -251,6 +251,13 @@ void main() { ); }); + test('should emit invoking unnamed constructor when name is empty', () { + expect( + refer('Foo').newInstanceNamed('', []), + equalsDart('Foo()'), + ); + }); + test('should emit invoking const Type()', () { expect( refer('Object').constInstance([]),