Skip to content

Commit a4e2776

Browse files
authoredMar 16, 2025
Support Dart 3.6.0 and analyzer 6.9.0 as a minimum. (#1192)
1 parent d747b4f commit a4e2776

31 files changed

+517
-600
lines changed
 

‎packages/freezed/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Unreleased patch
22

3-
Update docs (thanks to @lishaduck)
3+
- Update docs (thanks to @lishaduck)
4+
- Support Dart 3.6.0 and analyzer 6.9.0 as a minimum.
45

56
## 3.0.3 - 2025-03-02
67

‎packages/freezed/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,8 @@ targets:
12371237
options:
12381238
# Tells Freezed to format .freezed.dart files.
12391239
# This can significantly slow down code-generation.
1240+
# Disabling formatting will only work when opting into Dart 3.7 as a minimum
1241+
# in your project SDK constraints.
12401242
format: true
12411243
# Disable the generation of copyWith/== for the entire project
12421244
copy_with: false

‎packages/freezed/lib/src/ast.dart

+7-11
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ extension AstX on AstNode {
55
String? get documentation {
66
final builder = StringBuffer();
77

8-
for (
9-
Token? token = beginToken.precedingComments;
10-
token != null;
11-
token = token.next
12-
) {
8+
for (Token? token = beginToken.precedingComments;
9+
token != null;
10+
token = token.next) {
1311
builder.writeln(token);
1412
}
1513

@@ -63,9 +61,8 @@ extension ConstructorX on ConstructorDeclaration {
6361
// ignore: deprecated_member_use, latest analyzer with enclosingElement3 not available in stable channel
6462
final classElement = declaredElement!.enclosingElement3;
6563

66-
var generics = classElement.typeParameters
67-
.map((e) => '\$${e.name}')
68-
.join(', ');
64+
var generics =
65+
classElement.typeParameters.map((e) => '\$${e.name}').join(', ');
6966
if (generics.isNotEmpty) {
7067
generics = '<$generics>';
7168
}
@@ -80,9 +77,8 @@ extension ConstructorX on ConstructorDeclaration {
8077
// ignore: deprecated_member_use, latest analyzer with enclosingElement3 not available in stable channel
8178
final classElement = declaredElement!.enclosingElement3;
8279

83-
var generics = classElement.typeParameters
84-
.map((e) => '\$${e.name}')
85-
.join(', ');
80+
var generics =
81+
classElement.typeParameters.map((e) => '\$${e.name}').join(', ');
8682
if (generics.isNotEmpty) {
8783
generics = '<$generics>';
8884
}

‎packages/freezed/lib/src/freezed_generator.dart

+31-37
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class FreezedGenerator extends ParserGenerator<Freezed> {
3838
if (deepCopyProperty == null || commonGetter == null) continue;
3939

4040
yield deepCopyProperty.copyWith(
41-
nullable:
42-
deepCopyProperty.nullable ||
41+
nullable: deepCopyProperty.nullable ||
4342
commonProperty.isNullable ||
4443
commonGetter.isNullable,
4544
);
@@ -83,23 +82,21 @@ class FreezedGenerator extends ParserGenerator<Freezed> {
8382
Iterable<Object> _generateForData(Library globalData, Class data) sync* {
8483
if (data.options.fromJson) yield FromJson(data);
8584

86-
final commonCopyWith =
87-
data.options.annotation.copyWith ?? true
88-
? CopyWith(
89-
parents: data.parents,
90-
clonedClassName: data.name,
91-
readableProperties: data.properties.readableProperties,
92-
cloneableProperties: data.properties.cloneableProperties,
93-
deepCloneableProperties:
94-
_getCommonDeepCloneableProperties(
95-
data.constructors,
96-
data.properties,
97-
).toList(),
98-
genericsDefinition: data.genericsDefinitionTemplate,
99-
genericsParameter: data.genericsParameterTemplate,
100-
data: data,
101-
)
102-
: null;
85+
final commonCopyWith = data.options.annotation.copyWith ?? true
86+
? CopyWith(
87+
parents: data.parents,
88+
clonedClassName: data.name,
89+
readableProperties: data.properties.readableProperties,
90+
cloneableProperties: data.properties.cloneableProperties,
91+
deepCloneableProperties: _getCommonDeepCloneableProperties(
92+
data.constructors,
93+
data.properties,
94+
).toList(),
95+
genericsDefinition: data.genericsDefinitionTemplate,
96+
genericsParameter: data.genericsParameterTemplate,
97+
data: data,
98+
)
99+
: null;
103100

104101
yield Abstract(
105102
data: data,
@@ -114,24 +111,21 @@ class FreezedGenerator extends ParserGenerator<Freezed> {
114111
constructor: constructor,
115112
commonProperties: data.properties.readableProperties,
116113
globalData: globalData,
117-
copyWith:
118-
data.options.annotation.copyWith ??
119-
constructor.parameters.allParameters.isNotEmpty
120-
? CopyWith(
121-
parents: {},
122-
clonedClassName: constructor.redirectedName,
123-
cloneableProperties: constructor.properties.toList(),
124-
readableProperties:
125-
constructor.properties
126-
.where((e) => e.isSynthetic)
127-
.toList(),
128-
deepCloneableProperties: constructor.deepCloneableProperties,
129-
genericsDefinition: data.genericsDefinitionTemplate,
130-
genericsParameter: data.genericsParameterTemplate,
131-
data: data,
132-
parent: commonCopyWith,
133-
)
134-
: null,
114+
copyWith: data.options.annotation.copyWith ??
115+
constructor.parameters.allParameters.isNotEmpty
116+
? CopyWith(
117+
parents: {},
118+
clonedClassName: constructor.redirectedName,
119+
cloneableProperties: constructor.properties.toList(),
120+
readableProperties:
121+
constructor.properties.where((e) => e.isSynthetic).toList(),
122+
deepCloneableProperties: constructor.deepCloneableProperties,
123+
genericsDefinition: data.genericsDefinitionTemplate,
124+
genericsParameter: data.genericsParameterTemplate,
125+
data: data,
126+
parent: commonCopyWith,
127+
)
128+
: null,
135129
);
136130
}
137131
}

0 commit comments

Comments
 (0)