JSPM

  • Created
  • Published
  • Downloads 29449
  • Score
    100M100P100Q147544F
  • License MIT

compare ast-nodes

Package Exports

  • @putout/compare

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/compare) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

putout-compare NPM version Dependency Status

Compare AST-nodes.

Install

npm i @putout/compare

API

Compare (node, baseNode)

  • node - AST-node or code that will be generated;
  • baseNode AST-node with support of template variables.

Supported template variables:

__

Any node.

compare('const x = data', 'const __ = __');
compare('const {x} = data', 'const __ = __');
compare('const x = {data}', 'const __ = __');
// returns
true
__object

ObjectPattern or ObjectExpression with any count of properties.

compare('const {} = data', 'const __object = __')
compare('const {hello} = data', 'const __object = __')
// returns
true
__array

ArrayPattern or ArrayExpression with any count of elements.

compare('const [] = data', 'const __array = __');
compare('const [hello] = data', 'const __array = __');
compare('const hello = [data]', 'const __ = __array');
// returns
true
__args

Any count of arguments:

compare('(a, b, c) => {}', '(__args) => {}');
compare('(a, b) => {}', '(__args) => {}');
compare('() => {}', '(__args) => {}');
// returns
true
"__"

Any string literal.

compare('const a = "hello"', 'const __ = "__"');

License

MIT