Skip to content

Support non-function type aliases. #1013

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

Merged
merged 2 commits into from
Mar 31, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 2.0.1

* Support triple-shift `>>>` and `>>>=` operators (#992).
* Support non-function type aliases (#993).

# 2.0.0

Expand Down
6 changes: 5 additions & 1 deletion lib/src/dart_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ class DartFormatter {
// 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;
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 @@ -1819,7 +1819,7 @@ class SourceVisitor extends ThrowingAstVisitor {

space();

visit(node.functionType);
visit(node.type);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only real change needed to get this working. :)

});
}

Expand Down
28 changes: 27 additions & 1 deletion test/splitting/typedef.unit
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,30 @@ typedef LongfunctionType<First, Second,
First first,
Second second,
Third third,
Fourth fourth);
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>;
5 changes: 5 additions & 0 deletions test/whitespace/metadata.unit
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ class A {
<<<
@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) {;}
Expand Down
15 changes: 14 additions & 1 deletion test/whitespace/typedef.unit
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,17 @@ typedef Foo<A, B> = Function(A a, B b);
>>> generic function
typedef Foo =Function < A ,B > ( A a,B b );
<<<
typedef Foo = Function<A, B>(A a, B b);
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 extends List < T > , V > = Map < K , V > ;
<<<
typedef Hash<K extends List<T>, V>
= Map<K, V>;