From 39954cbf46b73f3c997ab06ff489c80c786d93e7 Mon Sep 17 00:00:00 2001 From: Nike Okoronkwo Date: Wed, 2 Jul 2025 09:00:34 -0400 Subject: [PATCH 1/3] Set `external` and `static` in correct order --- pkgs/code_builder/lib/src/emitter.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/code_builder/lib/src/emitter.dart b/pkgs/code_builder/lib/src/emitter.dart index 12109cc38d..64e2aa46cb 100644 --- a/pkgs/code_builder/lib/src/emitter.dart +++ b/pkgs/code_builder/lib/src/emitter.dart @@ -437,15 +437,15 @@ class DartEmitter extends Object for (var a in spec.annotations) { visitAnnotation(a, output); } + if (spec.external) { + output.write('external '); + } if (spec.static) { output.write('static '); } if (spec.late && _useNullSafetySyntax) { output.write('late '); } - if (spec.external) { - output.write('external '); - } switch (spec.modifier) { case FieldModifier.var$: if (spec.type == null) { From e2b74da28927b94249dc8f68eb025c9e00c5f9eb Mon Sep 17 00:00:00 2001 From: Nike Okoronkwo Date: Wed, 2 Jul 2025 11:54:53 -0400 Subject: [PATCH 2/3] added tests for `external`, `static` and `late` for field spec --- pkgs/code_builder/test/specs/field_test.dart | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pkgs/code_builder/test/specs/field_test.dart b/pkgs/code_builder/test/specs/field_test.dart index 3d53687bcf..0b8d6d905b 100644 --- a/pkgs/code_builder/test/specs/field_test.dart +++ b/pkgs/code_builder/test/specs/field_test.dart @@ -110,4 +110,34 @@ void main() { '''), ); }); + + test('should create a late static field', () { + expect( + Field((b) => b + ..name = 'value' + ..static = true + ..late = true + ..type = refer('String') + ..annotations.addAll([refer('JS').call([])])), + equalsDart(r''' + @JS() + static late String value; + ''', DartEmitter(useNullSafetySyntax: true)), + ); + }); + + test('should create an external static field', () { + expect( + Field((b) => b + ..name = 'value' + ..external = true + ..static = true + ..type = refer('double') + ..annotations.addAll([refer('JS').call([])])), + equalsDart(r''' + @JS() + external static double value; + '''), + ); + }); } From d11a07a8b545b2428281caa2987018b772f9af66 Mon Sep 17 00:00:00 2001 From: Nike Okoronkwo Date: Thu, 3 Jul 2025 11:31:58 -0400 Subject: [PATCH 3/3] updated CHANGELOG --- pkgs/code_builder/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/code_builder/CHANGELOG.md b/pkgs/code_builder/CHANGELOG.md index 1d86e5cbb7..f8459a3226 100644 --- a/pkgs/code_builder/CHANGELOG.md +++ b/pkgs/code_builder/CHANGELOG.md @@ -3,6 +3,7 @@ * Upgrade `dart_style` and `source_gen` to remove `package:macros` dependency. * Require Dart `^3.6.0` due to the upgrades. * Support `Expression.newInstanceNamed` with empty name +* Fixed bug: Fields declared with `static` and `external` now produce code with correct order ## 4.10.1