Operate
operate
provide you a way to manipulate path
nodes and keep comments
and loc
information.
Install
npm i @putout/operate
If you write plugin for putout
you already have operate
in putout
, all exampes will get operate
from putout
, but you can use direct require('@putout/operate')
as well.
API
replaceWith(path, node)
const {replaceWith} = require('putout').operate;
replaceWith(path, ContinueStatement);
replaceWithMultiple(path, nodes)
const {replaceWithMultiple} = require('putout').operate;
replaceWith(path, [
ExpressionStatement(path.node.argument),
ContinueStatement,
]);
isModuleExports(path)
Check if currentPath is module.exports
expression.
toExpression(node)
Can be used to convert node to expression
when building new nodes.
remove(path)
Remove node
, preserve comments.
License
MIT