Skip to content

Commit

Permalink
Fix any nullability and refactor typing model
Browse files Browse the repository at this point in the history
Major changes:
1. Fixes an issue where we assume that all JSAnys should be
nullable, whereas all anys should be nullable instead.
2. Changes typing model to go from IDLType to "raw" type, which
is either an IDL declaration type or a dart:js_interop type, to
a Dart type reference. This makes it easier to add generic types
later as well.

Minor changes:
1. Reuses _Type and renames it to _RawType instead of using a
record.
2. Removes unnecessary "isReturn" parameters as undefined can only
appear in a return type per the web IDL spec.
3. JSVoid -> void as it's more readable.
  • Loading branch information
srujzs committed Oct 20, 2023
1 parent d578748 commit 18d1ebd
Show file tree
Hide file tree
Showing 112 changed files with 1,217 additions and 1,203 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 0.3.1-dev

- Updated types to account for union types.
- Fixed issue where all `JSAny`s were treated as nullable.
- Changed `JSVoid` to `void`.

## 0.3.0

Expand Down
2 changes: 1 addition & 1 deletion lib/src/dom/anchors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class XRAnchor implements JSObject {}

extension XRAnchorExtension on XRAnchor {
external JSPromise requestPersistentHandle();
external JSVoid delete();
external void delete();
external XRSpace get anchorSpace;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/dom/angle_instanced_arrays.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ class ANGLE_instanced_arrays implements JSObject {
}

extension ANGLEInstancedArraysExtension on ANGLE_instanced_arrays {
external JSVoid drawArraysInstancedANGLE(
external void drawArraysInstancedANGLE(
GLenum mode,
GLint first,
GLsizei count,
GLsizei primcount,
);
external JSVoid drawElementsInstancedANGLE(
external void drawElementsInstancedANGLE(
GLenum mode,
GLsizei count,
GLenum type,
GLintptr offset,
GLsizei primcount,
);
external JSVoid vertexAttribDivisorANGLE(
external void vertexAttribDivisorANGLE(
GLuint index,
GLuint divisor,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/dom/background_fetch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BackgroundFetchManager implements JSObject {}
extension BackgroundFetchManagerExtension on BackgroundFetchManager {
external JSPromise fetch(
String id,
JSAny? requests, [
JSAny requests, [
BackgroundFetchOptions options,
]);
external JSPromise get(String id);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/dom/clipboard_apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extension ClipboardEventExtension on ClipboardEvent {
@staticInterop
class ClipboardItem implements JSObject {
external factory ClipboardItem(
JSAny? items, [
JSAny items, [
ClipboardItemOptions options,
]);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/dom/compute_pressure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class PressureObserver implements JSObject {

extension PressureObserverExtension on PressureObserver {
external JSPromise observe(PressureSource source);
external JSVoid unobserve(PressureSource source);
external JSVoid disconnect();
external void unobserve(PressureSource source);
external void disconnect();
external JSArray takeRecords();
}

Expand Down
38 changes: 19 additions & 19 deletions lib/src/dom/console.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@ abstract class $Console {}

extension $ConsoleExtension on $Console {
@JS('assert')
external JSVoid assert_(
external void assert_(
JSAny? data, [
bool condition,
]);
external JSVoid clear();
external JSVoid debug(JSAny? data);
external JSVoid error(JSAny? data);
external JSVoid info(JSAny? data);
external JSVoid log(JSAny? data);
external JSVoid table([
external void clear();
external void debug(JSAny? data);
external void error(JSAny? data);
external void info(JSAny? data);
external void log(JSAny? data);
external void table([
JSAny? tabularData,
JSArray properties,
]);
external JSVoid trace(JSAny? data);
external JSVoid warn(JSAny? data);
external JSVoid dir([
external void trace(JSAny? data);
external void warn(JSAny? data);
external void dir([
JSAny? item,
JSObject? options,
]);
external JSVoid dirxml(JSAny? data);
external JSVoid count([String label]);
external JSVoid countReset([String label]);
external JSVoid group(JSAny? data);
external JSVoid groupCollapsed(JSAny? data);
external JSVoid groupEnd();
external JSVoid time([String label]);
external JSVoid timeLog(
external void dirxml(JSAny? data);
external void count([String label]);
external void countReset([String label]);
external void group(JSAny? data);
external void groupCollapsed(JSAny? data);
external void groupEnd();
external void time([String label]);
external void timeLog(
JSAny? data, [
String label,
]);
external JSVoid timeEnd([String label]);
external void timeEnd([String label]);
}
8 changes: 4 additions & 4 deletions lib/src/dom/cookie_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ typedef CookieSameSite = String;
class CookieStore implements EventTarget {}

extension CookieStoreExtension on CookieStore {
external JSPromise get([JSAny? nameOrOptions]);
external JSPromise getAll([JSAny? nameOrOptions]);
external JSPromise get([JSAny nameOrOptions]);
external JSPromise getAll([JSAny nameOrOptions]);
external JSPromise set(
JSAny? nameOrOptions, [
JSAny nameOrOptions, [
String value,
]);
external JSPromise delete(JSAny? nameOrOptions);
external JSPromise delete(JSAny nameOrOptions);
external set onchange(EventHandler value);
external EventHandler get onchange;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/dom/css_animation_worklet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ typedef AnimatorInstanceConstructor = JSFunction;
class AnimationWorkletGlobalScope implements WorkletGlobalScope {}

extension AnimationWorkletGlobalScopeExtension on AnimationWorkletGlobalScope {
external JSVoid registerAnimator(
external void registerAnimator(
String name,
AnimatorInstanceConstructor animatorCtor,
);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/dom/css_animations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ extension CSSKeyframeRuleExtension on CSSKeyframeRule {
class CSSKeyframesRule implements CSSRule {}

extension CSSKeyframesRuleExtension on CSSKeyframesRule {
external JSVoid appendRule(String rule);
external JSVoid deleteRule(String select);
external void appendRule(String rule);
external void deleteRule(String select);
external CSSKeyframeRule? findRule(String select);
external set name(String value);
external String get name;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/dom/css_font_loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extension FontFaceDescriptorsExtension on FontFaceDescriptors {
class FontFace implements JSObject {
external factory FontFace(
String family,
JSAny? source, [
JSAny source, [
FontFaceDescriptors descriptors,
]);
}
Expand Down Expand Up @@ -167,7 +167,7 @@ class FontFaceSet implements EventTarget {
extension FontFaceSetExtension on FontFaceSet {
external FontFaceSet add(FontFace font);
external bool delete(FontFace font);
external JSVoid clear();
external void clear();
external JSPromise load(
String font, [
String text,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/dom/css_fonts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ extension CSSFontFeatureValuesRuleExtension on CSSFontFeatureValuesRule {
class CSSFontFeatureValuesMap implements JSObject {}

extension CSSFontFeatureValuesMapExtension on CSSFontFeatureValuesMap {
external JSVoid set(
external void set(
String featureValueName,
JSAny? values,
JSAny values,
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/dom/css_layout_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef BreakType = String;
class LayoutWorkletGlobalScope implements WorkletGlobalScope {}

extension LayoutWorkletGlobalScopeExtension on LayoutWorkletGlobalScope {
external JSVoid registerLayout(
external void registerLayout(
String name,
VoidFunction layoutCtor,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/dom/css_paint_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'webidl.dart';
class PaintWorkletGlobalScope implements WorkletGlobalScope {}

extension PaintWorkletGlobalScopeExtension on PaintWorkletGlobalScope {
external JSVoid registerPaint(
external void registerPaint(
String name,
VoidFunction paintCtor,
);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/dom/css_parser_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import 'dart:js_interop';

typedef CSSStringSource = JSAny?;
typedef CSSToken = JSAny?;
typedef CSSStringSource = JSAny;
typedef CSSToken = JSAny;

@JS()
@staticInterop
Expand Down
30 changes: 15 additions & 15 deletions lib/src/dom/css_typed_om.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import 'dart:js_interop';

import 'geometry.dart';

typedef CSSUnparsedSegment = JSAny?;
typedef CSSKeywordish = JSAny?;
typedef CSSNumberish = JSAny?;
typedef CSSPerspectiveValue = JSAny?;
typedef CSSColorRGBComp = JSAny?;
typedef CSSColorPercent = JSAny?;
typedef CSSColorNumber = JSAny?;
typedef CSSColorAngle = JSAny?;
typedef CSSUnparsedSegment = JSAny;
typedef CSSKeywordish = JSAny;
typedef CSSNumberish = JSAny;
typedef CSSPerspectiveValue = JSAny;
typedef CSSColorRGBComp = JSAny;
typedef CSSColorPercent = JSAny;
typedef CSSColorNumber = JSAny;
typedef CSSColorAngle = JSAny;
typedef CSSNumericBaseType = String;
typedef CSSMathOperator = String;

Expand Down Expand Up @@ -46,16 +46,16 @@ extension StylePropertyMapReadOnlyExtension on StylePropertyMapReadOnly {
class StylePropertyMap implements StylePropertyMapReadOnly {}

extension StylePropertyMapExtension on StylePropertyMap {
external JSVoid set(
external void set(
String property,
JSAny? values,
JSAny values,
);
external JSVoid append(
external void append(
String property,
JSAny? values,
JSAny values,
);
external JSVoid delete(String property);
external JSVoid clear();
external void delete(String property);
external void clear();
}

@JS('CSSUnparsedValue')
Expand Down Expand Up @@ -300,7 +300,7 @@ extension CSSTranslateExtension on CSSTranslate {
@staticInterop
class CSSRotate implements CSSTransformComponent {
external factory CSSRotate(
JSAny? angleOrX, [
JSAny angleOrX, [
CSSNumberish y,
CSSNumberish z,
CSSNumericValue angle,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/dom/css_view_transitions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef UpdateCallback = JSFunction;
class ViewTransition implements JSObject {}

extension ViewTransitionExtension on ViewTransition {
external JSVoid skipTransition();
external void skipTransition();
external JSPromise get updateCallbackDone;
external JSPromise get ready;
external JSPromise get finished;
Expand Down
22 changes: 11 additions & 11 deletions lib/src/dom/cssom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class MediaList implements JSObject {}

extension MediaListExtension on MediaList {
external String? item(int index);
external JSVoid appendMedium(String medium);
external JSVoid deleteMedium(String medium);
external void appendMedium(String medium);
external void deleteMedium(String medium);
external set mediaText(String value);
external String get mediaText;
external int get length;
Expand Down Expand Up @@ -49,15 +49,15 @@ extension CSSStyleSheetExtension on CSSStyleSheet {
String rule, [
int index,
]);
external JSVoid deleteRule(int index);
external void deleteRule(int index);
external JSPromise replace(String text);
external JSVoid replaceSync(String text);
external void replaceSync(String text);
external int addRule([
String selector,
String style,
int index,
]);
external JSVoid removeRule([int index]);
external void removeRule([int index]);
external CSSRule? get ownerRule;
external CSSRuleList get cssRules;
external CSSRuleList get rules;
Expand All @@ -69,16 +69,16 @@ extension CSSStyleSheetExtension on CSSStyleSheet {
class CSSStyleSheetInit implements JSObject {
external factory CSSStyleSheetInit({
String baseURL,
JSAny? media,
JSAny media,
bool disabled,
});
}

extension CSSStyleSheetInitExtension on CSSStyleSheetInit {
external set baseURL(String value);
external String get baseURL;
external set media(JSAny? value);
external JSAny? get media;
external set media(JSAny value);
external JSAny get media;
external set disabled(bool value);
external bool get disabled;
}
Expand Down Expand Up @@ -167,7 +167,7 @@ extension CSSGroupingRuleExtension on CSSGroupingRule {
String rule, [
int index,
]);
external JSVoid deleteRule(int index);
external void deleteRule(int index);
external CSSRuleList get cssRules;
}

Expand Down Expand Up @@ -207,7 +207,7 @@ extension CSSStyleDeclarationExtension on CSSStyleDeclaration {
external String item(int index);
external String getPropertyValue(String property);
external String getPropertyPriority(String property);
external JSVoid setProperty(
external void setProperty(
String property,
String value, [
String priority,
Expand Down Expand Up @@ -1521,7 +1521,7 @@ extension $CSSExtension on $CSS {
external CSSToken parseValue(String css);
external JSArray parseValueList(String css);
external JSArray parseCommaValueList(String css);
external JSVoid registerProperty(PropertyDefinition definition);
external void registerProperty(PropertyDefinition definition);
external CSSUnitValue number(num value);
external CSSUnitValue percent(num value);
external CSSUnitValue cap(num value);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/dom/cssom_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ extension ScrollToOptionsExtension on ScrollToOptions {
class MediaQueryList implements EventTarget {}

extension MediaQueryListExtension on MediaQueryList {
external JSVoid addListener(EventListener? callback);
external JSVoid removeListener(EventListener? callback);
external void addListener(EventListener? callback);
external void removeListener(EventListener? callback);
external String get media;
external bool get matches;
external set onchange(EventHandler value);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/dom/custom_state_pseudo_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import 'dart:js_interop';
class CustomStateSet implements JSObject {}

extension CustomStateSetExtension on CustomStateSet {
external JSVoid add(String value);
external void add(String value);
}
Loading

0 comments on commit 18d1ebd

Please sign in to comment.