How to use the esotope-hammerhead.Syntax.AssignmentExpression 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 / window-eval-get.ts View on Github external
condition: (node, parent) => {
        if (!parent)
            return false;

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

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

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

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

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

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

        return false;
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / computed-property-set.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 { createComputedPropertySetWrapper } from '../node-builder';
import { Syntax } from 'esotope-hammerhead';
import { shouldInstrumentProperty } from '../instrumented';

// Transform:
// obj[prop] = value -->
// __set$(object, prop, value)

export default {
    nodeReplacementRequireTransform: true,

    nodeTypes: [Syntax.AssignmentExpression],

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

        // super[prop] = value
        if (left.type === Syntax.MemberExpression && left.object.type === Syntax.Super)
            return false;

        if (node.operator === '=' && left.type === Syntax.MemberExpression && left.computed)
            return left.property.type === Syntax.Literal ? shouldInstrumentProperty(left.property.value) : true;

        return false;
    },

    run: node => createComputedPropertySetWrapper(node.left.property, node.left.object, node.right)
};
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / property-set.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 { createPropertySetWrapper } from '../node-builder';
import { Syntax } from 'esotope-hammerhead';
import { shouldInstrumentProperty } from '../instrumented';

// Transform:
// obj. = value -->
// __set$(obj, '', value)

export default {
    nodeReplacementRequireTransform: true,

    nodeTypes: [Syntax.AssignmentExpression],

    condition: node => {
        // super.prop = value
        if (node.left.type === Syntax.MemberExpression && node.left.object.type === Syntax.Super)
            return false;

        return node.operator === '=' &&
               node.left.type === Syntax.MemberExpression && !node.left.computed &&
               node.left.property.type === Syntax.Identifier &&
               shouldInstrumentProperty(node.left.property.name);
    },

    run: node => createPropertySetWrapper(node.left.property.name, node.left.object, node.right)
};
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / location-set.ts View on Github external
/*eslint-disable no-unused-vars*/
import { AssignmentExpression } from 'estree';
import { Transformer } from './index';
/*eslint-enable no-unused-vars*/
import { createLocationSetWrapper } from '../node-builder';
import { Syntax } from 'esotope-hammerhead';

// Transform:
// location = value -->
// (function(){ return __set$Loc(location, value) || location = value;}.apply(this))

const transformer: Transformer = {
    nodeReplacementRequireTransform: false,

    nodeTypes: Syntax.AssignmentExpression,

    condition: node => node.operator === '=' && node.left.type === Syntax.Identifier && node.left.name === 'location',

    run: (node, parent, key) => {
        if (!parent)
            return null;

        const wrapWithSequence = key !== 'arguments' && key !== 'consequent' && key !== 'alternate' &&
                                 // @ts-ignore
                                 (parent.type !== Syntax.SequenceExpression || parent.expressions[0] === node);

        return createLocationSetWrapper(node.right, wrapWithSequence);
    }
};

export default transformer;
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / concat-operator.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 { createExpandedConcatOperation } from '../node-builder';
import { Syntax } from 'esotope-hammerhead';

// Transform:
// val1 += val2
// --> val1 = val1 + val2

export default {
    nodeReplacementRequireTransform: true,

    nodeTypes: [Syntax.AssignmentExpression],

    condition: node => node.operator === '+=',

    run: node => createExpandedConcatOperation(node.left, node.right)
};
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / window-post-message-get.ts View on Github external
condition: (node, parent) => {
        if (!parent)
            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 / property-get.ts View on Github external
condition: (node, parent) => {
        if (node.computed)
            return false;

        if (!shouldInstrumentProperty(node.property.name))
            return false;

        // Skip: super.prop
        if (node.object.type === Syntax.Super)
            return false;

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

        // Skip: delete object.prop
        if (parent.type === Syntax.UnaryExpression && parent.operator === 'delete')
            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)
github DevExpress / testcafe-hammerhead / src / processing / script / node-builder.ts View on Github external
type:     Syntax.LogicalExpression,
                                operator: '||',

                                left: {
                                    type: Syntax.CallExpression,

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

                                    arguments: [locationIdentifier, tempIdentifier]
                                },

                                right: {
                                    type:     Syntax.AssignmentExpression,
                                    operator: '=',
                                    left:     locationIdentifier,
                                    right:    tempIdentifier
                                }
                            }
                        }
                    ]
                },

                generator: false
            },

            property: {
                type: Syntax.Identifier,
                name: 'call'
            }