putout-compare
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 __ = __');
true
__object
ObjectPattern
or ObjectExpression
with any count of properties
.
compare('const {} = data', 'const __object = __')
compare('const {hello} = data', 'const __object = __')
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');
true
__args
Any count of arguments
:
compare('(a, b, c) => {}', '(__args) => {}');
compare('(a, b) => {}', '(__args) => {}');
compare('() => {}', '(__args) => {}');
true
"__"
Any string literal.
compare('const a = "hello"', 'const __ = "__"');
License
MIT