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
3 changes: 2 additions & 1 deletion packages/freezed/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased patch

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

## 3.0.3 - 2025-03-02

Expand Down
2 changes: 2 additions & 0 deletions packages/freezed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,8 @@ targets:
options:
# Tells Freezed to format .freezed.dart files.
# This can significantly slow down code-generation.
# Disabling formatting will only work when opting into Dart 3.7 as a minimum
# in your project SDK constraints.
format: true
# Disable the generation of copyWith/== for the entire project
copy_with: false
Expand Down
18 changes: 7 additions & 11 deletions packages/freezed/lib/src/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ extension AstX on AstNode {
String? get documentation {
final builder = StringBuffer();

for (
Token? token = beginToken.precedingComments;
token != null;
token = token.next
) {
for (Token? token = beginToken.precedingComments;
token != null;
token = token.next) {
builder.writeln(token);
}

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

var generics = classElement.typeParameters
.map((e) => '\$${e.name}')
.join(', ');
var generics =
classElement.typeParameters.map((e) => '\$${e.name}').join(', ');
if (generics.isNotEmpty) {
generics = '<$generics>';
}
Expand All @@ -80,9 +77,8 @@ extension ConstructorX on ConstructorDeclaration {
// ignore: deprecated_member_use, latest analyzer with enclosingElement3 not available in stable channel
final classElement = declaredElement!.enclosingElement3;

var generics = classElement.typeParameters
.map((e) => '\$${e.name}')
.join(', ');
var generics =
classElement.typeParameters.map((e) => '\$${e.name}').join(', ');
if (generics.isNotEmpty) {
generics = '<$generics>';
}
Expand Down
68 changes: 31 additions & 37 deletions packages/freezed/lib/src/freezed_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class FreezedGenerator extends ParserGenerator<Freezed> {
if (deepCopyProperty == null || commonGetter == null) continue;

yield deepCopyProperty.copyWith(
nullable:
deepCopyProperty.nullable ||
nullable: deepCopyProperty.nullable ||
commonProperty.isNullable ||
commonGetter.isNullable,
);
Expand Down Expand Up @@ -83,23 +82,21 @@ class FreezedGenerator extends ParserGenerator<Freezed> {
Iterable<Object> _generateForData(Library globalData, Class data) sync* {
if (data.options.fromJson) yield FromJson(data);

final commonCopyWith =
data.options.annotation.copyWith ?? true
? CopyWith(
parents: data.parents,
clonedClassName: data.name,
readableProperties: data.properties.readableProperties,
cloneableProperties: data.properties.cloneableProperties,
deepCloneableProperties:
_getCommonDeepCloneableProperties(
data.constructors,
data.properties,
).toList(),
genericsDefinition: data.genericsDefinitionTemplate,
genericsParameter: data.genericsParameterTemplate,
data: data,
)
: null;
final commonCopyWith = data.options.annotation.copyWith ?? true
? CopyWith(
parents: data.parents,
clonedClassName: data.name,
readableProperties: data.properties.readableProperties,
cloneableProperties: data.properties.cloneableProperties,
deepCloneableProperties: _getCommonDeepCloneableProperties(
data.constructors,
data.properties,
).toList(),
genericsDefinition: data.genericsDefinitionTemplate,
genericsParameter: data.genericsParameterTemplate,
data: data,
)
: null;

yield Abstract(
data: data,
Expand All @@ -114,24 +111,21 @@ class FreezedGenerator extends ParserGenerator<Freezed> {
constructor: constructor,
commonProperties: data.properties.readableProperties,
globalData: globalData,
copyWith:
data.options.annotation.copyWith ??
constructor.parameters.allParameters.isNotEmpty
? CopyWith(
parents: {},
clonedClassName: constructor.redirectedName,
cloneableProperties: constructor.properties.toList(),
readableProperties:
constructor.properties
.where((e) => e.isSynthetic)
.toList(),
deepCloneableProperties: constructor.deepCloneableProperties,
genericsDefinition: data.genericsDefinitionTemplate,
genericsParameter: data.genericsParameterTemplate,
data: data,
parent: commonCopyWith,
)
: null,
copyWith: data.options.annotation.copyWith ??
constructor.parameters.allParameters.isNotEmpty
? CopyWith(
parents: {},
clonedClassName: constructor.redirectedName,
cloneableProperties: constructor.properties.toList(),
readableProperties:
constructor.properties.where((e) => e.isSynthetic).toList(),
deepCloneableProperties: constructor.deepCloneableProperties,
genericsDefinition: data.genericsDefinitionTemplate,
genericsParameter: data.genericsParameterTemplate,
data: data,
parent: commonCopyWith,
)
: null,
);
}
}
Expand Down
Loading