Skip to content

Commit 2a2a2d6

Browse files
[code_builder] Set external and static in correct order (#2120)
1 parent a4335eb commit 2a2a2d6

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

pkgs/code_builder/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Upgrade `dart_style` and `source_gen` to remove `package:macros` dependency.
44
* Require Dart `^3.6.0` due to the upgrades.
55
* Support `Expression.newInstanceNamed` with empty name
6+
* Fixed bug: Fields declared with `static` and `external` now produce code with correct order
67

78
## 4.10.1
89

pkgs/code_builder/lib/src/emitter.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,15 @@ class DartEmitter extends Object
437437
for (var a in spec.annotations) {
438438
visitAnnotation(a, output);
439439
}
440+
if (spec.external) {
441+
output.write('external ');
442+
}
440443
if (spec.static) {
441444
output.write('static ');
442445
}
443446
if (spec.late && _useNullSafetySyntax) {
444447
output.write('late ');
445448
}
446-
if (spec.external) {
447-
output.write('external ');
448-
}
449449
switch (spec.modifier) {
450450
case FieldModifier.var$:
451451
if (spec.type == null) {

pkgs/code_builder/test/specs/field_test.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,34 @@ void main() {
110110
'''),
111111
);
112112
});
113+
114+
test('should create a late static field', () {
115+
expect(
116+
Field((b) => b
117+
..name = 'value'
118+
..static = true
119+
..late = true
120+
..type = refer('String')
121+
..annotations.addAll([refer('JS').call([])])),
122+
equalsDart(r'''
123+
@JS()
124+
static late String value;
125+
''', DartEmitter(useNullSafetySyntax: true)),
126+
);
127+
});
128+
129+
test('should create an external static field', () {
130+
expect(
131+
Field((b) => b
132+
..name = 'value'
133+
..external = true
134+
..static = true
135+
..type = refer('double')
136+
..annotations.addAll([refer('JS').call([])])),
137+
equalsDart(r'''
138+
@JS()
139+
external static double value;
140+
'''),
141+
);
142+
});
113143
}

0 commit comments

Comments
 (0)