Closed
Description
In my opinion, this should be working:
await visit( tree, 'code', visitor )
function visitor( node, index, parent ) {
return new Promise( resolve => {
const removeNode = () => {
parent.children.splice( index, 1 );
resolve()
}
setTimeout( removeNode, 10 );
})
}
Another (more abstract) example:
await visit( tree, 'code', visitor )
async function visitor( node, index, parent ) {
node.value = await someAsyncStuff();
}
Background
Visitor might do:
- read a node
- perform an action based on the node value/props (reading/writing files, do a HTTP request, ...)
- modify the tree based on the result of async operation
However, currently, only sync operations are allowed. That's why it cannot be used for async transformers, which should be supported by unified.