Skip to content

fix: treat undefined force as omitted in classList.toggle - #358

Open
johnhldiver-beep wants to merge 1 commit into
WebReflection:mainfrom
johnhldiver-beep:fix/277-classlist-toggle-undefined
Open

johnhldiver-beep wants to merge 1 commit into
WebReflection:mainfrom
johnhldiver-beep:fix/277-classlist-toggle-undefined

Conversation

@johnhldiver-beep

Copy link
Copy Markdown

Fixes #277.

DOMTokenList.toggle(token, force) treated an explicitly-passed undefined second argument as false instead of as an omitted argument (Web IDL optional-boolean semantics). Repro on base: with the token absent, toggle('test', undefined) returned false and failed to add; with the token present it already removed and returned false.

Fix (1 line, in both esm/dom/token-list.js and the committed mirror cjs/dom/token-list.js): else if (force || arguments.length === 1) → else if (force || force === undefined). One-arg calls behave identically (force is undefined then too); explicit true/false force behaviour is unchanged.

Tests: 4 regression assertions in test/html/element.js beside the existing toggle tests (present+undefined removes and returns false; absent+undefined adds and returns true). New tests failed before the fix (absent case: expected true, got false); node test/html/element.js and the full node test/index.js suite both exit 0 with no failures after the fix. Honest limits: this suite prints no numeric assertion totals, so counts are reported as exit codes + failure-grep counts; eslint/tsc and the full npm test (eslint + benchmark + c8) were not run (only runtime deps installed).

Note: prior PR #334 covered the same concern but was closed unmerged because its author voluntarily withdrew it to clean a backlog — not a maintainer rejection. Adjacent open PR #336 (class-attribute parse perf) does not touch toggle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In 'HTMLElement.classList.toggle' the 'force' attribute works uncorrectly.

1 participant