How to use the esotope-hammerhead.Syntax.CallExpression 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 / computed-property-get.ts View on Github external
return false;

        // object[prop] = value
        if (parent.type === Syntax.AssignmentExpression && parent.left === node)
            return false;

        // delete object[prop]
        if (parent.type === Syntax.UnaryExpression && parent.operator === 'delete')
            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 / method-call.ts View on Github external
// WARNING: this file is used by both the client and the server.
// Do not use any browser or node-specific API!
// -------------------------------------------------------------

import { createStringLiteral, createMethCallWrapper } from '../node-builder';
import { Syntax } from 'esotope-hammerhead';
import { shouldInstrumentMethod } from '../instrumented';

// Transform:
// obj.method(args...); obj[method](args...); -->
// _call$(obj, 'method', args...); _call$(obj, method, args...);

export default {
    nodeReplacementRequireTransform: true,

    nodeTypes: [Syntax.CallExpression],

    condition: node => {
        const callee = node.callee;

        if (callee.type === Syntax.MemberExpression) {
            if (callee.computed)
                return callee.property.type === Syntax.Literal ? shouldInstrumentMethod(callee.property.value) : true;

            return shouldInstrumentMethod(callee.property.name);
        }

        return false;
    },

    run: node => {
        const callee = node.callee;
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / location-get.ts View on Github external
// Skip: { location: value }
        if (parent.type === Syntax.Property && parent.key === node)
            return false;

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

        // Skip: function (location) { ... } || function func(location) { ... } || location => { ... }
        if ((parent.type === Syntax.FunctionExpression || parent.type === Syntax.FunctionDeclaration ||
             parent.type === Syntax.ArrowFunctionExpression) && parent.params.indexOf(node) !== -1)
            return false;

        // Skip already transformed: __get$Loc(location)
        if (parent.type === Syntax.CallExpression && parent.callee.type === Syntax.Identifier &&
            parent.callee.name === INSTRUCTION.getLocation)
            return false;

        // Skip: class X { location () {} }
        if (parent.type === Syntax.MethodDefinition)
            return false;

        // Skip: class location { x () {} }
        if (parent.type === Syntax.ClassDeclaration)
            return false;

        // Skip: function x (...location) {}
        if (parent.type === Syntax.RestElement)
            return false;

        return true;
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / eval-bind.ts View on Github external
// WARNING: this file is used by both the client and the server.
// Do not use any browser or node-specific API!
// -------------------------------------------------------------

import { createGetEvalMethCall } from '../node-builder';
import { Syntax } from 'esotope-hammerhead';
import replaceNode from './replace-node';

// Transform:
// foo = eval.bind(...); -->
// foo = __get$Eval(eval).bind(...);

export default {
    nodeReplacementRequireTransform: false,

    nodeTypes: [Syntax.CallExpression],

    condition: node => {
        if (node.callee.type === Syntax.MemberExpression && node.callee.property.name === 'bind') {
            const obj = node.callee.object;

            // obj.eval.bind(), obj[eval].bind(),
            if (obj.type === Syntax.MemberExpression && (obj.property.value || obj.property.name) === 'eval')
                return true;

            // eval.bind()
            if (obj.name === 'eval')
                return true;
        }

        return false;
    },
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / eval-get.ts View on Github external
condition: (node, parent) => {
        if (node.name === 'eval' && parent) {
            // Skip: eval()
            if (parent.type === Syntax.CallExpression && parent.callee === node)
                return false;

            // Skip: class X { eval () {} }
            if (parent.type === Syntax.MethodDefinition)
                return false;

            // Skip: class eval { x () {} }
            if (parent.type === Syntax.ClassDeclaration)
                return false;

            // Skip: window.eval, eval.call
            if (parent.type === Syntax.MemberExpression)
                return false;

            // Skip: function eval () { ... }
            if ((parent.type === Syntax.FunctionExpression || parent.type === Syntax.FunctionDeclaration) &&
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / dynamic-import.ts View on Github external
import { CallExpression } from 'estree';
import { Transformer } from './index';
/*eslint-enable no-unused-vars*/
import { createGetProxyUrlMethCall } from '../node-builder';
import { Syntax } from 'esotope-hammerhead';
import replaceNode from './replace-node';

// Transform:
// import(something).then()
// -->
// import(__get$ProxyUrl(something)).then()

const transformer: Transformer = {
    nodeReplacementRequireTransform: true,

    nodeTypes: Syntax.CallExpression,

    // @ts-ignore
    condition: node => node.callee.type === Syntax.Import,

    run: node => {
        const newArgs = createGetProxyUrlMethCall(node.arguments[0], transformer.baseUrl);

        replaceNode(node.arguments[0], newArgs, node, 'arguments');

        return null;
    }
};

export default transformer;
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / window-post-message-get.ts View on Github external
return false;

        // Skip: window.postMessage.field
        if (parent.type === Syntax.MemberExpression && (parent.property === node || parent.object === node))
            return false;

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

        // Skip: window.postMessage = 1, window["postMessage"] = 1
        if (parent.type === Syntax.AssignmentExpression && parent.left === node)
            return false;

        // Skip already transformed: __get$PostMessage(window.postMessage), __get$PostMessage(window["postMessage"])
        if (parent.type === Syntax.CallExpression && parent.callee.type === Syntax.Identifier &&
            parent.callee.name === INSTRUCTION.getPostMessage)
            return false;

        // window.postMessage
        if (node.property.type === Syntax.Identifier && node.property.name === 'postMessage')
            return true;

        // window['postMessage']
        if (node.property.type === Syntax.Literal && node.property.value === 'postMessage')
            return true;

        return false;
    },
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / eval-get.ts View on Github external
// Skip: eval = value || function x (eval = value) { ... }
            if ((parent.type === Syntax.AssignmentExpression || parent.type === Syntax.AssignmentPattern) &&
                parent.left === node)
                return false;

            // Skip: const eval = value;
            if (parent.type === Syntax.VariableDeclarator && parent.id === node)
                return false;

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

            // Skip already transformed: __get$Eval(eval)
            if (parent.type === Syntax.CallExpression && parent.callee.type === Syntax.Identifier &&
                parent.callee.name === INSTRUCTION.getEval)
                return false;

            // Skip: function x (...eval) {}
            if (parent.type === Syntax.RestElement)
                return false;

            return true;
        }

        return false;
    },
github DevExpress / testcafe-hammerhead / src / processing / script / node-builder.ts View on Github external
export function createGetEvalMethCall (node: Expression): CallExpression {
    return {
        type: Syntax.CallExpression,

        callee: {
            type: Syntax.Identifier,
            name: INSTRUCTION.getEval
        },

        arguments: [node]
    };
}