Repository navigation
fix: treat undefined force as omitted in classList.toggle - #358
Open
johnhldiver-beep wants to merge 1 commit into
Open
johnhldiver-beep wants to merge 1 commit into
johnhldiver-beep wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #277.
DOMTokenList.toggle(token, force)treated an explicitly-passedundefinedsecond argument asfalseinstead of as an omitted argument (Web IDL optional-boolean semantics). Repro on base: with the token absent,toggle('test', undefined)returnedfalseand failed to add; with the token present it already removed and returnedfalse.Fix (1 line, in both
esm/dom/token-list.jsand the committed mirrorcjs/dom/token-list.js):else if (force || arguments.length === 1)→else if (force || force === undefined). One-arg calls behave identically (force isundefinedthen too); explicittrue/falseforce behaviour is unchanged.Tests: 4 regression assertions in
test/html/element.jsbeside the existing toggle tests (present+undefinedremoves and returnsfalse; absent+undefinedadds and returnstrue). New tests failed before the fix (absent case: expectedtrue, gotfalse);node test/html/element.jsand the fullnode test/index.jssuite 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 fullnpm 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.