How to use the esotope-hammerhead.Syntax.Literal 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-post-message-get.ts View on Github external
// 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 / static-import.ts View on Github external
/*eslint-disable no-unused-vars*/
import { Transformer } from './index';
import { Literal } from 'estree';
/*eslint-enable no-unused-vars*/
import { getProxyUrlLiteral } from '../node-builder';
import { Syntax } from 'esotope-hammerhead';

// Transform:
// import something from 'url';   -->   import something from 'processed-url';
// export * from 'url';   -->   export * from 'processed-url';
// export { x as y } from 'url';   -->   export { x as y } from 'processed-url';

const transformer: Transformer = {
    nodeReplacementRequireTransform: false,

    nodeTypes: Syntax.Literal,

    condition: (node, parent) => !!parent && (parent.type === Syntax.ImportDeclaration ||
                                              parent.type === Syntax.ExportAllDeclaration ||
                                              parent.type === Syntax.ExportNamedDeclaration) && parent.source === node,

    run: node => transformer.resolver ? getProxyUrlLiteral(node, transformer.resolver) : null
};

export default transformer;
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / computed-property-set.ts View on Github external
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;
    },
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / window-eval-get.ts View on Github external
// 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-get.ts View on Github external
condition: (node, parent) => {
        if (!node.computed)
            return false;

        if (node.property.type === Syntax.Literal && !shouldInstrumentProperty(node.property.value))
            return false;

        // super[prop]
        if (node.object.type === Syntax.Super)
            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 === '--')
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / eval.ts View on Github external
condition: node => {
        if (!node.arguments.length)
            return false;

        const callee = node.callee;

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

        // obj.eval(), obj['eval'](),
        return callee.type === Syntax.MemberExpression &&
               (callee.property.type === Syntax.Identifier && callee.property.name ||
                callee.property.type === Syntax.Literal && callee.property.value) === 'eval';
    },
github DevExpress / testcafe-hammerhead / src / processing / script / transformers / method-call.ts View on Github external
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;
    },
github DevExpress / testcafe-hammerhead / src / processing / script / node-builder.ts View on Github external
export function createGetProxyUrlMethCall (arg: Expression | SpreadElement, baseUrl?: string): CallExpression {
    const args = [arg];

    if (baseUrl) {
        args.push({
            type:  Syntax.Literal,
            value: baseUrl,
            raw:   `"${baseUrl}"`
        });
    }

    return {
        type: Syntax.CallExpression,

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

        arguments: args
    };
}