Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit aa7f62d

Browse files
Add support for external keyword on fields (#422)
Add `external` field to `FieldBuilder` and emit the keyword in the visitor.
1 parent 3b2039b commit aa7f62d

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 4.6.0-wip
22

33
* Add support for named arguments in `enum` classes
4+
* Add support for external keyword on fields.
45

56
## 4.5.0
67

lib/src/emitter.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ class DartEmitter extends Object
386386
if (spec.late && _useNullSafetySyntax) {
387387
output.write('late ');
388388
}
389+
if (spec.external) {
390+
output.write('external ');
391+
}
389392
switch (spec.modifier) {
390393
case FieldModifier.var$:
391394
if (spec.type == null) {

lib/src/specs/field.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ abstract class Field extends Object
4141
/// Whether this field should be prefixed with `late`.
4242
bool get late;
4343

44+
/// Whether the field should be prefixed with `external`.
45+
bool get external;
46+
4447
/// Name of the field.
4548
String get name;
4649

@@ -86,6 +89,9 @@ abstract class FieldBuilder extends Object
8689
/// Whether this field should be prefixed with `late`.
8790
bool late = false;
8891

92+
/// Whether the field should be prefixed with `external`.
93+
bool external = false;
94+
8995
/// Name of the field.
9096
String? name;
9197

lib/src/specs/field.g.dart

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/specs/field_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,18 @@ void main() {
9696
'''),
9797
);
9898
});
99+
100+
test('should create a external field', () {
101+
expect(
102+
Field((b) => b
103+
..name = 'value'
104+
..external = true
105+
..type = refer('double')
106+
..annotations.addAll([refer('Float').call([])])),
107+
equalsDart(r'''
108+
@Float()
109+
external double value;
110+
'''),
111+
);
112+
});
99113
}

0 commit comments

Comments
 (0)