Closed
Description
const {tokenize} = require("@csstools/css-tokenizer"); // @csstools/css-tokenizer is a peer dependency.
var parser = require("@csstools/css-parser-algorithms")
const value = parser.parseComponentValue(tokenize({css: "foo(bar(baz))"}));
parser.replaceComponentValues([[value]], node => {
console.log(node);
if (parser.FunctionNode.isFunctionNode(node) && node.getName() === 'bar') {
return new parser.TokenNode(['ident-token', 'x', node.value[2], node.value[3], {value: 'x'}]);
}
});
(Runkit)
In line with other AST-walking and -replacement APIs, I would expect that if I replace a parent node in the AST, the replacement algorithm will stop traversing any of that node's children. (Note that this is how PostCSS's walk()
and replaceWith()
interact.) Instead, replaceComponentValues()
continues traversing the removed nodes. This is extra unnecessary work and can even cause data corruption if, for example, information is being stored about nodes encountered during the traversal.