How to use the babel-types.expressionStatement function in babel-types

To help you get started, we’ve selected a few babel-types 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 facebook / prepack / src / serializer / ResidualReactElementSerializer.js View on Github external
reactElement: ObjectValue,
    id: BabelNodeExpression,
    reactElementAst: BabelNodeExpression,
    hoistedCreateElementIdentifier: BabelNodeIdentifier,
    originalCreateElementIdentifier: BabelNodeIdentifier
  ) {
    // if the currentHoistedReactElements is not defined, we create it an emit the function call
    // this should only occur once per additional function
    if (this._lazilyHoistedNodes === undefined) {
      let funcId = t.identifier(this.residualHeapSerializer.functionNameGenerator.generate());
      this._lazilyHoistedNodes = {
        id: funcId,
        createElementIdentifier: hoistedCreateElementIdentifier,
        nodes: [],
      };
      let statement = t.expressionStatement(
        t.logicalExpression(
          "&&",
          t.binaryExpression("===", id, t.unaryExpression("void", t.numericLiteral(0), true)),
          // pass the createElementIdentifier if it's not null
          t.callExpression(funcId, originalCreateElementIdentifier ? [originalCreateElementIdentifier] : [])
        )
      );
      let optimizedFunction = this.residualHeapSerializer.isReferencedOnlyByOptimizedFunction(reactElement);
      this.residualHeapSerializer.getPrelude(optimizedFunction).push(statement);
    }
    // we then push the reactElement and its id into our list of elements to process after
    // the current additional function has serialzied
    invariant(this._lazilyHoistedNodes !== undefined);
    invariant(Array.isArray(this._lazilyHoistedNodes.nodes));
    this._lazilyHoistedNodes.nodes.push({ id, astNode: reactElementAst });
  }
github babel / babel / packages / babel-core / src / transformation / modules / system.js View on Github external
if (node.kind !== "var" && !t.isProgram(parent)) { // let, const
      // can't be accessed
      return;
    }

    // ignore block hoisted nodes as these can be left in
    if (state.formatter._canHoist(node)) return;

    let nodes = [];

    for (let i = 0; i < node.declarations.length; i++) {
      let declar = node.declarations[i];
      state.hoistDeclarators.push(t.variableDeclarator(declar.id));
      if (declar.init) {
        // no initializer so we can just hoist it as-is
        let assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
        nodes.push(assign);
      }
    }

    // for (let i in test)
    if (t.isFor(parent) && parent.left === node) {
      return node.declarations[0].id;
    }

    return nodes;
  }
};
github babel / babel / packages / babel-helper-replace-supers / src / index.js View on Github external
specHandleAssignmentExpression(ref, path, node) {
    if (node.operator === "=") {
      // super.name = "val"; -> _set(Object.getPrototypeOf(objectRef.prototype), "name", this);
      return this.setSuperProperty(node.left.property, node.right, node.left.computed);
    } else {
      // super.age += 2; -> let _ref = super.age; super.age = _ref + 2;
      ref = ref || path.scope.generateUidIdentifier("ref");
      return [
        t.variableDeclaration("var", [
          t.variableDeclarator(ref, node.left)
        ]),
        t.expressionStatement(
          t.assignmentExpression("=", node.left, t.binaryExpression(node.operator[0], ref, node.right))
        )
      ];
    }
  }
github babel / babel / packages / babel-plugin-transform-regenerator / src / hoist.js View on Github external
exit: function(path) {
        let expr = varDeclToExpr(path.node, false);
        if (expr === null) {
          path.remove();
        } else {
          // We don't need to traverse this expression any further because
          // there can't be any new declarations inside an expression.
          path.replaceWith(t.expressionStatement(expr));
        }

        // Since the original node has been either removed or replaced,
        // avoid traversing it any further.
        path.skip();
      }
    },
github babel / babel / packages / babel-plugin-transform-regenerator / src / hoist.js View on Github external
FunctionDeclaration: function(path) {
      let node = path.node;
      vars[node.id.name] = node.id;

      let assignment = t.expressionStatement(
        t.assignmentExpression(
          "=",
          node.id,
          t.functionExpression(
            node.id,
            node.params,
            node.body,
            node.generator,
            node.expression
          )
        )
      );

      if (path.parentPath.isBlockStatement()) {
        // Insert the assignment form before the first statement in the
        // enclosing block.
github plasma-umass / Stopify / src / cpsVisitor.ts View on Github external
exit(path) {
            const { body } = path.node;
            const bodyPath = path.get('body.0');
            const newBody = t.expressionStatement(foldSequence(bodyPath, body));
            newBody.cps = true;
            path.node.body = [newBody];
        },
    },
github trivago / melody / packages / melody-plugin-idom / src / visitors / idom.js View on Github external
const isSelfClosing = el.selfClosing || !el.children.length;
    let openElementCall = elementOpen(
        state,
        isSelfClosing ? 'elementVoid' : 'elementOpen',
        el.name,
        key,
        staticId,
        attributes
    );
    if (isSelfClosing && ref) {
        openElementCall = t.callExpression(
            t.identifier(state.addImportFrom('melody-idom', 'ref')),
            [ref, openElementCall]
        );
    }
    replacements.push(t.expressionStatement(openElementCall));
}
github suchipi / run-on-server / packages / babel-plugin / src / IdMappingsFile.js View on Github external
_build(mappings) {
    const outputContent = t.expressionStatement(
      t.assignmentExpression(
        "=",
        t.memberExpression(t.identifier("module"), t.identifier("exports")),
        t.objectExpression(
          Object.keys(mappings).map((key) => {
            const valueNode = mappings[key];
            const keyNode = t.stringLiteral(key);

            return t.objectProperty(keyNode, valueNode);
          })
        )
      )
    );

    const comment =
      "\n" +
github plasma-umass / Stopify / hygiene / ts / useGlobalObject.ts View on Github external
function setGlobal(global: t.Expression, name: t.Identifier, expr: t.Expression): t.Statement {
  return t.expressionStatement(
    t.assignmentExpression('=',
      t.memberExpression(global, name, false),
      expr));
}
github plasma-umass / Stopify / src / callcc / toModule.ts View on Github external
function fakeModule(path: NodePath) {
  const isStop = t.identifier("$isStop");
  const onStop = t.identifier("$onStop");
  const onDone = t.identifier("$onDone");
  const opts = t.identifier("$opts");

  path.node.body.push(t.returnStatement(t.callExpression(onDone, [])));

  path.node.body = [t.expressionStatement(
    t.assignmentExpression(
      '=',
      t.memberExpression(t.identifier('module'), t.identifier('exports')),
      t.functionExpression(
        void 0,
        [isStop, onStop, onDone, opts], 
        t.blockStatement(path.node.body))))];
}
const visitor: Visitor = {