Node.before() inserts after if the new node is already a sibling
See original GitHub issueconst postcss = require("postcss");
const root = postcss.parse("@foo; @bar; @baz");
const foo = root.nodes[0];
const baz = root.nodes[2];
baz.before(foo);
root.toString(); // expected: "@bar; @foo; @baz"
// actually: "@bar; @baz; @foo"
It looks like the index calculation gets stale once the new node is removed from its original location.
Issue Analytics
- State:
- Created a year ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Node.insertBefore() - Web APIs | MDN
The insertBefore() method of the Node interface inserts a node before a reference node as a child of a specified parent node.
Read more >JavaScript insertAfter(): Insert a new node before an existing ...
First, select the next sibling node of the existing node. · Then, select the parent node of the existing node and call the...
Read more >How to insert an element after another element in JavaScript ...
If there the reference Node has a sibling after, then the new Node is inserted before that sibling; Returns the new Node. Extending...
Read more >JavaScript Insert After: How To Use These Methods Successfully
Insert after in JavaScript is a method of inserting a new node after the existing node (parent node) is not supported by the...
Read more >HTML DOM Element insertBefore Method - W3Schools
HTML DOM Element insertBefore() The insertBefore() method inserts a child node before an existing child.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, it could be dangerous.
It is better to call
remove()
in plugin.Sorry, I need to ask a help with research and PR.
I am spending all my free resources helping people affected by war.