JSPM

  • Created
  • Published
  • Downloads 27134
  • Score
    100M100P100Q149222F
  • License MIT

operate on ast

Package Exports

  • @putout/operate

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@putout/operate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Operate NPM version Dependency Status Build Status Coverage Status

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.

getPathAfterImports(body)

Get next path after latest ImportDeclaration:

const programPath =  path.scope.getProgramParent().path;
const afterImportsPath = getPathAfterImports(programPath.get('body'));

License

MIT