From 9999b5774b88addfe4f3dc6d1a3c8fae36630ebf Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 15:53:11 +0200 Subject: [PATCH 01/21] #1092@patch: Makes PointerEvent implementation more specification compliant. https://w3c.github.io/pointerevents/#dom-pointerevent-constructor. --- .../src/event/events/IPointerEventInit.ts | 5 +++ .../src/event/events/PointerEvent.ts | 41 +++++++++++-------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/packages/happy-dom/src/event/events/IPointerEventInit.ts b/packages/happy-dom/src/event/events/IPointerEventInit.ts index 1ec9a1684..145da4f19 100644 --- a/packages/happy-dom/src/event/events/IPointerEventInit.ts +++ b/packages/happy-dom/src/event/events/IPointerEventInit.ts @@ -1,4 +1,5 @@ import IMouseEventInit from './IMouseEventInit.js'; +import PointerEvent from './PointerEvent.js'; export default interface IPointerEventInit extends IMouseEventInit { pointerId?: number; @@ -9,6 +10,10 @@ export default interface IPointerEventInit extends IMouseEventInit { tiltX?: number; tiltY?: number; twist?: number; + altitudeAngle?: number; + azimuthAngle?: number; pointerType?: string; isPrimary?: boolean; + coalescedEvents?: PointerEvent[]; + predictedEvents?: PointerEvent[]; } diff --git a/packages/happy-dom/src/event/events/PointerEvent.ts b/packages/happy-dom/src/event/events/PointerEvent.ts index bd0cc4ae0..99f86c210 100644 --- a/packages/happy-dom/src/event/events/PointerEvent.ts +++ b/packages/happy-dom/src/event/events/PointerEvent.ts @@ -6,15 +6,19 @@ import IPointerEventInit from './IPointerEventInit.js'; */ export default class PointerEvent extends MouseEvent { public readonly pointerId: number = 0; - public readonly width: number = 0; - public readonly height: number = 0; + public readonly width: number = 1; + public readonly height: number = 1; public readonly pressure: number = 0; public readonly tangentialPressure: number = 0; public readonly tiltX: number = 0; public readonly tiltY: number = 0; public readonly twist: number = 0; + public readonly altitudeAngle: number = 0; + public readonly azimuthAngle: number = 0; public readonly pointerType: string = ''; public readonly isPrimary: boolean = false; + public readonly coalescedEvents: PointerEvent[] = []; + public readonly predictedEvents: PointerEvent[] = []; /** * Constructor. @@ -22,21 +26,26 @@ export default class PointerEvent extends MouseEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IPointerEventInit = null) { + constructor(type: string, eventInit: IPointerEventInit = {}) { super(type, eventInit); - if (eventInit) { - this.pointerId = eventInit.pointerId !== undefined ? eventInit.pointerId : 0; - this.width = eventInit.width !== undefined ? eventInit.width : 0; - this.height = eventInit.height !== undefined ? eventInit.height : 0; - this.pressure = eventInit.pressure !== undefined ? eventInit.pressure : 0; - this.tangentialPressure = - eventInit.tangentialPressure !== undefined ? eventInit.tangentialPressure : 0; - this.tiltX = eventInit.tiltX !== undefined ? eventInit.tiltX : 0; - this.tiltY = eventInit.tiltY !== undefined ? eventInit.tiltY : 0; - this.twist = eventInit.twist !== undefined ? eventInit.twist : 0; - this.pointerType = eventInit.pointerType !== undefined ? eventInit.pointerType : ''; - this.isPrimary = eventInit.isPrimary || eventInit.isPrimary; - } + this.pointerId = eventInit.pointerId ?? 0; + this.width = eventInit.width ?? 1; + this.height = eventInit.height ?? 1; + this.pressure = eventInit.pressure ?? 0; + this.tangentialPressure = eventInit.tangentialPressure ?? 0; + this.tiltX = eventInit.tiltX ?? 0; + this.tiltY = eventInit.tiltY ?? 0; + this.twist = eventInit.twist ?? 0; + this.altitudeAngle = eventInit.altitudeAngle ?? 0; + this.azimuthAngle = eventInit.azimuthAngle ?? 0; + this.pointerType = eventInit.pointerType ?? ''; + this.isPrimary = eventInit.isPrimary ?? false; + this.coalescedEvents = eventInit.coalescedEvents ?? []; + this.predictedEvents = eventInit.predictedEvents ?? []; } + + public getCoalescedEvents = (): PointerEvent[] => this.coalescedEvents; + + public getPredictedEvents = (): PointerEvent[] => this.predictedEvents; } From 9e6452c71207fcfed83a8c03ef0a69b6dc711385 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 16:16:09 +0200 Subject: [PATCH 02/21] #1092@patch: No need to initialize properties, already done inside the constructor. --- .../src/event/events/PointerEvent.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/happy-dom/src/event/events/PointerEvent.ts b/packages/happy-dom/src/event/events/PointerEvent.ts index 99f86c210..e41a7ee35 100644 --- a/packages/happy-dom/src/event/events/PointerEvent.ts +++ b/packages/happy-dom/src/event/events/PointerEvent.ts @@ -5,20 +5,20 @@ import IPointerEventInit from './IPointerEventInit.js'; * */ export default class PointerEvent extends MouseEvent { - public readonly pointerId: number = 0; - public readonly width: number = 1; - public readonly height: number = 1; - public readonly pressure: number = 0; - public readonly tangentialPressure: number = 0; - public readonly tiltX: number = 0; - public readonly tiltY: number = 0; - public readonly twist: number = 0; - public readonly altitudeAngle: number = 0; - public readonly azimuthAngle: number = 0; - public readonly pointerType: string = ''; - public readonly isPrimary: boolean = false; - public readonly coalescedEvents: PointerEvent[] = []; - public readonly predictedEvents: PointerEvent[] = []; + public readonly pointerId: number; + public readonly width: number; + public readonly height: number; + public readonly pressure: number; + public readonly tangentialPressure: number; + public readonly tiltX: number; + public readonly tiltY: number; + public readonly twist: number; + public readonly altitudeAngle: number; + public readonly azimuthAngle: number; + public readonly pointerType: string; + public readonly isPrimary: boolean; + public readonly coalescedEvents: PointerEvent[]; + public readonly predictedEvents: PointerEvent[]; /** * Constructor. From 78cc9e7ba7eb9f0f3ca7858b41d734038d3f4e0d Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 16:45:24 +0200 Subject: [PATCH 03/21] #1092@patch: Simplifies AnimationEvent. https://drafts.csswg.org/css-animations/#interface-animationevent. --- .../happy-dom/src/event/events/AnimationEvent.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/happy-dom/src/event/events/AnimationEvent.ts b/packages/happy-dom/src/event/events/AnimationEvent.ts index 771dc1fd1..12477c9e2 100644 --- a/packages/happy-dom/src/event/events/AnimationEvent.ts +++ b/packages/happy-dom/src/event/events/AnimationEvent.ts @@ -5,9 +5,9 @@ import IAnimationEventInit from './IAnimationEventInit.js'; * */ export default class AnimationEvent extends Event { - public animationName = ''; - public elapsedTime = 0; - public pseudoElement = ''; + public readonly animationName: string; + public readonly elapsedTime: number; + public readonly pseudoElement: string; /** * Constructor. @@ -15,10 +15,11 @@ export default class AnimationEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit?: IAnimationEventInit) { + constructor(type: string, eventInit: IAnimationEventInit = {}) { super(type, eventInit); - this.animationName = eventInit?.animationName || ''; - this.elapsedTime = eventInit?.elapsedTime || 0; - this.pseudoElement = eventInit?.pseudoElement || ''; + + this.animationName = eventInit.animationName ?? ''; + this.elapsedTime = eventInit.elapsedTime ?? 0; + this.pseudoElement = eventInit.pseudoElement ?? ''; } } From 942bdf99767cf5372ce579d28acdbb7ea68801a8 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 16:45:58 +0200 Subject: [PATCH 04/21] #1092@patch: Simplifies CustomEvent. https://dom.spec.whatwg.org/#interface-customevent. --- packages/happy-dom/src/event/events/CustomEvent.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/happy-dom/src/event/events/CustomEvent.ts b/packages/happy-dom/src/event/events/CustomEvent.ts index 91fc93be2..a9305ddc1 100644 --- a/packages/happy-dom/src/event/events/CustomEvent.ts +++ b/packages/happy-dom/src/event/events/CustomEvent.ts @@ -5,7 +5,7 @@ import ICustomEventInit from './ICustomEventInit.js'; * */ export default class CustomEvent extends Event { - public detail: object = null; + public detail: object; /** * Constructor. @@ -13,12 +13,10 @@ export default class CustomEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: ICustomEventInit = null) { + constructor(type: string, eventInit: ICustomEventInit = {}) { super(type, eventInit); - if (eventInit) { - this.detail = eventInit.detail !== undefined ? eventInit.detail : null; - } + this.detail = eventInit.detail ?? null; } /** From afce504cd8a06e210d7bb99fb9d2a015af17a669 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 16:46:18 +0200 Subject: [PATCH 05/21] #1092@patch: Simplifies ErrorEvent. https://html.spec.whatwg.org/multipage/webappapis.html#the-errorevent-interface. --- .../happy-dom/src/event/events/ErrorEvent.ts | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/happy-dom/src/event/events/ErrorEvent.ts b/packages/happy-dom/src/event/events/ErrorEvent.ts index e06b6e2ba..1bb7b61d0 100644 --- a/packages/happy-dom/src/event/events/ErrorEvent.ts +++ b/packages/happy-dom/src/event/events/ErrorEvent.ts @@ -5,11 +5,11 @@ import IErrorEventInit from './IErrorEventInit.js'; * */ export default class ErrorEvent extends UIEvent { - public readonly message: string = ''; - public readonly filename: string = ''; - public readonly lineno: number = 0; - public readonly colno: number = 0; - public readonly error: Error | null = null; + public readonly message: string; + public readonly filename: string; + public readonly lineno: number; + public readonly colno: number; + public readonly error: Error | null; /** * Constructor. @@ -17,15 +17,13 @@ export default class ErrorEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IErrorEventInit = null) { + constructor(type: string, eventInit: IErrorEventInit = {}) { super(type, eventInit); - if (eventInit) { - this.message = eventInit.message || ''; - this.filename = eventInit.filename || ''; - this.lineno = eventInit.lineno !== undefined ? eventInit.lineno : 0; - this.colno = eventInit.colno !== undefined ? eventInit.colno : 0; - this.error = eventInit.error || null; - } + this.message = eventInit.message ?? ''; + this.filename = eventInit.filename ?? ''; + this.lineno = eventInit.lineno ?? 0; + this.colno = eventInit.colno ?? 0; + this.error = eventInit.error ?? null; } } From 4ff55a18d59b4766698bfbd62ade1fb17aaba6cf Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 16:48:37 +0200 Subject: [PATCH 06/21] #1092@patch: Simplifies FocusEvent. https://w3c.github.io/uievents/#interface-focusevent. --- packages/happy-dom/src/event/events/FocusEvent.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/happy-dom/src/event/events/FocusEvent.ts b/packages/happy-dom/src/event/events/FocusEvent.ts index 5aef7647a..cc7468306 100644 --- a/packages/happy-dom/src/event/events/FocusEvent.ts +++ b/packages/happy-dom/src/event/events/FocusEvent.ts @@ -6,7 +6,7 @@ import IFocusEventInit from './IFocusEventInit.js'; * */ export default class FocusEvent extends UIEvent { - public readonly relatedTarget: EventTarget = null; + public readonly relatedTarget: EventTarget | null; /** * Constructor. @@ -14,11 +14,9 @@ export default class FocusEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IFocusEventInit = null) { + constructor(type: string, eventInit: IFocusEventInit = {}) { super(type, eventInit); - if (eventInit) { - this.relatedTarget = eventInit.relatedTarget || null; - } + this.relatedTarget = eventInit.relatedTarget ?? null; } } From e704aca798640671ca01791282bff35f5eb2f1a7 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 16:50:56 +0200 Subject: [PATCH 07/21] #1092@patch: Simplifies InputEvent. https://w3c.github.io/uievents/#interface-inputevent. --- .../happy-dom/src/event/events/InputEvent.ts | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/happy-dom/src/event/events/InputEvent.ts b/packages/happy-dom/src/event/events/InputEvent.ts index a906d4243..d003ea2c6 100644 --- a/packages/happy-dom/src/event/events/InputEvent.ts +++ b/packages/happy-dom/src/event/events/InputEvent.ts @@ -6,10 +6,10 @@ import IInputEventInit from './IInputEventInit.js'; * */ export default class InputEvent extends UIEvent { - public readonly data: string = ''; - public readonly dataTransfer: DataTransfer = null; - public readonly inputType: string = ''; - public readonly isComposing: boolean = false; + public readonly data: string; + public readonly dataTransfer: DataTransfer; + public readonly inputType: string; + public readonly isComposing: boolean; /** * Constructor. @@ -17,14 +17,12 @@ export default class InputEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IInputEventInit = null) { + constructor(type: string, eventInit: IInputEventInit = {}) { super(type, eventInit); - if (eventInit) { - this.data = eventInit.data || ''; - this.dataTransfer = eventInit.dataTransfer || null; - this.inputType = eventInit.inputType || ''; - this.isComposing = eventInit.isComposing || false; - } + this.data = eventInit.data ?? ''; + this.dataTransfer = eventInit.dataTransfer ?? null; + this.inputType = eventInit.inputType ?? ''; + this.isComposing = eventInit.isComposing ?? false; } } From 8f53feeca58620dcdf2edeb2f2d5c10a560144bb Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 16:53:36 +0200 Subject: [PATCH 08/21] #1092@patch: Simplifies KeyboardEvent. https://w3c.github.io/uievents/#interface-keyboardevent. --- .../src/event/events/KeyboardEvent.ts | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/packages/happy-dom/src/event/events/KeyboardEvent.ts b/packages/happy-dom/src/event/events/KeyboardEvent.ts index 6ff36a762..86348a1bb 100644 --- a/packages/happy-dom/src/event/events/KeyboardEvent.ts +++ b/packages/happy-dom/src/event/events/KeyboardEvent.ts @@ -9,15 +9,15 @@ export default class KeyboardEvent extends UIEvent { public static DOM_KEY_LOCATION_LEFT = 1; public static DOM_KEY_LOCATION_RIGHT = 2; public static DOM_KEY_LOCATION_NUMPAD = 3; - public readonly altKey: boolean = false; - public readonly code: string = ''; - public readonly ctrlKey: boolean = false; - public readonly isComposing: boolean = false; - public readonly key: string = ''; - public readonly location: number = 0; - public readonly metaKey: boolean = false; - public readonly repeat: boolean = false; - public readonly shiftKey: boolean = false; + public readonly altKey: boolean; + public readonly code: string; + public readonly ctrlKey: boolean; + public readonly isComposing: boolean; + public readonly key: string; + public readonly location: number; + public readonly metaKey: boolean; + public readonly repeat: boolean; + public readonly shiftKey: boolean; /** * Constructor. @@ -25,19 +25,17 @@ export default class KeyboardEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IKeyboardEventInit = null) { + constructor(type: string, eventInit: IKeyboardEventInit = {}) { super(type, eventInit); - if (eventInit) { - this.altKey = eventInit.altKey || false; - this.code = eventInit.code || ''; - this.ctrlKey = eventInit.ctrlKey || false; - this.isComposing = eventInit.isComposing || false; - this.key = eventInit.key || ''; - this.location = eventInit.location !== undefined ? eventInit.location : 0; - this.metaKey = eventInit.metaKey || false; - this.repeat = eventInit.repeat || false; - this.shiftKey = eventInit.shiftKey || false; - } + this.altKey = eventInit.altKey ?? false; + this.code = eventInit.code ?? ''; + this.ctrlKey = eventInit.ctrlKey ?? false; + this.isComposing = eventInit.isComposing ?? false; + this.key = eventInit.key ?? ''; + this.location = eventInit.location ?? 0; + this.metaKey = eventInit.metaKey ?? false; + this.repeat = eventInit.repeat ?? false; + this.shiftKey = eventInit.shiftKey ?? false; } } From e31aff44e7c511da2c750d6c00eb6c1431739572 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 17:18:46 +0200 Subject: [PATCH 09/21] #1092@patch: Simplifies MediaQueryListEvent. https://drafts.csswg.org/cssom-view/#the-mediaquerylist-interface. --- .../happy-dom/src/event/events/MediaQueryListEvent.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/happy-dom/src/event/events/MediaQueryListEvent.ts b/packages/happy-dom/src/event/events/MediaQueryListEvent.ts index 9125568e8..10afd2e30 100644 --- a/packages/happy-dom/src/event/events/MediaQueryListEvent.ts +++ b/packages/happy-dom/src/event/events/MediaQueryListEvent.ts @@ -5,8 +5,8 @@ import IMediaQueryListInit from './IMediaQueryListInit.js'; * */ export default class MediaQueryListEvent extends Event { - public readonly matches: boolean = false; - public readonly media: string = ''; + public readonly matches: boolean; + public readonly media: string; /** * Constructor. @@ -17,9 +17,7 @@ export default class MediaQueryListEvent extends Event { constructor(type: string, eventInit: IMediaQueryListInit = null) { super(type, eventInit); - if (eventInit) { - this.matches = eventInit.matches || false; - this.media = eventInit.media || ''; - } + this.matches = eventInit.matches ?? false; + this.media = eventInit.media ?? ''; } } From 7ad046baee4488873b57c20e70fb185523611e99 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 17:20:11 +0200 Subject: [PATCH 10/21] #1092@patch: Simplifies MessageEvent. https://html.spec.whatwg.org/multipage/comms.html#the-messageevent-interface. --- .../src/event/events/MessageEvent.ts | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/happy-dom/src/event/events/MessageEvent.ts b/packages/happy-dom/src/event/events/MessageEvent.ts index a0b2260cf..e94337ef8 100644 --- a/packages/happy-dom/src/event/events/MessageEvent.ts +++ b/packages/happy-dom/src/event/events/MessageEvent.ts @@ -9,11 +9,11 @@ import IMessageEventInit from './IMessageEventInit.js'; * @see https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent */ export default class MessageEvent extends Event { - public data?: unknown | null = null; - public origin?: string = ''; - public lastEventId?: string = ''; - public source?: IWindow | null = null; - public ports?: IMessagePort[] = []; + public readonly data: unknown | null; + public readonly origin: string; + public readonly lastEventId: string; + public readonly source: IWindow | null; + public readonly ports: IMessagePort[]; /** * Constructor. @@ -21,12 +21,13 @@ export default class MessageEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit?: IMessageEventInit) { + constructor(type: string, eventInit: IMessageEventInit = {}) { super(type, eventInit); - this.data = eventInit?.data !== undefined ? eventInit.data : null; - this.origin = eventInit?.origin || ''; - this.lastEventId = eventInit?.lastEventId || ''; - this.source = eventInit?.source || null; - this.ports = eventInit?.ports || []; + + this.data = eventInit.data ?? null; + this.origin = eventInit.origin ?? ''; + this.lastEventId = eventInit.lastEventId ?? ''; + this.source = eventInit.source ?? null; + this.ports = eventInit.ports ?? []; } } From 2f81725aad9fc14596ca8a20b947c4306745b0c9 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 17:24:24 +0200 Subject: [PATCH 11/21] #1092@patch: Simplifies MouseEvent. https://w3c.github.io/uievents/#interface-mouseevent. --- .../happy-dom/src/event/events/MouseEvent.ts | 64 +++++++++---------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/packages/happy-dom/src/event/events/MouseEvent.ts b/packages/happy-dom/src/event/events/MouseEvent.ts index 88dd6f04b..c3c5a2a17 100644 --- a/packages/happy-dom/src/event/events/MouseEvent.ts +++ b/packages/happy-dom/src/event/events/MouseEvent.ts @@ -6,22 +6,22 @@ import IMouseEventInit from './IMouseEventInit.js'; * */ export default class MouseEvent extends UIEvent { - public readonly altKey: boolean = false; - public readonly button: number = 0; - public readonly buttons: number = 0; - public readonly clientX: number = 0; - public readonly clientY: number = 0; - public readonly ctrlKey: boolean = false; - public readonly metaKey: boolean = false; - public readonly movementX: number = 0; - public readonly movementY: number = 0; - public readonly offsetX: number = 0; - public readonly offsetY: number = 0; - public readonly region: string = ''; - public readonly relatedTarget: EventTarget = null; - public readonly screenX: number = 0; - public readonly screenY: number = 0; - public readonly shiftKey: boolean = false; + public readonly altKey: boolean; + public readonly button: number; + public readonly buttons: number; + public readonly clientX: number; + public readonly clientY: number; + public readonly ctrlKey: boolean; + public readonly metaKey: boolean; + public readonly movementX: number; + public readonly movementY: number; + public readonly offsetX: number; + public readonly offsetY: number; + public readonly region: string; + public readonly relatedTarget: EventTarget | null; + public readonly screenX: number; + public readonly screenY: number; + public readonly shiftKey: boolean; /** * Constructor. @@ -29,24 +29,22 @@ export default class MouseEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IMouseEventInit = null) { + constructor(type: string, eventInit: IMouseEventInit = {}) { super(type, eventInit); - if (eventInit) { - this.altKey = eventInit.altKey || false; - this.button = eventInit.button !== undefined ? eventInit.button : 0; - this.buttons = eventInit.buttons !== undefined ? eventInit.buttons : 0; - this.clientX = eventInit.clientX !== undefined ? eventInit.clientX : 0; - this.clientY = eventInit.clientY !== undefined ? eventInit.clientY : 0; - this.ctrlKey = eventInit.ctrlKey || false; - this.metaKey = eventInit.metaKey || false; - this.movementX = eventInit.movementX || 0; - this.movementY = eventInit.movementY || 0; - this.region = eventInit.region || ''; - this.relatedTarget = eventInit.relatedTarget || null; - this.screenX = eventInit.screenX !== undefined ? eventInit.screenX : 0; - this.screenY = eventInit.screenY !== undefined ? eventInit.screenY : 0; - this.shiftKey = eventInit.shiftKey || false; - } + this.altKey = eventInit.altKey ?? false; + this.button = eventInit.button ?? 0; + this.buttons = eventInit.buttons ?? 0; + this.clientX = eventInit.clientX ?? 0; + this.clientY = eventInit.clientY ?? 0; + this.ctrlKey = eventInit.ctrlKey ?? false; + this.metaKey = eventInit.metaKey ?? false; + this.movementX = eventInit.movementX ?? 0; + this.movementY = eventInit.movementY ?? 0; + this.region = eventInit.region ?? ''; + this.relatedTarget = eventInit.relatedTarget ?? null; + this.screenX = eventInit.screenX ?? 0; + this.screenY = eventInit.screenY ?? 0; + this.shiftKey = eventInit.shiftKey ?? false; } } From 4714f21535a761a63eef3ead39c9d7cc795c49d3 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 17:25:43 +0200 Subject: [PATCH 12/21] #1092@patch: Simplifies ProgressEvent. https://xhr.spec.whatwg.org/#interface-progressevent. --- .../happy-dom/src/event/events/ProgressEvent.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/happy-dom/src/event/events/ProgressEvent.ts b/packages/happy-dom/src/event/events/ProgressEvent.ts index 071e26f8d..8caa72166 100644 --- a/packages/happy-dom/src/event/events/ProgressEvent.ts +++ b/packages/happy-dom/src/event/events/ProgressEvent.ts @@ -5,9 +5,9 @@ import IProgressEventInit from './IProgressEventInit.js'; * */ export default class ProgressEvent extends Event { - public readonly lengthComputable: boolean = false; - public readonly loaded: number = 0; - public readonly total: number = 0; + public readonly lengthComputable: boolean; + public readonly loaded: number; + public readonly total: number; /** * Constructor. @@ -15,13 +15,11 @@ export default class ProgressEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IProgressEventInit = null) { + constructor(type: string, eventInit: IProgressEventInit = {}) { super(type); - if (eventInit) { - this.lengthComputable = eventInit.lengthComputable || false; - this.loaded = eventInit.loaded !== undefined ? eventInit.loaded : 0; - this.total = eventInit.total !== undefined ? eventInit.total : 0; - } + this.lengthComputable = eventInit.lengthComputable ?? false; + this.loaded = eventInit.loaded ?? 0; + this.total = eventInit.total ?? 0; } } From 4ee35d95a66ab1ac2c81b0f120478eeaeb8299c7 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 17:34:27 +0200 Subject: [PATCH 13/21] #1092@patch: Simplifies StorageEvent. https://html.spec.whatwg.org/multipage/webstorage.html#the-storageevent-interface. --- .../src/event/events/IStorageEventInit.ts | 3 ++- .../src/event/events/StorageEvent.ts | 22 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/happy-dom/src/event/events/IStorageEventInit.ts b/packages/happy-dom/src/event/events/IStorageEventInit.ts index c7575f792..f0228cc94 100644 --- a/packages/happy-dom/src/event/events/IStorageEventInit.ts +++ b/packages/happy-dom/src/event/events/IStorageEventInit.ts @@ -3,7 +3,8 @@ import Storage from '../../storage/Storage.js'; export default interface IStorageEventInit extends IEventInit { key?: string; - newValue?: string; oldValue?: string; + newValue?: string; + url?: string; storageArea?: Storage; } diff --git a/packages/happy-dom/src/event/events/StorageEvent.ts b/packages/happy-dom/src/event/events/StorageEvent.ts index a824409fe..0684715d5 100644 --- a/packages/happy-dom/src/event/events/StorageEvent.ts +++ b/packages/happy-dom/src/event/events/StorageEvent.ts @@ -6,10 +6,11 @@ import Storage from '../../storage/Storage.js'; * */ export default class StorageEvent extends Event { - public readonly key: string = null; - public readonly newValue: string = null; - public readonly oldValue: string = null; - public readonly storageArea: Storage = null; + public readonly key: string | null; + public readonly oldValue: string | null; + public readonly newValue: string | null; + public readonly url: string; + public readonly storageArea: Storage | null; /** * Constructor. @@ -17,14 +18,13 @@ export default class StorageEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IStorageEventInit = null) { + constructor(type: string, eventInit: IStorageEventInit = {}) { super(type); - if (eventInit) { - this.key = eventInit.key !== undefined ? eventInit.key : null; - this.newValue = eventInit.newValue !== undefined ? eventInit.newValue : null; - this.oldValue = eventInit.oldValue !== undefined ? eventInit.oldValue : null; - this.storageArea = eventInit.storageArea !== undefined ? eventInit.storageArea : null; - } + this.key = eventInit.key ?? null; + this.oldValue = eventInit.oldValue ?? null; + this.newValue = eventInit.newValue ?? null; + this.url = eventInit.url ?? ''; + this.storageArea = eventInit.storageArea ?? null; } } From 64e4bd9d59969c8a5c22fcbe730e48c9269afb3c Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 17:35:27 +0200 Subject: [PATCH 14/21] #1092@patch: Simplifies SubmitEvent. https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#the-submitevent-interface. --- packages/happy-dom/src/event/events/SubmitEvent.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/happy-dom/src/event/events/SubmitEvent.ts b/packages/happy-dom/src/event/events/SubmitEvent.ts index 773ace36e..882460e6e 100644 --- a/packages/happy-dom/src/event/events/SubmitEvent.ts +++ b/packages/happy-dom/src/event/events/SubmitEvent.ts @@ -6,7 +6,7 @@ import IHTMLElement from '../../nodes/html-element/IHTMLElement.js'; * An event triggered by form submit buttons. */ export default class SubmitEvent extends Event { - public readonly submitter: IHTMLElement; + public readonly submitter: IHTMLElement | null; /** * Constructor. @@ -14,9 +14,9 @@ export default class SubmitEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: ISubmitEventInit = null) { + constructor(type: string, eventInit: ISubmitEventInit = {}) { super(type, eventInit); - this.submitter = eventInit?.submitter || null; + this.submitter = eventInit.submitter ?? null; } } From 7a9cbb4725ad4c1c97d84ce58864dfc0e13eb7ab Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 17:35:47 +0200 Subject: [PATCH 15/21] #1092@patch: Simplifies WheelEvent. https://w3c.github.io/uievents/#interface-wheelevent. --- .../happy-dom/src/event/events/WheelEvent.ts | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/happy-dom/src/event/events/WheelEvent.ts b/packages/happy-dom/src/event/events/WheelEvent.ts index 3cfaa82ac..edaa216ae 100644 --- a/packages/happy-dom/src/event/events/WheelEvent.ts +++ b/packages/happy-dom/src/event/events/WheelEvent.ts @@ -8,10 +8,10 @@ export default class WheelEvent extends UIEvent { public static DOM_DELTA_PIXEL = 0; public static DOM_DELTA_LINE = 1; public static DOM_DELTA_PAGE = 2; - public readonly deltaX: number = 0; - public readonly deltaY: number = 0; - public readonly deltaZ: number = 0; - public readonly deltaMode: number = 0; + public readonly deltaX: number; + public readonly deltaY: number; + public readonly deltaZ: number; + public readonly deltaMode: number; /** * Constructor. @@ -19,14 +19,12 @@ export default class WheelEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IWheelEventInit = null) { + constructor(type: string, eventInit: IWheelEventInit = {}) { super(type, eventInit); - if (eventInit) { - this.deltaX = eventInit.deltaX !== undefined ? eventInit.deltaX : 0; - this.deltaY = eventInit.deltaY !== undefined ? eventInit.deltaY : 0; - this.deltaZ = eventInit.deltaZ !== undefined ? eventInit.deltaZ : 0; - this.deltaMode = eventInit.deltaMode !== undefined ? eventInit.deltaMode : 0; - } + this.deltaX = eventInit.deltaX ?? 0; + this.deltaY = eventInit.deltaY ?? 0; + this.deltaZ = eventInit.deltaZ ?? 0; + this.deltaMode = eventInit.deltaMode ?? 0; } } From 6e6acd2ac7b9168570dbf24c9ab6149312154b54 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 17:37:53 +0200 Subject: [PATCH 16/21] #1092@patch: Simplifies UIEvent. https://w3c.github.io/uievents/#idl-uievent. --- packages/happy-dom/src/event/UIEvent.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/happy-dom/src/event/UIEvent.ts b/packages/happy-dom/src/event/UIEvent.ts index 6e874aa3b..212e41dc1 100644 --- a/packages/happy-dom/src/event/UIEvent.ts +++ b/packages/happy-dom/src/event/UIEvent.ts @@ -10,12 +10,12 @@ export default class UIEvent extends Event { public static CAPTURING_PHASE = 1; public static AT_TARGET = 2; public static BUBBLING_PHASE = 3; - public readonly detail: number = 0; + public readonly detail: number; public readonly layerX: number = 0; public readonly layerY: number = 0; public readonly pageX: number = 0; public readonly pageY: number = 0; - public readonly view: IWindow = null; + public readonly view: IWindow | null; /** * Constructor. @@ -23,12 +23,10 @@ export default class UIEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IUIEventInit = null) { + constructor(type: string, eventInit: IUIEventInit = {}) { super(type, eventInit); - if (eventInit) { - this.detail = eventInit.detail !== undefined ? eventInit.detail : 0; - this.view = eventInit.view || null; - } + this.detail = eventInit.detail ?? 0; + this.view = eventInit.view ?? null; } } From d7e6620bae10330558872a21faff5c1ee6e275f7 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 17:42:30 +0200 Subject: [PATCH 17/21] #1092@patch: Simplifies Event. https://dom.spec.whatwg.org/#interface-event. --- packages/happy-dom/src/event/Event.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/happy-dom/src/event/Event.ts b/packages/happy-dom/src/event/Event.ts index 8b0634ded..99d324cb1 100644 --- a/packages/happy-dom/src/event/Event.ts +++ b/packages/happy-dom/src/event/Event.ts @@ -12,9 +12,9 @@ import IDocument from '../nodes/document/IDocument.js'; * Event. */ export default class Event { - public composed = false; - public bubbles = false; - public cancelable = false; + public composed: boolean; + public bubbles: boolean; + public cancelable: boolean; public defaultPrevented = false; public eventPhase: EventPhaseEnum = EventPhaseEnum.none; public _immediatePropagationStopped = false; @@ -22,7 +22,7 @@ export default class Event { public _target: IEventTarget = null; public _currentTarget: IEventTarget = null; public timeStamp: number = performance.now(); - public type: string = null; + public type: string; public _isInPassiveEventListener = false; public NONE = EventPhaseEnum.none; public CAPTURING_PHASE = EventPhaseEnum.capturing; @@ -35,14 +35,12 @@ export default class Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IEventInit = null) { + constructor(type: string, eventInit: IEventInit = {}) { this.type = type; - if (eventInit) { - this.bubbles = eventInit.bubbles || false; - this.cancelable = eventInit.cancelable || false; - this.composed = eventInit.composed || false; - } + this.bubbles = eventInit.bubbles ?? false; + this.cancelable = eventInit.cancelable ?? false; + this.composed = eventInit.composed ?? false; } /** From a09244e6080ba39b4ed99bcb24aadb642a65de0e Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 17:52:50 +0200 Subject: [PATCH 18/21] #1092@patch: Fixes MediaQueryListEvent eventInit param. --- packages/happy-dom/src/event/events/MediaQueryListEvent.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/happy-dom/src/event/events/MediaQueryListEvent.ts b/packages/happy-dom/src/event/events/MediaQueryListEvent.ts index 10afd2e30..60afbf2d2 100644 --- a/packages/happy-dom/src/event/events/MediaQueryListEvent.ts +++ b/packages/happy-dom/src/event/events/MediaQueryListEvent.ts @@ -14,7 +14,7 @@ export default class MediaQueryListEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IMediaQueryListInit = null) { + constructor(type: string, eventInit: IMediaQueryListInit = {}) { super(type, eventInit); this.matches = eventInit.matches ?? false; From 40e01dc2f851c2b9d17002bbc086b0c2c1652f0e Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sat, 30 Sep 2023 12:28:43 +0200 Subject: [PATCH 19/21] #1092@patch: Switch back to eventInit = null instead of {}. --- packages/happy-dom/src/event/Event.ts | 8 ++--- packages/happy-dom/src/event/UIEvent.ts | 6 ++-- .../src/event/events/AnimationEvent.ts | 8 ++--- .../happy-dom/src/event/events/CustomEvent.ts | 4 +-- .../happy-dom/src/event/events/ErrorEvent.ts | 12 ++++---- .../happy-dom/src/event/events/FocusEvent.ts | 4 +-- .../happy-dom/src/event/events/InputEvent.ts | 10 +++---- .../src/event/events/KeyboardEvent.ts | 20 ++++++------- .../src/event/events/MediaQueryListEvent.ts | 6 ++-- .../src/event/events/MessageEvent.ts | 12 ++++---- .../happy-dom/src/event/events/MouseEvent.ts | 30 +++++++++---------- .../src/event/events/PointerEvent.ts | 30 +++++++++---------- .../src/event/events/ProgressEvent.ts | 8 ++--- .../src/event/events/StorageEvent.ts | 12 ++++---- .../happy-dom/src/event/events/SubmitEvent.ts | 4 +-- .../happy-dom/src/event/events/WheelEvent.ts | 10 +++---- 16 files changed, 92 insertions(+), 92 deletions(-) diff --git a/packages/happy-dom/src/event/Event.ts b/packages/happy-dom/src/event/Event.ts index 99d324cb1..c039f9b68 100644 --- a/packages/happy-dom/src/event/Event.ts +++ b/packages/happy-dom/src/event/Event.ts @@ -35,12 +35,12 @@ export default class Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IEventInit = {}) { + constructor(type: string, eventInit: IEventInit | null = null) { this.type = type; - this.bubbles = eventInit.bubbles ?? false; - this.cancelable = eventInit.cancelable ?? false; - this.composed = eventInit.composed ?? false; + this.bubbles = eventInit?.bubbles ?? false; + this.cancelable = eventInit?.cancelable ?? false; + this.composed = eventInit?.composed ?? false; } /** diff --git a/packages/happy-dom/src/event/UIEvent.ts b/packages/happy-dom/src/event/UIEvent.ts index 212e41dc1..1fc859f16 100644 --- a/packages/happy-dom/src/event/UIEvent.ts +++ b/packages/happy-dom/src/event/UIEvent.ts @@ -23,10 +23,10 @@ export default class UIEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IUIEventInit = {}) { + constructor(type: string, eventInit: IUIEventInit | null = null) { super(type, eventInit); - this.detail = eventInit.detail ?? 0; - this.view = eventInit.view ?? null; + this.detail = eventInit?.detail ?? 0; + this.view = eventInit?.view ?? null; } } diff --git a/packages/happy-dom/src/event/events/AnimationEvent.ts b/packages/happy-dom/src/event/events/AnimationEvent.ts index 12477c9e2..669e26638 100644 --- a/packages/happy-dom/src/event/events/AnimationEvent.ts +++ b/packages/happy-dom/src/event/events/AnimationEvent.ts @@ -15,11 +15,11 @@ export default class AnimationEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IAnimationEventInit = {}) { + constructor(type: string, eventInit: IAnimationEventInit | null = null) { super(type, eventInit); - this.animationName = eventInit.animationName ?? ''; - this.elapsedTime = eventInit.elapsedTime ?? 0; - this.pseudoElement = eventInit.pseudoElement ?? ''; + this.animationName = eventInit?.animationName ?? ''; + this.elapsedTime = eventInit?.elapsedTime ?? 0; + this.pseudoElement = eventInit?.pseudoElement ?? ''; } } diff --git a/packages/happy-dom/src/event/events/CustomEvent.ts b/packages/happy-dom/src/event/events/CustomEvent.ts index a9305ddc1..f0f4d12d7 100644 --- a/packages/happy-dom/src/event/events/CustomEvent.ts +++ b/packages/happy-dom/src/event/events/CustomEvent.ts @@ -13,10 +13,10 @@ export default class CustomEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: ICustomEventInit = {}) { + constructor(type: string, eventInit: ICustomEventInit | null = null) { super(type, eventInit); - this.detail = eventInit.detail ?? null; + this.detail = eventInit?.detail ?? null; } /** diff --git a/packages/happy-dom/src/event/events/ErrorEvent.ts b/packages/happy-dom/src/event/events/ErrorEvent.ts index 1bb7b61d0..1bd1725c5 100644 --- a/packages/happy-dom/src/event/events/ErrorEvent.ts +++ b/packages/happy-dom/src/event/events/ErrorEvent.ts @@ -17,13 +17,13 @@ export default class ErrorEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IErrorEventInit = {}) { + constructor(type: string, eventInit: IErrorEventInit | null = null) { super(type, eventInit); - this.message = eventInit.message ?? ''; - this.filename = eventInit.filename ?? ''; - this.lineno = eventInit.lineno ?? 0; - this.colno = eventInit.colno ?? 0; - this.error = eventInit.error ?? null; + this.message = eventInit?.message ?? ''; + this.filename = eventInit?.filename ?? ''; + this.lineno = eventInit?.lineno ?? 0; + this.colno = eventInit?.colno ?? 0; + this.error = eventInit?.error ?? null; } } diff --git a/packages/happy-dom/src/event/events/FocusEvent.ts b/packages/happy-dom/src/event/events/FocusEvent.ts index cc7468306..3a6493050 100644 --- a/packages/happy-dom/src/event/events/FocusEvent.ts +++ b/packages/happy-dom/src/event/events/FocusEvent.ts @@ -14,9 +14,9 @@ export default class FocusEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IFocusEventInit = {}) { + constructor(type: string, eventInit: IFocusEventInit | null = null) { super(type, eventInit); - this.relatedTarget = eventInit.relatedTarget ?? null; + this.relatedTarget = eventInit?.relatedTarget ?? null; } } diff --git a/packages/happy-dom/src/event/events/InputEvent.ts b/packages/happy-dom/src/event/events/InputEvent.ts index d003ea2c6..01c06d501 100644 --- a/packages/happy-dom/src/event/events/InputEvent.ts +++ b/packages/happy-dom/src/event/events/InputEvent.ts @@ -17,12 +17,12 @@ export default class InputEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IInputEventInit = {}) { + constructor(type: string, eventInit: IInputEventInit | null = null) { super(type, eventInit); - this.data = eventInit.data ?? ''; - this.dataTransfer = eventInit.dataTransfer ?? null; - this.inputType = eventInit.inputType ?? ''; - this.isComposing = eventInit.isComposing ?? false; + this.data = eventInit?.data ?? ''; + this.dataTransfer = eventInit?.dataTransfer ?? null; + this.inputType = eventInit?.inputType ?? ''; + this.isComposing = eventInit?.isComposing ?? false; } } diff --git a/packages/happy-dom/src/event/events/KeyboardEvent.ts b/packages/happy-dom/src/event/events/KeyboardEvent.ts index 86348a1bb..632c60f1a 100644 --- a/packages/happy-dom/src/event/events/KeyboardEvent.ts +++ b/packages/happy-dom/src/event/events/KeyboardEvent.ts @@ -25,17 +25,17 @@ export default class KeyboardEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IKeyboardEventInit = {}) { + constructor(type: string, eventInit: IKeyboardEventInit | null = null) { super(type, eventInit); - this.altKey = eventInit.altKey ?? false; - this.code = eventInit.code ?? ''; - this.ctrlKey = eventInit.ctrlKey ?? false; - this.isComposing = eventInit.isComposing ?? false; - this.key = eventInit.key ?? ''; - this.location = eventInit.location ?? 0; - this.metaKey = eventInit.metaKey ?? false; - this.repeat = eventInit.repeat ?? false; - this.shiftKey = eventInit.shiftKey ?? false; + this.altKey = eventInit?.altKey ?? false; + this.code = eventInit?.code ?? ''; + this.ctrlKey = eventInit?.ctrlKey ?? false; + this.isComposing = eventInit?.isComposing ?? false; + this.key = eventInit?.key ?? ''; + this.location = eventInit?.location ?? 0; + this.metaKey = eventInit?.metaKey ?? false; + this.repeat = eventInit?.repeat ?? false; + this.shiftKey = eventInit?.shiftKey ?? false; } } diff --git a/packages/happy-dom/src/event/events/MediaQueryListEvent.ts b/packages/happy-dom/src/event/events/MediaQueryListEvent.ts index 60afbf2d2..9d9f9e9eb 100644 --- a/packages/happy-dom/src/event/events/MediaQueryListEvent.ts +++ b/packages/happy-dom/src/event/events/MediaQueryListEvent.ts @@ -14,10 +14,10 @@ export default class MediaQueryListEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IMediaQueryListInit = {}) { + constructor(type: string, eventInit: IMediaQueryListInit | null = null) { super(type, eventInit); - this.matches = eventInit.matches ?? false; - this.media = eventInit.media ?? ''; + this.matches = eventInit?.matches ?? false; + this.media = eventInit?.media ?? ''; } } diff --git a/packages/happy-dom/src/event/events/MessageEvent.ts b/packages/happy-dom/src/event/events/MessageEvent.ts index e94337ef8..a2cd12f8e 100644 --- a/packages/happy-dom/src/event/events/MessageEvent.ts +++ b/packages/happy-dom/src/event/events/MessageEvent.ts @@ -21,13 +21,13 @@ export default class MessageEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IMessageEventInit = {}) { + constructor(type: string, eventInit: IMessageEventInit | null = null) { super(type, eventInit); - this.data = eventInit.data ?? null; - this.origin = eventInit.origin ?? ''; - this.lastEventId = eventInit.lastEventId ?? ''; - this.source = eventInit.source ?? null; - this.ports = eventInit.ports ?? []; + this.data = eventInit?.data ?? null; + this.origin = eventInit?.origin ?? ''; + this.lastEventId = eventInit?.lastEventId ?? ''; + this.source = eventInit?.source ?? null; + this.ports = eventInit?.ports ?? []; } } diff --git a/packages/happy-dom/src/event/events/MouseEvent.ts b/packages/happy-dom/src/event/events/MouseEvent.ts index c3c5a2a17..036a902a9 100644 --- a/packages/happy-dom/src/event/events/MouseEvent.ts +++ b/packages/happy-dom/src/event/events/MouseEvent.ts @@ -29,22 +29,22 @@ export default class MouseEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IMouseEventInit = {}) { + constructor(type: string, eventInit: IMouseEventInit | null = null) { super(type, eventInit); - this.altKey = eventInit.altKey ?? false; - this.button = eventInit.button ?? 0; - this.buttons = eventInit.buttons ?? 0; - this.clientX = eventInit.clientX ?? 0; - this.clientY = eventInit.clientY ?? 0; - this.ctrlKey = eventInit.ctrlKey ?? false; - this.metaKey = eventInit.metaKey ?? false; - this.movementX = eventInit.movementX ?? 0; - this.movementY = eventInit.movementY ?? 0; - this.region = eventInit.region ?? ''; - this.relatedTarget = eventInit.relatedTarget ?? null; - this.screenX = eventInit.screenX ?? 0; - this.screenY = eventInit.screenY ?? 0; - this.shiftKey = eventInit.shiftKey ?? false; + this.altKey = eventInit?.altKey ?? false; + this.button = eventInit?.button ?? 0; + this.buttons = eventInit?.buttons ?? 0; + this.clientX = eventInit?.clientX ?? 0; + this.clientY = eventInit?.clientY ?? 0; + this.ctrlKey = eventInit?.ctrlKey ?? false; + this.metaKey = eventInit?.metaKey ?? false; + this.movementX = eventInit?.movementX ?? 0; + this.movementY = eventInit?.movementY ?? 0; + this.region = eventInit?.region ?? ''; + this.relatedTarget = eventInit?.relatedTarget ?? null; + this.screenX = eventInit?.screenX ?? 0; + this.screenY = eventInit?.screenY ?? 0; + this.shiftKey = eventInit?.shiftKey ?? false; } } diff --git a/packages/happy-dom/src/event/events/PointerEvent.ts b/packages/happy-dom/src/event/events/PointerEvent.ts index e41a7ee35..32aa9d805 100644 --- a/packages/happy-dom/src/event/events/PointerEvent.ts +++ b/packages/happy-dom/src/event/events/PointerEvent.ts @@ -26,23 +26,23 @@ export default class PointerEvent extends MouseEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IPointerEventInit = {}) { + constructor(type: string, eventInit: IPointerEventInit | null = null) { super(type, eventInit); - this.pointerId = eventInit.pointerId ?? 0; - this.width = eventInit.width ?? 1; - this.height = eventInit.height ?? 1; - this.pressure = eventInit.pressure ?? 0; - this.tangentialPressure = eventInit.tangentialPressure ?? 0; - this.tiltX = eventInit.tiltX ?? 0; - this.tiltY = eventInit.tiltY ?? 0; - this.twist = eventInit.twist ?? 0; - this.altitudeAngle = eventInit.altitudeAngle ?? 0; - this.azimuthAngle = eventInit.azimuthAngle ?? 0; - this.pointerType = eventInit.pointerType ?? ''; - this.isPrimary = eventInit.isPrimary ?? false; - this.coalescedEvents = eventInit.coalescedEvents ?? []; - this.predictedEvents = eventInit.predictedEvents ?? []; + this.pointerId = eventInit?.pointerId ?? 0; + this.width = eventInit?.width ?? 1; + this.height = eventInit?.height ?? 1; + this.pressure = eventInit?.pressure ?? 0; + this.tangentialPressure = eventInit?.tangentialPressure ?? 0; + this.tiltX = eventInit?.tiltX ?? 0; + this.tiltY = eventInit?.tiltY ?? 0; + this.twist = eventInit?.twist ?? 0; + this.altitudeAngle = eventInit?.altitudeAngle ?? 0; + this.azimuthAngle = eventInit?.azimuthAngle ?? 0; + this.pointerType = eventInit?.pointerType ?? ''; + this.isPrimary = eventInit?.isPrimary ?? false; + this.coalescedEvents = eventInit?.coalescedEvents ?? []; + this.predictedEvents = eventInit?.predictedEvents ?? []; } public getCoalescedEvents = (): PointerEvent[] => this.coalescedEvents; diff --git a/packages/happy-dom/src/event/events/ProgressEvent.ts b/packages/happy-dom/src/event/events/ProgressEvent.ts index 8caa72166..1ed8dd6da 100644 --- a/packages/happy-dom/src/event/events/ProgressEvent.ts +++ b/packages/happy-dom/src/event/events/ProgressEvent.ts @@ -15,11 +15,11 @@ export default class ProgressEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IProgressEventInit = {}) { + constructor(type: string, eventInit: IProgressEventInit | null = null) { super(type); - this.lengthComputable = eventInit.lengthComputable ?? false; - this.loaded = eventInit.loaded ?? 0; - this.total = eventInit.total ?? 0; + this.lengthComputable = eventInit?.lengthComputable ?? false; + this.loaded = eventInit?.loaded ?? 0; + this.total = eventInit?.total ?? 0; } } diff --git a/packages/happy-dom/src/event/events/StorageEvent.ts b/packages/happy-dom/src/event/events/StorageEvent.ts index 0684715d5..24ea5498c 100644 --- a/packages/happy-dom/src/event/events/StorageEvent.ts +++ b/packages/happy-dom/src/event/events/StorageEvent.ts @@ -18,13 +18,13 @@ export default class StorageEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IStorageEventInit = {}) { + constructor(type: string, eventInit: IStorageEventInit | null = null) { super(type); - this.key = eventInit.key ?? null; - this.oldValue = eventInit.oldValue ?? null; - this.newValue = eventInit.newValue ?? null; - this.url = eventInit.url ?? ''; - this.storageArea = eventInit.storageArea ?? null; + this.key = eventInit?.key ?? null; + this.oldValue = eventInit?.oldValue ?? null; + this.newValue = eventInit?.newValue ?? null; + this.url = eventInit?.url ?? ''; + this.storageArea = eventInit?.storageArea ?? null; } } diff --git a/packages/happy-dom/src/event/events/SubmitEvent.ts b/packages/happy-dom/src/event/events/SubmitEvent.ts index 882460e6e..864173cf1 100644 --- a/packages/happy-dom/src/event/events/SubmitEvent.ts +++ b/packages/happy-dom/src/event/events/SubmitEvent.ts @@ -14,9 +14,9 @@ export default class SubmitEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: ISubmitEventInit = {}) { + constructor(type: string, eventInit: ISubmitEventInit | null = null) { super(type, eventInit); - this.submitter = eventInit.submitter ?? null; + this.submitter = eventInit?.submitter ?? null; } } diff --git a/packages/happy-dom/src/event/events/WheelEvent.ts b/packages/happy-dom/src/event/events/WheelEvent.ts index edaa216ae..097d06007 100644 --- a/packages/happy-dom/src/event/events/WheelEvent.ts +++ b/packages/happy-dom/src/event/events/WheelEvent.ts @@ -19,12 +19,12 @@ export default class WheelEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IWheelEventInit = {}) { + constructor(type: string, eventInit: IWheelEventInit | null = null) { super(type, eventInit); - this.deltaX = eventInit.deltaX ?? 0; - this.deltaY = eventInit.deltaY ?? 0; - this.deltaZ = eventInit.deltaZ ?? 0; - this.deltaMode = eventInit.deltaMode ?? 0; + this.deltaX = eventInit?.deltaX ?? 0; + this.deltaY = eventInit?.deltaY ?? 0; + this.deltaZ = eventInit?.deltaZ ?? 0; + this.deltaMode = eventInit?.deltaMode ?? 0; } } From cad98a959d863c6e1b6a9db645c207fd6fce8feb Mon Sep 17 00:00:00 2001 From: David Ortner Date: Sat, 30 Sep 2023 13:23:04 +0200 Subject: [PATCH 20/21] #1092@trivial: Fix detail in CustomEvent. --- packages/happy-dom/src/event/events/CustomEvent.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/happy-dom/src/event/events/CustomEvent.ts b/packages/happy-dom/src/event/events/CustomEvent.ts index f0f4d12d7..0393d9709 100644 --- a/packages/happy-dom/src/event/events/CustomEvent.ts +++ b/packages/happy-dom/src/event/events/CustomEvent.ts @@ -5,7 +5,8 @@ import ICustomEventInit from './ICustomEventInit.js'; * */ export default class CustomEvent extends Event { - public detail: object; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public detail: any; /** * Constructor. From 04b2fcc245823574348bef422a1ea154c5be8ff5 Mon Sep 17 00:00:00 2001 From: David Ortner Date: Sat, 30 Sep 2023 13:26:40 +0200 Subject: [PATCH 21/21] #1092@trivial: Adds test for PointerEvent. --- packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts b/packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts index 054fa16c2..fb5194e66 100644 --- a/packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts +++ b/packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts @@ -394,6 +394,8 @@ describe('HTMLElement', () => { expect(((triggeredEvent)).composed).toBe(true); expect(((triggeredEvent)).target === element).toBe(true); expect(((triggeredEvent)).currentTarget === element).toBe(true); + expect(((triggeredEvent)).width).toBe(1); + expect(((triggeredEvent)).height).toBe(1); }); });