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 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) { 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; + '''), + ); + }); }