How to use the esotope-hammerhead.Syntax.ExpressionStatement 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 / js-protocol-last-expression.ts View on Github external
/*eslint-disable no-unused-vars*/
import { ExpressionStatement } from 'estree';
import { Transformer } from './index';
/*eslint-enable no-unused-vars*/
import { createHtmlProcessorWrapper } from '../node-builder';
import { Syntax } from 'esotope-hammerhead';

// Transform:
// x = 5; "hello" --> x = 5; parent.__proc$Html(window, "hello")
// someAction(); generateHtmlPage() --> someAction(); parent.__proc$Html(window, generateHtmlPage())

const transformer: Transformer = {
    nodeReplacementRequireTransform: true,

    nodeTypes: Syntax.ExpressionStatement,

    condition: (node, parent) => !!transformer.wrapLastExpr && !!parent && parent.type === Syntax.Program &&
                                 parent.body[parent.body.length - 1] === node,

    run: node => {
        transformer.wrapLastExpr = false;

        return createHtmlProcessorWrapper(node);
    }
};

export default transformer;
github DevExpress / testcafe-hammerhead / src / processing / script / index.ts View on Github external
function isStrictMode (ast: Program): boolean {
    if (ast.body.length) {
        const firstChild = ast.body[0];

        if (firstChild.type === Syntax.ExpressionStatement && firstChild.expression.type === Syntax.Literal)
            return firstChild.expression.value === 'use strict';
    }

    return false;
}
github DevExpress / testcafe-hammerhead / src / processing / script / node-builder.ts View on Github external
export function createAssignmentExprStmt (left: MemberExpression, right: Identifier): ExpressionStatement {
    return {
        type: Syntax.ExpressionStatement,

        expression: {
            type:     Syntax.AssignmentExpression,
            operator: '=',
            left:     left,
            right:    right
        }
    };
}
github DevExpress / testcafe-hammerhead / src / processing / script / index.ts View on Github external
function isArrayDataScript (ast: Program): boolean {
    const firstChild = ast.body[0];

    return ast.body.length === 1 &&
           firstChild.type === Syntax.ExpressionStatement &&
           firstChild.expression.type === Syntax.ArrayExpression;
}