npm.io
16.2.0 • Published 3 months ago

@putout/traverse

Licence
MIT
Version
16.2.0
Deps
2
Size
6 kB
Vulns
0
Weekly
0
Stars
796

@putout/traverse NPM version

Traverse AST-nodes

Install

npm i @putout/traverse

API

superTraverse
import {template} from '@putout/engine-parser';
import {superTraverse} from '@putout/traverse';

const node = template.ast('const a = b');

superTraverse(node, {
    'Identifier'(path) {
        console.log('found identifier');
    },
    
    'throw __a'(path, {__a}) {
        console.log(__a);
    },
    
    'await __'(path) {
        console.log('found await');
    },
    'for await (__ of __) __'(path) {
        console.log('found for-of');
    },
});
contains
import {template} from '@putout/engine-parser';
import {contains} from '@putout/traverse';

const node = template.ast('async () => await x');

contains(node, [
    'return __',
    'throw __',
    'await __',
    'for await (__ of __) __',
]);

// returns
true;

License

MIT

Keywords