Skip to content
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
6 changes: 3 additions & 3 deletions web_generator/lib/src/ast/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ Type getRepresentationType(TypeDeclaration td) {
}

/// Recursively get the generic types specified in a given type [t]
List<GenericType> getGenericTypes(Type t) {
final types = <(String, Type?)>[];
Set<GenericType> getGenericTypes(Type t) {
final types = <(String, Type?)>{};
switch (t) {
case GenericType():
types.add((t.name, t.constraint));
Expand Down Expand Up @@ -250,7 +250,7 @@ List<GenericType> getGenericTypes(Type t) {

// Types are cloned so that modifications to constraints can happen without
// affecting initial references
return types.map((t) => GenericType(name: t.$1, constraint: t.$2)).toList();
return types.map((t) => GenericType(name: t.$1, constraint: t.$2)).toSet();
}

Type desugarTypeAliases(Type t) {
Expand Down
20 changes: 14 additions & 6 deletions web_generator/lib/src/ast/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,24 @@ sealed class ClosureType extends DeclarationType {
this.typeParameters = const [],
this.parameters = const [],
this.isNullable = false,
}) : declarationName = name;
}) : declarationName = name {
if (typeParameters.isEmpty) {
typeParameters.addAll(getGenericTypes(this).map((t) {
t.constraint ??= BuiltinType.anyType;
return t;
}));
}
}

@override
Reference emit([TypeOptions? options]) {
return TypeReference((t) => t
..symbol = declarationName
..isNullable = options?.nullable ?? isNullable);
..isNullable = options?.nullable ?? isNullable
..types.addAll(typeParameters.map((t) {
final clonedT = GenericType(name: t.name, isNullable: t.isNullable);
return clonedT.emit(options);
})));
}
}

Expand Down Expand Up @@ -388,8 +399,7 @@ class FunctionType extends ClosureType {
name: 'call',
id: const ID(type: 'fun', name: 'call'),
returnType: returnType,
parameters: parameters,
typeParameters: typeParameters)
parameters: parameters)
]);
}

Expand Down Expand Up @@ -445,8 +455,6 @@ class _ConstructorDeclaration extends CallableDeclaration
.addAll(typeParameters.map((t) => t.emit(options?.toTypeOptions())))
..methods.add(Method((m) => m
..name = 'call'
..types
.addAll(typeParameters.map((t) => t.emit(options?.toTypeOptions())))
..returns = returnType.emit(options?.toTypeOptions())
..requiredParameters.addAll(requiredParams)
..optionalParameters.addAll(optionalParams)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extension type const MyEnum._(int _) {

static const MyEnum D = MyEnum._(4);
}
typedef Transformer<T extends _i1.JSAny?> = _AnonymousFunction_5293571<T>;
@_i1.JS()
external _i1.JSFunction copyOfmyEnclosingFunction;
@_i1.JS()
Expand Down Expand Up @@ -112,6 +113,10 @@ extension type AnonymousType_9143117<T extends _i1.JSAny?>._(_i1.JSObject _)

external T value;
}
extension type _AnonymousFunction_5293571<T extends _i1.JSAny?>._(
_i1.JSFunction _) implements _i1.JSFunction {
external ComposedType<T> call(T object);
}
extension type ComposedType<T extends _i1.JSAny?>._(_i1.JSObject _)
implements _i1.JSObject {
external T enclosed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export declare enum MyEnum {
interface ComposedType<T = any> {
enclosed: T;
}
export type Transformer<T> = (object: T) => ComposedType<T>;
export declare let copyOfmyEnclosingFunction: typeof myEnclosingFunction;
export declare const myEnumValue: MyEnum;
export declare const myEnumValue2: typeof MyEnum;
Expand Down