-
Notifications
You must be signed in to change notification settings - Fork 34
[interop] Add Support for Anonymous Declarations #434
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
base: main
Are you sure you want to change the base?
Changes from all commits
1c76d12
d79c2cf
38b3aab
cb90943
37e0d1a
0b943e7
e7535a4
c49ce6c
f1a9e1c
7f0a2e0
f57165c
49aa015
574250f
283ab5d
4a9bca6
78a535f
5421359
f92ffc9
9944b7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import 'base.dart'; | |
|
||
/// A built in type supported by `dart:js_interop` or by this library | ||
/// (with generated declarations) | ||
class BuiltinType extends Type { | ||
class BuiltinType extends NamedType { | ||
@override | ||
final String name; | ||
|
||
|
@@ -21,15 +21,15 @@ class BuiltinType extends Type { | |
/// Whether the given type is present in "dart:js_interop" | ||
final bool fromDartJSInterop; | ||
|
||
// TODO(nikeokoronkwo): Types in general should have an `isNullable` | ||
// property on them to indicate nullability for Dart generated code. | ||
final bool? isNullable; | ||
@override | ||
nikeokoronkwo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bool isNullable; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we not make this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can, but it isn't guaranteed to be set. It is only set if /// isNullable can be null
Type _transformType(TSTypeNode type,
{bool parameter = false, bool typeArg = false, bool? isNullable}) {
// code
} |
||
|
||
BuiltinType( | ||
{required this.name, | ||
this.typeParams = const [], | ||
this.fromDartJSInterop = false, | ||
this.isNullable}); | ||
bool? isNullable}) | ||
: isNullable = isNullable ?? false; | ||
|
||
@override | ||
ID get id => ID(type: 'type', name: name); | ||
|
@@ -39,16 +39,14 @@ class BuiltinType extends Type { | |
|
||
@override | ||
Reference emit([TypeOptions? options]) { | ||
options ??= TypeOptions(); | ||
|
||
return TypeReference((t) => t | ||
..symbol = name | ||
..types.addAll(typeParams | ||
// if there is only one type param, and it is void, ignore | ||
.where((p) => typeParams.length != 1 || p != $voidType) | ||
.map((p) => p.emit(TypeOptions()))) | ||
.map((p) => p.emit(options))) | ||
..url = fromDartJSInterop ? 'dart:js_interop' : null | ||
..isNullable = isNullable ?? options!.nullable); | ||
..isNullable = isNullable || (options?.nullable ?? false)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In theory, |
||
} | ||
|
||
static final BuiltinType $voidType = BuiltinType(name: 'void'); | ||
|
@@ -81,7 +79,10 @@ class BuiltinType extends Type { | |
name: 'JSString', fromDartJSInterop: true, isNullable: isNullable) | ||
: BuiltinType(name: 'String', isNullable: isNullable), | ||
PrimitiveType.$void || PrimitiveType.undefined => $voidType, | ||
PrimitiveType.any || PrimitiveType.unknown => anyType, | ||
PrimitiveType.any => (isNullable ?? false) | ||
? anyType | ||
: BuiltinType(name: 'JSAny', fromDartJSInterop: true), | ||
PrimitiveType.unknown => anyType, | ||
PrimitiveType.object => BuiltinType( | ||
name: 'JSObject', fromDartJSInterop: true, isNullable: isNullable), | ||
PrimitiveType.symbol => BuiltinType( | ||
|
@@ -128,13 +129,14 @@ class BuiltinType extends Type { | |
} | ||
} | ||
|
||
class PackageWebType extends Type { | ||
class PackageWebType extends NamedType { | ||
@override | ||
final String name; | ||
|
||
final List<Type> typeParams; | ||
|
||
final bool? isNullable; | ||
@override | ||
bool isNullable; | ||
|
||
@override | ||
ID get id => ID(type: 'type', name: name); | ||
|
@@ -143,29 +145,29 @@ class PackageWebType extends Type { | |
String? get dartName => null; | ||
|
||
PackageWebType._( | ||
{required this.name, this.typeParams = const [], this.isNullable}); | ||
{required this.name, | ||
this.typeParams = const [], | ||
this.isNullable = false}); | ||
|
||
@override | ||
Reference emit([TypeOptions? options]) { | ||
options ??= TypeOptions(); | ||
|
||
// TODO: We can make this a shared function as it is called a lot | ||
// between types | ||
return TypeReference((t) => t | ||
..symbol = name | ||
..types.addAll(typeParams | ||
// if there is only one type param, and it is void, ignore | ||
.where((p) => typeParams.length != 1 || p != BuiltinType.$voidType) | ||
.map((p) => p.emit(TypeOptions()))) | ||
.map((p) => p.emit(options))) | ||
..url = 'package:web/web.dart' | ||
..isNullable = isNullable ?? options!.nullable); | ||
..isNullable = isNullable || (options?.nullable ?? false)); | ||
} | ||
|
||
static PackageWebType parse(String name, | ||
{bool? isNullable, List<Type> typeParams = const []}) { | ||
return PackageWebType._( | ||
name: renameMap.containsKey(name) ? renameMap[name]! : name, | ||
isNullable: isNullable, | ||
isNullable: isNullable ?? false, | ||
typeParams: typeParams); | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.