Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/code_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions pkgs/code_builder/lib/src/emitter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 30 additions & 0 deletions pkgs/code_builder/test/specs/field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
'''),
);
});
}
Loading