Repository navigation
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.
Problem
before()andafter()drop the node when it's one of their own arguments:i.before(i, 'x')loses the node the same way.replaceWith()already handles this case.asFragment()moves every argument into a fragment, which takesnodeout of its parent.before()then inserts the fragment beforenode, which is now inside the fragment.after()inserts it before the end ofnoderead after the move.Fix
This follows the DOM spec's "viable previous sibling" and "viable next sibling" steps. The insertion point is the nearest sibling that isn't one of the arguments, and it's looked up before the arguments are moved. For
before(), the reference is that sibling's next sibling, or the parent's first child when there isn't one. Forafter(), it's the next sibling that isn't moved, ornullto append.Tests
The new assertions in
test/html/element.jscover the node itself among the arguments, moving the adjacent sibling, and the case where no viable sibling is left. They fail without the change (Expected: <div>ax<i></i>b</div>,Got instead: <div>ab</div>). I checked every expected string by running the same calls in Chrome.npm testpasses, with coverage still at 100% statements/branches/lines (the same asmain).cjs/is regenerated withnpm run cjs.