Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a factory constructor with metadata before it to split. #1580

Merged
merged 1 commit into from
Oct 15, 2024
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
66 changes: 34 additions & 32 deletions lib/src/front_end/ast_node_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -407,43 +407,45 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {

@override
void visitConstructorDeclaration(ConstructorDeclaration node) {
var header = pieces.build(metadata: node.metadata, () {
pieces.modifier(node.externalKeyword);
pieces.modifier(node.constKeyword);
pieces.modifier(node.factoryKeyword);
pieces.visit(node.returnType);
pieces.token(node.period);
pieces.token(node.name);
});
pieces.withMetadata(node.metadata, () {
var header = pieces.build(() {
pieces.modifier(node.externalKeyword);
pieces.modifier(node.constKeyword);
pieces.modifier(node.factoryKeyword);
pieces.visit(node.returnType);
pieces.token(node.period);
pieces.token(node.name);
});

var parameters = nodePiece(node.parameters);
var parameters = nodePiece(node.parameters);

Piece? redirect;
Piece? initializerSeparator;
Piece? initializers;
if (node.redirectedConstructor case var constructor?) {
var separator = pieces.build(() {
pieces.token(node.separator);
pieces.space();
});
Piece? redirect;
Piece? initializerSeparator;
Piece? initializers;
if (node.redirectedConstructor case var constructor?) {
var separator = pieces.build(() {
pieces.token(node.separator);
pieces.space();
});

redirect = AssignPiece(
separator, nodePiece(constructor, context: NodeContext.assignment),
canBlockSplitRight: false);
} else if (node.initializers.isNotEmpty) {
initializerSeparator = tokenPiece(node.separator!);
initializers = createCommaSeparated(node.initializers);
}
redirect = AssignPiece(
separator, nodePiece(constructor, context: NodeContext.assignment),
canBlockSplitRight: false);
} else if (node.initializers.isNotEmpty) {
initializerSeparator = tokenPiece(node.separator!);
initializers = createCommaSeparated(node.initializers);
}

var body = nodePiece(node.body);
var body = nodePiece(node.body);

pieces.add(ConstructorPiece(header, parameters, body,
canSplitParameters: node.parameters.parameters
.canSplit(node.parameters.rightParenthesis),
hasOptionalParameter: node.parameters.rightDelimiter != null,
redirect: redirect,
initializerSeparator: initializerSeparator,
initializers: initializers));
pieces.add(ConstructorPiece(header, parameters, body,
canSplitParameters: node.parameters.parameters
.canSplit(node.parameters.rightParenthesis),
hasOptionalParameter: node.parameters.rightDelimiter != null,
redirect: redirect,
initializerSeparator: initializerSeparator,
initializers: initializers));
});
}

@override
Expand Down
11 changes: 11 additions & 0 deletions test/tall/regression/other/dart.unit
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,15 @@ class Benchmark {
// A rate of one run per 2s, with a millisecond of noise. Some variation is
// needed for Golem's noise-based filtering and regression detection.
double measure() => (2000 + Random().nextDouble() - 0.5) * 1000;
}
>>>
class Uint8ClampedList {
@patch
factory Uint8ClampedList.fromList(List<int> elements) = NativeUint8ClampedList.fromList;
}
<<<
class Uint8ClampedList {
@patch
factory Uint8ClampedList.fromList(List<int> elements) =
NativeUint8ClampedList.fromList;
}