Calling a .data() setter on a mixed selection returned by .contents() skips every element when the first node is text.
const $ = load('<div>text<span></span></div>');
const contents = $('div').contents();
contents.data('foo', 'bar');
console.log($('span').data('foo')); // undefined, expected 'bar'
The object-map setter has the same problem. Both setters also return undefined instead of the selection in this case. Existing behavior and tests set data on all elements when the selection starts with an element; the leading text should simply be skipped.
Reproduced against main 0ab9a8e on macOS / Node.js. Baseline attributes tests pass; a public API regression fails. Proposed fix: execute the existing setter iteration before applying the first-element check that is needed for getters. Correct the two setter docstrings which currently describe first-element-only behavior.
Investigated with OpenAI Codex assistance.
Calling a
.data()setter on a mixed selection returned by.contents()skips every element when the first node is text.The object-map setter has the same problem. Both setters also return
undefinedinstead of the selection in this case. Existing behavior and tests set data on all elements when the selection starts with an element; the leading text should simply be skipped.Reproduced against main 0ab9a8e on macOS / Node.js. Baseline attributes tests pass; a public API regression fails. Proposed fix: execute the existing setter iteration before applying the first-element check that is needed for getters. Correct the two setter docstrings which currently describe first-element-only behavior.
Investigated with OpenAI Codex assistance.