Skip to content

Commit

Permalink
Fix order of elements after .add
Browse files Browse the repository at this point in the history
```js
$('<a>').add('<b>').map((i, e) => console.log(e.tagName))
```

produces `A`, then `B` in jQuery, and `b` and `a` in cheerio.

Adapter from #952.

Co-Authored-By: codeevery <1003657663@qq.com>
  • Loading branch information
fb55 and 1003657663 committed Mar 11, 2018
1 parent 67a9271 commit e8a2599
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 17 deletions.
9 changes: 4 additions & 5 deletions lib/api/traversing.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,13 @@ exports.end = function() {

exports.add = function(other, context) {
var selection = this._make(other, context);
var contents = uniqueSort(selection.get().concat(this.get()));
var contents = uniqueSort(this.get().concat(selection.get()));

for (var i = 0; i < contents.length; ++i) {
selection[i] = contents[i];
this[i] = contents[i];
}
selection.length = contents.length;

return selection;
this.length = contents.length;
return this;
};

// Add the previous set of elements on the stack to the current set, optionally
Expand Down

0 comments on commit e8a2599

Please sign in to comment.