refactor: hoist constructor-assigned properties to class fields in src/core and src/platform/input#8635
Conversation
Aligns `src/core/tags.js` and all classes in `src/platform/input/` with the
class-fields convention in AGENTS.md §15: every property assigned via
`this.x = ...` now has a corresponding class-field declaration with a
`@type` JSDoc block.
- `Tags._parent` hoisted.
- `MouseEvent.buttons` hoisted.
- `Mouse` bound event handlers (`_upHandler`, `_downHandler`, `_moveHandler`,
`_wheelHandler`, `_contextMenuHandler`) hoisted.
- `Keyboard` bound event handlers (`_keyDownHandler`, `_keyUpHandler`,
`_keyPressHandler`, `_visibilityChangeHandler`, `_windowBlurHandler`) plus
`preventDefault` / `stopPropagation` hoisted.
- `TouchDevice._element` and bound handlers hoisted; redundant
`this._element = null` removed from the constructor.
- `GamePad` (id, index, _buttons, _axes, _previousAxes, mapping, map, hand,
pad) hoisted, preserving existing JSDoc.
- `GamePads` (gamepadsSupported, current, _previous, and the two connect
handlers) hoisted; `current` / `_previous` now initialized directly via
field initializers, removing redundant constructor assignments.
Also tightens the return type of `getTouchTargetCoords` in
`src/platform/input/touch-event.js` from `object` to `{x: number, y: number}`.
No behavior changes. Verified with `npx eslint src/platform/input/`,
`npm run build:types`, and `npm run test:types`.
Made-with: Cursor
There was a problem hiding this comment.
Pull request overview
Refactors core/input classes to follow the repository’s class-fields convention by hoisting constructor-assigned properties into explicit class field declarations and tightening a touch helper return type.
Changes:
- Hoists constructor-assigned properties to class fields across
src/core/tags.jsandsrc/platform/input/*classes. - Removes redundant constructor assignments that duplicate class-field initializers (e.g.
GamePads.current,GamePads._previous,TouchDevice._element). - Narrows
getTouchTargetCoordsJSDoc return type to{x: number, y: number}.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/platform/input/touch-event.js | Tightens JSDoc return type for getTouchTargetCoords. |
| src/platform/input/touch-device.js | Hoists _element and handler properties to class fields; removes redundant ctor assignment. |
| src/platform/input/mouse.js | Hoists bound handler properties to class fields. |
| src/platform/input/mouse-event.js | Adds buttons as an explicit class field with JSDoc. |
| src/platform/input/keyboard.js | Hoists bound handler properties and options flags to class fields with JSDoc. |
| src/platform/input/game-pads.js | Hoists GamePad/GamePads constructor-assigned properties to class fields; removes redundant ctor array initializations. |
| src/core/tags.js | Hoists _parent to an explicit class field with JSDoc. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _list = []; | ||
|
|
||
| /** | ||
| * @type {object} |
There was a problem hiding this comment.
_parent is declared as @type {object}, but constructor(parent) accepts parent as optional, so _parent can be undefined. Update the field JSDoc (and/or add an initializer) to reflect the actual possible values (e.g. object|undefined or initialize to null and type object|null) so generated types/docs are accurate.
| * @type {object} | |
| * @type {object|undefined} |
Summary
src/core/tags.jsand every class insrc/platform/input/with the class-fields convention inAGENTS.md§15. All properties previously assigned only viathis.x = ...in a constructor now have explicit class-field declarations with@typeJSDoc blocks.GamePads.current/GamePads._previousandTouchDevice._element).getTouchTargetCoordsinsrc/platform/input/touch-event.jsfrom the genericobjectto{x: number, y: number}.Hoisted fields by class:
Tags:_parentMouseEvent:buttonsMouse:_upHandler,_downHandler,_moveHandler,_wheelHandler,_contextMenuHandlerKeyboard:_keyDownHandler,_keyUpHandler,_keyPressHandler,_visibilityChangeHandler,_windowBlurHandler,preventDefault,stopPropagationTouchDevice:_element,_startHandler,_endHandler,_moveHandler,_cancelHandlerGamePad:id,index,_buttons,_axes,_previousAxes,mapping,map,hand,pad(existing inline JSDoc preserved)GamePads:gamepadsSupported,current,_previous,_ongamepadconnectedHandler,_ongamepaddisconnectedHandlerNo behavior changes.
Test plan
npx eslint src/platform/input/passesnpm run build:typessucceedsnpm run test:typessucceeds