How to use the esotope-hammerhead.Syntax.ForInStatement function in esotope-hammerhead

To help you get started, we’ve selected a few esotope-hammerhead 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 DevExpress / testcafe-hammerhead / src / processing / script / transformers / for-in.ts View on Github external
import {
    createTempVarIdentifier,
    createAssignmentExprStmt,
    createVarDeclaration,
    createBlockExprStmt
} from '../node-builder';
import replaceNode from './replace-node';

// Transform:
// for(obj[prop] in src), for(obj.prop in src) -->
// for(const __set$temp in src) { obj[prop] = __set$temp; }

export default {
    nodeReplacementRequireTransform: false,

    nodeTypes: [Syntax.ForInStatement],

    condition: node => node.left.type === Syntax.MemberExpression,

    run: node => {
        const tempVarAst         = createTempVarIdentifier();
        const varDeclaration     = createVarDeclaration(tempVarAst);
        const assignmentExprStmt = createAssignmentExprStmt(node.left, tempVarAst);

        if (node.body.type !== Syntax.BlockStatement)
            replaceNode(node.body, createBlockExprStmt([assignmentExprStmt, node.body]), node, 'body');
        else
            replaceNode(null, assignmentExprStmt, node.body, 'body');

        replaceNode(node.left, varDeclaration, node, 'left');

        return null;
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / computed-property-get.ts View on Github external
return false;

        // object[prop]++ || object[prop]-- || ++object[prop] || --object[prop]
        if (parent.type === Syntax.UpdateExpression && parent.operator === '++' || parent.operator === '--')
            return false;

        // object[prop]()
        if (parent.type === Syntax.CallExpression && parent.callee === node)
            return false;

        // new (object[prop])() || new (object[prop])
        if (parent.type === Syntax.NewExpression && parent.callee === node)
            return false;

        // for(object[prop] in source)
        if (parent.type === Syntax.ForInStatement && parent.left === node)
            return false;

        return true;
    },
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / property-get.ts View on Github external
return false;

        // Skip: object.prop()
        if (parent.type === Syntax.CallExpression && parent.callee === node)
            return false;

        // Skip: object.prop++ || object.prop-- || ++object.prop || --object.prop
        if (parent.type === Syntax.UpdateExpression && parent.operator === '++' || parent.operator === '--')
            return false;

        // Skip: new (object.prop)() || new (object.prop)
        if (parent.type === Syntax.NewExpression && parent.callee === node)
            return false;

        // Skip: for(object.prop in source)
        if (parent.type === Syntax.ForInStatement && parent.left === node)
            return false;

        return true;
    },
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / location-property-get.ts View on Github external
condition: (node, parent) => {
        // Skip: for(location.field in obj)
        if (parent && parent.type === Syntax.ForInStatement && parent.left === node)
            return false;

        return node.object.type === Syntax.Identifier && node.object.name === 'location';
    },