Skip to content

Commit c9975c6

Browse files
authored
Require analyzer ^13.0.0, with breaking changes. (#1821)
* Require analyzer ^13.0.0, with breaking changes. * Update comment on writeTokenAssignment() * Remove unnecessary type arguments.
1 parent 4b77cd8 commit c9975c6

11 files changed

Lines changed: 257 additions & 187 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.1.9
2+
3+
* Require `analyzer: ^13.0.0`.
4+
15
## 3.1.8
26

37
### Style changes

lib/src/ast_extensions.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ extension AstNodeExtensions on AstNode {
1212
BlockFormat get blockFormatType => switch (this) {
1313
AdjacentStrings(indentStrings: true) => BlockFormat.indentedAdjacentStrings,
1414
AdjacentStrings() => BlockFormat.unindentedAdjacentStrings,
15+
NamedArgument(:var argumentExpression) =>
16+
argumentExpression.blockFormatType,
1517
Expression(:var blockFormatType) => blockFormatType,
1618
_ => BlockFormat.none,
1719
};
@@ -30,9 +32,6 @@ extension AstNodeExtensions on AstNode {
3032
AnnotatedNode(metadata: [var annotation, ...]) => annotation.beginToken,
3133
AnnotatedNode(firstTokenAfterCommentAndMetadata: var token) => token,
3234

33-
// The inner [NormalFormalParameter] is an [AnnotatedNode].
34-
DefaultFormalParameter(:var parameter) => parameter.firstNonCommentToken,
35-
3635
// The inner [PatternVariableDeclaration] is an [AnnotatedNode].
3736
PatternVariableDeclarationStatement(:var declaration) =>
3837
declaration.firstNonCommentToken,
@@ -214,9 +213,6 @@ extension ExpressionExtensions on Expression {
214213
/// category it belongs to.
215214
BlockFormat get blockFormatType {
216215
return switch (this) {
217-
// Unwrap named expressions to get the real expression inside.
218-
NamedExpression(:var expression) => expression.blockFormatType,
219-
220216
// Allow the target of a single-section cascade to be block formatted.
221217
CascadeExpression(:var target, :var cascadeSections)
222218
when cascadeSections.length == 1 && target.canBlockSplit =>
@@ -276,7 +272,7 @@ extension ExpressionExtensions on Expression {
276272
/// Whether this is an argument in an argument list with a trailing comma.
277273
bool get isTrailingCommaArgument {
278274
var parent = this.parent;
279-
if (parent is NamedExpression) parent = parent.parent;
275+
if (parent is NamedArgument) parent = parent.parent;
280276

281277
return parent is ArgumentList && parent.arguments.hasCommaAfter;
282278
}
@@ -479,15 +475,16 @@ extension AdjacentStringsExtensions on AdjacentStrings {
479475

480476
// Don't indent when following `:`.
481477
MapLiteralEntry(:var value) when value == this => false,
482-
NamedExpression() => false,
478+
NamedArgument() => false,
479+
RecordLiteralNamedField() => false,
483480

484481
// Don't indent when the body of a `=>` function.
485482
ExpressionFunctionBody() => false,
486483
_ => true,
487484
};
488485
}
489486

490-
bool _hasOtherStringArgument(List<Expression> arguments) => arguments.any(
487+
bool _hasOtherStringArgument(Iterable<Argument> arguments) => arguments.any(
491488
(argument) => argument != this && argument is StringLiteral,
492489
);
493490
}

lib/src/cli/formatter_options.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'show.dart';
1313
import 'summary.dart';
1414

1515
// Note: The following line of code is modified by tool/grind.dart.
16-
const dartStyleVersion = '3.1.8';
16+
const dartStyleVersion = '3.1.9';
1717

1818
/// Global options parsed from the command line that affect how the formatter
1919
/// produces and uses its outputs.

lib/src/front_end/ast_node_visitor.dart

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -577,13 +577,6 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
577577
writePatternVariable(node.keyword, node.type, node.name);
578578
}
579579

580-
@override
581-
void visitDefaultFormalParameter(DefaultFormalParameter node) {
582-
// Visit the inner parameter. It will then access its parent to extract the
583-
// default value.
584-
pieces.visit(node.parameter);
585-
}
586-
587580
@override
588581
void visitDoStatement(DoStatement node) {
589582
pieces.token(node.doKeyword);
@@ -772,7 +765,7 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
772765

773766
@override
774767
void visitFieldFormalParameter(FieldFormalParameter node) {
775-
if (node.parameters case var parameters?) {
768+
if (node.functionTypedSuffix case var functionTypedSuffix?) {
776769
// A function-typed field formal like:
777770
//
778771
// C(this.fn(parameter));
@@ -781,15 +774,15 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
781774
fieldKeyword: node.thisKeyword,
782775
period: node.period,
783776
node.name,
784-
node.typeParameters,
785-
parameters,
786-
node.question,
777+
functionTypedSuffix.typeParameters,
778+
functionTypedSuffix.formalParameters,
779+
functionTypedSuffix.question,
787780
parameter: node,
788781
);
789782
} else {
790783
writeFormalParameter(
791784
node,
792-
mutableKeyword: node.keyword,
785+
mutableKeyword: node.constFinalOrVarKeyword,
793786
fieldKeyword: node.thisKeyword,
794787
period: node.period,
795788
node.type,
@@ -802,7 +795,7 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
802795
void visitFormalParameterList(FormalParameterList node) {
803796
// Find the first non-mandatory parameter (if there are any).
804797
var firstOptional = node.parameters.indexWhere(
805-
(p) => p is DefaultFormalParameter,
798+
(p) => p.isNamed || p.isOptionalPositional,
806799
);
807800

808801
// If the parameter list is completely empty, write the brackets inline so
@@ -961,18 +954,6 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
961954
});
962955
}
963956

964-
@override
965-
void visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
966-
writeFunctionType(
967-
parameter: node,
968-
node.returnType,
969-
node.name,
970-
node.typeParameters,
971-
node.parameters,
972-
node.question,
973-
);
974-
}
975-
976957
@override
977958
void visitGenericFunctionType(GenericFunctionType node) {
978959
writeFunctionType(
@@ -1290,10 +1271,15 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
12901271

12911272
@override
12921273
void visitLabel(Label node) {
1293-
pieces.visit(node.label);
1274+
pieces.token(node.name);
12941275
pieces.token(node.colon);
12951276
}
12961277

1278+
@override
1279+
void visitLabelReference(LabelReference node) {
1280+
pieces.token(node.name);
1281+
}
1282+
12971283
@override
12981284
void visitLabeledStatement(LabeledStatement node) {
12991285
var sequence = SequenceBuilder(this);
@@ -1490,11 +1476,11 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
14901476
}
14911477

14921478
@override
1493-
void visitNamedExpression(NamedExpression node) {
1494-
writeAssignment(
1495-
node.name.label,
1496-
node.name.colon,
1497-
node.expression,
1479+
void visitNamedArgument(NamedArgument node) {
1480+
writeTokenAssignment(
1481+
node.name,
1482+
node.colon,
1483+
node.argumentExpression,
14981484
rightHandSideContext: NodeContext.namedExpression,
14991485
);
15001486
}
@@ -1750,6 +1736,16 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
17501736
);
17511737
}
17521738

1739+
@override
1740+
void visitRecordLiteralNamedField(RecordLiteralNamedField node) {
1741+
writeTokenAssignment(
1742+
node.name,
1743+
node.colon,
1744+
node.fieldExpression,
1745+
rightHandSideContext: NodeContext.namedExpression,
1746+
);
1747+
}
1748+
17531749
@override
17541750
void visitRecordPattern(RecordPattern node) {
17551751
writeRecord(node.leftParenthesis, node.fields, node.rightParenthesis);
@@ -1872,13 +1868,24 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
18721868
}
18731869

18741870
@override
1875-
void visitSimpleFormalParameter(SimpleFormalParameter node) {
1876-
writeFormalParameter(
1877-
node,
1878-
node.type,
1879-
node.name,
1880-
mutableKeyword: node.keyword,
1881-
);
1871+
void visitRegularFormalParameter(RegularFormalParameter node) {
1872+
if (node.functionTypedSuffix case var functionTypedSuffix?) {
1873+
writeFunctionType(
1874+
node.type,
1875+
node.name!,
1876+
functionTypedSuffix.typeParameters,
1877+
functionTypedSuffix.formalParameters,
1878+
functionTypedSuffix.question,
1879+
parameter: node,
1880+
);
1881+
} else {
1882+
writeFormalParameter(
1883+
node,
1884+
node.type,
1885+
node.name,
1886+
mutableKeyword: node.constFinalOrVarKeyword,
1887+
);
1888+
}
18821889
}
18831890

18841891
@override
@@ -1927,7 +1934,7 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
19271934

19281935
@override
19291936
void visitSuperFormalParameter(SuperFormalParameter node) {
1930-
if (node.parameters case var parameters?) {
1937+
if (node.functionTypedSuffix case var functionTypedSuffix?) {
19311938
// A function-typed super parameter like:
19321939
//
19331940
// C(super.fn(parameter));
@@ -1936,15 +1943,15 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
19361943
fieldKeyword: node.superKeyword,
19371944
period: node.period,
19381945
node.name,
1939-
node.typeParameters,
1940-
parameters,
1941-
node.question,
1946+
functionTypedSuffix.typeParameters,
1947+
functionTypedSuffix.formalParameters,
1948+
functionTypedSuffix.question,
19421949
parameter: node,
19431950
);
19441951
} else {
19451952
writeFormalParameter(
19461953
node,
1947-
mutableKeyword: node.keyword,
1954+
mutableKeyword: node.constFinalOrVarKeyword,
19481955
fieldKeyword: node.superKeyword,
19491956
period: node.period,
19501957
node.type,

lib/src/front_end/delimited_list_builder.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ final class DelimitedListBuilder {
492492
if (candidateIndex == -1) return;
493493

494494
// The block argument must be positional.
495-
if (arguments[candidateIndex] is NamedExpression) return;
495+
if (arguments[candidateIndex] is NamedArgument) return;
496496

497497
// Only allow up to one trailing argument after the block argument. This
498498
// handles the common `tags` and `timeout` named arguments in `test()` and
@@ -514,7 +514,7 @@ final class DelimitedListBuilder {
514514
// });
515515
if (candidateIndex == 1 &&
516516
arguments[1].blockFormatType == BlockFormat.function &&
517-
arguments[0] is! NamedExpression) {
517+
arguments[0] is! NamedArgument) {
518518
var firstArgumentFormatType = arguments[0].blockFormatType;
519519
if (firstArgumentFormatType
520520
case BlockFormat.unindentedAdjacentStrings ||

lib/src/front_end/expression_contents.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ class ExpressionContents {
4949
final List<_Contents> _stack = [_Contents(_Type.otherCall)];
5050

5151
/// Begins tracking an argument list.
52-
void beginCall(List<AstNode> arguments) {
52+
void beginCall(List<Argument> arguments) {
5353
var type = _Type.otherCall;
5454

5555
// Count the non-trivial named arguments in this call.
5656
var namedArguments = 0;
5757
for (var argument in arguments) {
58-
if (argument is NamedExpression) {
58+
if (argument is NamedArgument) {
5959
type = _Type.callWithNamedArgument;
60-
if (!_isTrivial(argument.expression)) namedArguments++;
60+
if (!_isTrivial(argument.argumentExpression)) namedArguments++;
6161
}
6262
}
6363

@@ -66,7 +66,7 @@ class ExpressionContents {
6666

6767
/// Ends the most recently begun call and returns `true` if its argument list
6868
/// should eagerly split.
69-
bool endCall(List<Expression> arguments) {
69+
bool endCall(List<Argument> arguments) {
7070
var contents = _end();
7171

7272
// If there are "too many" named arguments in this call and the calls it

0 commit comments

Comments
 (0)