Skip to content

Commit

Permalink
Fix compile error when using dart_style with analyzer 6.2.0. (#1414)
Browse files Browse the repository at this point in the history
Fix #1413.
  • Loading branch information
munificent authored Feb 29, 2024
1 parent 3fcc65f commit c644037
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## 2.3.6-wip
## 2.3.6

There are no user-visible changes in this release. The only changes are behind
the `tall-style` experiment flag.
* Fix compile error when using dart_style with analyzer 6.2.0.

## 2.3.5

Expand Down
22 changes: 22 additions & 0 deletions lib/src/ast_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,25 @@ extension PatternExtensions on DartPattern {
_ => false,
};
}

// TODO(rnystrom): This is a gross hack because dart_style 2.3.5 has a bad
// analyzer constraint which allows dart_style to be used with a version of
// analyzer that doesn't publicly expose the `.macroKeyword` getter.
// Fortunately, the oldest analyzer that dart_style allows *does* have the
// getter on the ClassDeclarationImpl class.
//
// To get users off that bad version, we're publishing a new version of
// dart_style that has the same constraint and gracefully handles that getter
// not statically being visible.
//
// This hack will be removed immediately after publishing a version with that
// fix.
extension ClassDeclarationExtensions on ClassDeclaration {
/// If the [ClassDeclaration] is from a version of analyzer that has the
/// `macroKeyword` getter and the class has a `macro` keyword, returns that
/// token.
///
/// Otherwise, returns `null`.
Token? get hackMacroKeywordForOlderAnalyzer =>
(this as dynamic).macroKeyword as Token?;
}
2 changes: 1 addition & 1 deletion lib/src/cli/formatter_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'show.dart';
import 'summary.dart';

// Note: The following line of code is modified by tool/grind.dart.
const dartStyleVersion = '2.3.5';
const dartStyleVersion = '2.3.6';

/// Global options that affect how the formatter produces and uses its outputs.
class FormatterOptions {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/front_end/ast_node_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
node.interfaceKeyword,
node.finalKeyword,
node.sealedKeyword,
node.macroKeyword,
node.hackMacroKeywordForOlderAnalyzer,
node.mixinKeyword,
node.classKeyword,
],
Expand Down
2 changes: 1 addition & 1 deletion lib/src/source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ class SourceVisitor extends ThrowingAstVisitor {
modifier(node.finalKeyword);
modifier(node.sealedKeyword);
modifier(node.mixinKeyword);
modifier(node.macroKeyword);
modifier(node.hackMacroKeywordForOlderAnalyzer);
token(node.classKeyword);
space();
token(node.name);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dart_style
# Note: See tool/grind.dart for how to bump the version.
version: 2.3.6-wip
version: 2.3.6
description: >-
Opinionated, automatic Dart source code formatter.
Provides an API and a CLI tool.
Expand Down

0 comments on commit c644037

Please sign in to comment.