Support non-function type aliases.
Fix #993.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 149d8c9..63249e0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
# 2.0.1
* Support triple-shift `>>>` and `>>>=` operators (#992).
+* Support non-function type aliases (#993).
# 2.0.0
diff --git a/lib/src/dart_formatter.dart b/lib/src/dart_formatter.dart
index d88af89..7f437a9 100644
--- a/lib/src/dart_formatter.dart
+++ b/lib/src/dart_formatter.dart
@@ -88,7 +88,11 @@
// command line.
var featureSet = FeatureSet.fromEnableFlags2(
sdkLanguageVersion: Version(2, 13, 0),
- flags: ['non-nullable', 'generic-metadata', 'triple-shift']);
+ flags: [
+ 'generic-metadata',
+ 'nonfunction-type-aliases',
+ 'triple-shift'
+ ]);
var inputOffset = 0;
var text = source.text;
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index 6a2ccd4..a39e026 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -1819,7 +1819,7 @@
space();
- visit(node.functionType);
+ visit(node.type);
});
}
diff --git a/test/splitting/typedef.unit b/test/splitting/typedef.unit
index aa0760f..e2a89a0 100644
--- a/test/splitting/typedef.unit
+++ b/test/splitting/typedef.unit
@@ -60,4 +60,30 @@
First first,
Second second,
Third third,
- Fourth fourth);
\ No newline at end of file
+ Fourth fourth);
+>>> non-function split type parameters
+typedef G = SomeType<TypeOne, TypeTwo, TypeThree>;
+<<<
+typedef G = SomeType<TypeOne, TypeTwo,
+ TypeThree>;
+>>> non-function split all type parameters
+typedef G = SomeType<TypeOne, TypeTwo, TypeThree, TypeFour, TypeFive, TypeSix>;
+<<<
+typedef G = SomeType<
+ TypeOne,
+ TypeTwo,
+ TypeThree,
+ TypeFour,
+ TypeFive,
+ TypeSix>;
+>>> non-function generic typedef parameters on one line
+typedef Foo<T, S> = SomeType;
+<<<
+typedef Foo<T, S> = SomeType;
+>>> non-function generic typedef parameters that split
+typedef LongGenericType<First, Second, Third, Fourth, Fifth, Sixth> = AnotherType<First, Second, Third, Fourth>;
+<<<
+typedef LongGenericType<First, Second,
+ Third, Fourth, Fifth, Sixth>
+ = AnotherType<First, Second, Third,
+ Fourth>;
\ No newline at end of file
diff --git a/test/whitespace/metadata.unit b/test/whitespace/metadata.unit
index 87ed0b7..37a311a 100644
--- a/test/whitespace/metadata.unit
+++ b/test/whitespace/metadata.unit
@@ -270,6 +270,11 @@
<<<
@foo
typedef Fn = Function();
+>>> metadata on non-function typedef
+@foo typedef Hash< @a K, @b ( 1 ) V > = Map < K , V > ;
+<<<
+@foo
+typedef Hash<@a K, @b(1) V> = Map<K, V>;
>>> single metadata on for-in loop variable
main() {
for ( @a var i in list) {;}
diff --git a/test/whitespace/typedef.unit b/test/whitespace/typedef.unit
index 71d697c..077b05b 100644
--- a/test/whitespace/typedef.unit
+++ b/test/whitespace/typedef.unit
@@ -37,4 +37,16 @@
>>> generic function
typedef Foo =Function < A ,B > ( A a,B b );
<<<
-typedef Foo = Function<A, B>(A a, B b);
\ No newline at end of file
+typedef Foo = Function<A, B>(A a, B b);
+>>>
+typedef Foo = Bar;
+<<<
+typedef Foo = Bar;
+>>> non-function typedef
+typedef Json = Map < String , Object ? > ;
+<<<
+typedef Json = Map<String, Object?>;
+>>> non-function generic typedef
+typedef Hash < K, V > = Map < K , V > ;
+<<<
+typedef Hash<K, V> = Map<K, V>;
\ No newline at end of file