Skip to content

Commit f3e59ed

Browse files
authored
Include nullability information for typedefs (#79)
These types were declared using the type name, but without its associated nullability.
1 parent d733f2e commit f3e59ed

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.2.3-wip
2+
3+
- Fixed a bug where `typedef`s were not declared with the IDL type's
4+
nullability.
5+
16
## 0.2.2-beta
27

38
- Updates SDK version minimum to 3.2.0-194.0.dev.

lib/src/dom/html.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ typedef RenderingContext = JSAny?;
8787
typedef HTMLOrSVGImageElement = JSAny?;
8888
typedef CanvasImageSource = JSAny?;
8989
typedef OffscreenRenderingContext = JSAny?;
90-
typedef EventHandler = EventHandlerNonNull;
91-
typedef OnErrorEventHandler = OnErrorEventHandlerNonNull;
92-
typedef OnBeforeUnloadEventHandler = OnBeforeUnloadEventHandlerNonNull;
90+
typedef EventHandler = EventHandlerNonNull?;
91+
typedef OnErrorEventHandler = OnErrorEventHandlerNonNull?;
92+
typedef OnBeforeUnloadEventHandler = OnBeforeUnloadEventHandlerNonNull?;
9393
typedef TimerHandler = JSAny?;
9494
typedef ImageBitmapSource = JSAny?;
9595
typedef MessageEventSource = JSAny?;

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: web
22
description: >-
33
Lightweight DOM and JS bindings built around JS static interop.
4-
version: 0.2.2-beta
4+
version: 0.2.3-wip
55

66
repository: https://github.com/dart-lang/web
77

tool/bindings_generator/translator.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,10 @@ class Translator {
346346
}
347347
}
348348

349-
code.TypeDef _typedef(String name, String type) => code.TypeDef((b) => b
350-
..name = name
351-
..definition = _typeReference(type));
349+
code.TypeDef _typedef(String name, String type, bool nullable) =>
350+
code.TypeDef((b) => b
351+
..name = name
352+
..definition = _typeReference(type, isNullable: nullable));
352353

353354
code.Method _topLevelGetter(String dartName, String getterName) =>
354355
code.Method((b) => b
@@ -674,17 +675,19 @@ class Translator {
674675
..comments.addAll(licenseHeader)
675676
..body.addAll([
676677
for (final typedef in library.typedefs)
677-
_typedef(typedef.name.toDart, _typeRaw(typedef.idlType)),
678+
_typedef(typedef.name.toDart, _typeRaw(typedef.idlType),
679+
typedef.idlType.nullable.toDart),
678680
// TODO(joshualitt): We should lower callbacks and callback interfaces to
679681
// a Dart function that takes a typed Dart function, and returns an
680682
// JSFunction.
681683
for (final callback in library.callbacks)
682-
_typedef(callback.name.toDart, 'JSFunction'),
684+
_typedef(callback.name.toDart, 'JSFunction', false),
683685
for (final callbackInterface in library.callbackInterfaces)
684-
_typedef(callbackInterface.name.toDart, 'JSFunction'),
686+
_typedef(callbackInterface.name.toDart, 'JSFunction', false),
685687
// TODO(joshualitt): Enums in the WebIDL are just strings, but we could
686688
// make them easier to work with on the Dart side.
687-
for (final enum_ in library.enums) _typedef(enum_.name.toDart, 'String'),
689+
for (final enum_ in library.enums)
690+
_typedef(enum_.name.toDart, 'String', false),
688691
for (final interfacelike in library.interfacelikes)
689692
..._interfacelike(interfacelike),
690693
]));

0 commit comments

Comments
 (0)