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

Commit a436e5b

Browse files
authored
Fix const factory constructors (#300)
Fixes #288 Reorder output to write `const` before `factory`.
1 parent 5b582b3 commit a436e5b

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CHANGELOG.md

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

33
* Add support for defining enums.
4+
* Fix keyword ordering for `const factory` constructors.
45

56
## 3.4.1
67

lib/src/emitter.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ class DartEmitter extends Object
157157
if (spec.external) {
158158
output.write('external ');
159159
}
160-
if (spec.factory) {
161-
output.write('factory ');
162-
}
163160
if (spec.constant) {
164161
output.write('const ');
165162
}
163+
if (spec.factory) {
164+
output.write('factory ');
165+
}
166166
output.write(clazz);
167167
if (spec.name != null) {
168168
output..write('.')..write(spec.name);

test/specs/class_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,22 @@ void main() {
248248
);
249249
});
250250

251+
test('should create a class with a const factory constructor', () {
252+
expect(
253+
Class((b) => b
254+
..name = 'Foo'
255+
..constructors.add(Constructor((b) => b
256+
..factory = true
257+
..constant = true
258+
..redirect = refer('_Foo')))),
259+
equalsDart(r'''
260+
class Foo {
261+
const factory Foo() = _Foo;
262+
}
263+
'''),
264+
);
265+
});
266+
251267
test('should create a class with a factory lambda constructor', () {
252268
expect(
253269
Class((b) => b

0 commit comments

Comments
 (0)