How to use @putout/engine-parser - 9 common examples

To help you get started, we’ve selected a few @putout/engine-parser 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 / compare / lib / compare.js View on Github external
function parseNode(a) {
    if (isStr(a))
        return template.ast(a);
    
    if (!a.node)
        return a;
    
    return a.node;
}
github coderaiser / putout / packages / compare / lib / compare.js View on Github external
function parseTemplate(tmpl) {
    const node = template.ast(tmpl);
    
    if (tmpl === '__object')
        return [node, __OBJECT_TYPE];
    
    if (tmpl === '__array')
        return [node, __ARRAY_TYPE];
    
    const {type} = node;
    
    return [node, type];
}
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;
github coderaiser / putout / packages / engine-loader / lib / transforms / jscodeshift.js View on Github external
const printAST = (a) => isStr(a) ? a : print(a);
const getFn = (a) => (...args) => {
github coderaiser / putout / packages / engine-loader / lib / wrap-plugin.js View on Github external
find(ast, {push}) {
            const oldCode = print(ast);
            transform(ast, oldCode, name);
            const newCode = print(ast);
            
            if (newCode === oldCode)
                return;
            
            const positions = getPositions(oldCode, newCode);
            for (const start of positions) {
                const node = {
                    loc: {
                        start,
                    },
                };
                
                const path = {
                    node,
github coderaiser / putout / packages / engine-loader / lib / wrap-plugin.js View on Github external
find(ast, {push}) {
            const oldCode = print(ast);
            transform(ast, oldCode, name);
            const newCode = print(ast);
            
            if (newCode === oldCode)
                return;
            
            const positions = getPositions(oldCode, newCode);
            for (const start of positions) {
                const node = {
                    loc: {
                        start,
                    },
                };
                
                const path = {
                    node,
                };
github coderaiser / putout / packages / putout / lib / putout.js View on Github external
const ast = parse(clearSource, {
        parser,
        isTS,
        isFlow,
        isJSX,
    });
    
    const places = transform(ast, source, opts);
    
    if (!opts.fix)
        return {
            code: source,
            places,
        };
    
    const printed = print(ast);
    const code = `${shebang}${printed}`;
    
    return {
        code,
        places,
    };
};
github coderaiser / putout / packages / putout / lib / putout.js View on Github external
module.exports = (source, opts) => {
    opts = defaultOpts(opts);
    const {
        parser,
        isTS,
        isFlow,
        isJSX,
    } = opts;
    
    const [clearSource, shebang] = cutShebang(source);
    const ast = parse(clearSource, {
        parser,
        isTS,
        isFlow,
        isJSX,
    });
    
    const places = transform(ast, source, opts);
    
    if (!opts.fix)
        return {
            code: source,
            places,
        };
    
    const printed = print(ast);
    const code = `${shebang}${printed}`;

@putout/engine-parser

🐊Putout parser

MIT
Latest version published 22 days ago

Package Health Score

73 / 100
Full package analysis