diff --git a/CHANGELOG.md b/CHANGELOG.md index c65fcd59..d1854edd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ on other parameters (#1212). * Don't split before `.` following a record literal (#1213). * Don't force split on a line comment before a switch expression case (#1215). +* Require `package:analyzer` `^5.12.0`. # 2.3.1 diff --git a/lib/src/dart_formatter.dart b/lib/src/dart_formatter.dart index 30ea1064..bb32bd58 100644 --- a/lib/src/dart_formatter.dart +++ b/lib/src/dart_formatter.dart @@ -153,13 +153,13 @@ class DartFormatter { var token = node.endToken.next!; if (token.type != TokenType.CLOSE_CURLY_BRACKET) { var stringSource = StringSource(text, source.uri); - var error = AnalysisError( - stringSource, - token.offset - inputOffset, - math.max(token.length, 1), - ParserErrorCode.UNEXPECTED_TOKEN, - [token.lexeme]); - + var error = AnalysisError.tmp( + source: stringSource, + offset: token.offset - inputOffset, + length: math.max(token.length, 1), + errorCode: ParserErrorCode.UNEXPECTED_TOKEN, + arguments: [token.lexeme], + ); throw FormatterException([error]); } } diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart index 589c245a..fefaae18 100644 --- a/lib/src/source_visitor.dart +++ b/lib/src/source_visitor.dart @@ -1813,7 +1813,7 @@ class SourceVisitor extends ThrowingAstVisitor { var hasInnerControlFlow = false; for (var element in ifElements) { _visitIfCondition(element.ifKeyword, element.leftParenthesis, - element.condition, element.caseClause, element.rightParenthesis); + element.expression, element.caseClause, element.rightParenthesis); visitChild(element, element.thenElement); if (element.thenElement.isControlFlowElement) { @@ -1856,7 +1856,7 @@ class SourceVisitor extends ThrowingAstVisitor { @override void visitIfStatement(IfStatement node) { - _visitIfCondition(node.ifKeyword, node.leftParenthesis, node.condition, + _visitIfCondition(node.ifKeyword, node.leftParenthesis, node.expression, node.caseClause, node.rightParenthesis); void visitClause(Statement clause) { @@ -2252,9 +2252,22 @@ class SourceVisitor extends ThrowingAstVisitor { @override void visitNamedType(NamedType node) { - visit(node.name); + var importPrefix = node.importPrefix; + if (importPrefix != null) { + builder.startSpan(); + + token(importPrefix.name); + soloZeroSplit(); + token(importPrefix.period); + } + + token(node.name2); visit(node.typeArguments); token(node.question); + + if (importPrefix != null) { + builder.endSpan(); + } } @override diff --git a/pubspec.yaml b/pubspec.yaml index d9528532..0725ca93 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,7 @@ environment: sdk: ">=2.19.0 <3.0.0" dependencies: - analyzer: ^5.7.0 + analyzer: ^5.12.0 args: ">=1.0.0 <3.0.0" path: ^1.0.0 pub_semver: ">=1.4.4 <3.0.0"