How to use @putout/compare - 4 common examples

To help you get started, we’ve selected a few @putout/compare examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github coderaiser / putout / packages / engine-runner / lib / template / index.js View on Github external
return (path) => {
        log(rule, path.node);
        
        if (nodesExclude.length && compareAny(path, nodesExclude))
            return;
        
        if (nodesInclude.length && !compareAll(path, nodesInclude))
            return;
        
        fn(path);
    };
}
github coderaiser / putout / packages / engine-runner / lib / replace.js View on Github external
const fix = (from, to, path) => {
    const nodeFrom = template.ast(from);
    const watermark = `${from} -> ${to}`;
    
    path._putout = path._putout || [];
    
    if (path._putout.includes(watermark))
        return;
    
    if (!compare(path, nodeFrom))
        return;
    
    if (!to)
        return path.remove();
    
    const nodeTo = template.ast.fresh(to);
    const {node} = path;
    
    const waysFrom = findVarsWays(nodeFrom);
    const waysTo = findVarsWays(nodeTo);
    const values = getValues({
        waysFrom,
        node,
    });
    
    replaceWith(path, nodeTo);
github coderaiser / putout / packages / engine-runner / lib / template / index.js View on Github external
return (path) => {
        log(rule, path.node);
        
        if (nodesExclude.length && compareAny(path, nodesExclude))
            return;
        
        if (nodesInclude.length && !compareAll(path, nodesInclude))
            return;
        
        fn(path);
    };
}
github coderaiser / putout / packages / engine-runner / lib / template / index.js View on Github external
const entries = Object.entries(visitor);
    const nodesExclude = maybeArray(options.exclude);
    const nodesInclude = maybeArray(options.include);
    
    for (const [tmpl, fn] of entries) {
        if (!isTemplate(tmpl)) {
            parsed.push(exclude({
                rule,
                tmpl,
                fn,
                nodesExclude,
            }));
            continue;
        }
        
        const [node, type] = parseTemplate(tmpl);
        const visit = wrapWithCheck({
            rule,
            fn,
            nodesExclude,
            nodesInclude: [
                node,
                ...nodesInclude,
            ],
        });
        
        parsed.push({
            [type]: visit,
        });
    }
    
    return parsed;

@putout/compare

compare AST-nodes according to 🦎 PutoutScript

MIT
Latest version published 1 month ago

Package Health Score

83 / 100
Full package analysis