How to use the ast-types.builders.expressionStatement function in ast-types

To help you get started, we’ve selected a few ast-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 probmods / webppl / src / transforms / stack.js View on Github external
function transformFnBody(node) {
  var addressParam = node.params[2];

  var bindAddress = build.variableDeclaration('var', [
    build.variableDeclarator(
        build.identifier(localVarName),
        addressParam)]);

  // Use member expression so that this isn't cps'd. Writing as an
  // assignment statement doesn't work as it is wrapped in a thunk and
  // returned early from the function.
  var saveAddress = build.expressionStatement(
      build.callExpression(
      build.memberExpression(
      build.identifier(saveAddressFn[0]),
      build.identifier(saveAddressFn[1])
      ), [
        build.identifier(globalVarName),
        addressParam]));

  var expr = build.functionExpression(
      node.id,
      node.params,
      build.blockStatement([bindAddress, saveAddress].concat(node.body.body))
      );
  expr.loc = node.loc;
  return expr;
}
github rainforestapp / decaf / src / parser.js View on Github external
function insertSuperCall(path) {
  const classMethods = get(path, 'value.body.body') || [];
  const constructorIndex = findIndex(classMethods, {kind: 'constructor'});
  if (constructorIndex > -1) {
    const superCalls = jsc(classMethods[constructorIndex])
      .find(jsc.CallExpression, {callee: {name: 'super'}})
      .nodes();
    if (superCalls.length < 1) {
      classMethods[constructorIndex]
        .value.body.body
        .unshift(
          b.expressionStatement(b.callExpression(b.identifier('super'), [])));
    }
  }
}
github rexxars / sql-to-graphql / steps / ast-builders / resolve-map.js View on Github external
function buildExportedFunc(opts, ast, name) {
    var func = (opts.es6 ? b.functionDeclaration : b.functionExpression)(
        b.identifier(name),
        [b.identifier('type')],
        b.blockStatement(ast)
    );

    if (opts.es6) {
        return [b.exportDeclaration(false, func)];
    }

    return [
        b.expressionStatement(b.assignmentExpression(
            '=',
            b.memberExpression(
                b.identifier('exports'),
                b.identifier(name),
                false
            ),
            func
        ))
    ];
}
github rexxars / sql-to-graphql / steps / ast-builders / type.js View on Github external
module.exports = function buildType(type, opts) {
    var imports = buildTypeImports(type, opts);
    var typeAst = type.ast;
    var typeExport = [buildExports(b.identifier(type.varName), opts)];
    var register = [b.expressionStatement(
        b.callExpression(
            b.identifier('registerType'),
            [b.identifier(type.varName)]
        )
    )];

    return b.program([]
        .concat(imports)
        .concat(typeAst)
        .concat(register)
        .concat(typeExport)
    );
};
github paeckchen / paeckchen / packages / paeckchen-core / src / plugins / es6-export.ts View on Github external
.map(specifier =>
      b.expressionStatement(
        b.assignmentExpression(
          '=',
          moduleExportsExpression(specifier.exported.name),
          b.memberExpression(
            b.memberExpression(
              tempIdentifier,
              b.identifier('exports'),
              false
            ),
            b.literal(specifier.local.name),
            true
          )
        )
      )
    );
github paeckchen / paeckchen / packages / paeckchen-core / src / modules.ts View on Github external
function wrapExternalModule(modulePath: string, context: PaeckchenContext): Promise {
  const external = context.config.externals[modulePath] === false
    ? b.objectExpression([])
    : b.identifier(context.config.externals[modulePath] as string);
  return Promise.resolve(b.program([
    b.expressionStatement(
      b.assignmentExpression(
        '=',
        b.memberExpression(
          b.identifier('module'),
          b.identifier('exports'),
          false
        ),
        external
      )
    )
  ]));
}
github probmods / webppl / src / transforms / stack.js View on Github external
function transformContinuation(node) {
  var saveAddress = build.expressionStatement(
      build.callExpression(
      build.memberExpression(
      build.identifier(saveAddressFn[0]),
      build.identifier(saveAddressFn[1])
      ), [
        build.identifier(globalVarName),
        build.identifier(localVarName)]));

  var expr = build.functionExpression(
      node.id,
      node.params,
      build.blockStatement([saveAddress].concat(node.body.body))
      );
  expr.loc = node.loc;
  return expr;
}
github probmods / webppl / src / transforms / cps.js View on Github external
function buildFunction(params, body, id) {
  return build.functionExpression(id || null, params,
                                  build.blockStatement([build.expressionStatement(body)]));
}
github probmods / webppl / src / syntax.js View on Github external
return function(node) {
    if (types.Program.check(node) &&
        node.body.length === 1 &&
        types.ExpressionStatement.check(node.body[0])) {
      return build.program([
        build.expressionStatement(f(node.body[0].expression))
      ]);
    }
    else {
      return failSafe('inProgram', fail);
    }
  };
}
github rainforestapp / decaf / src / parser.js View on Github external
return mapThrowStatement(node, meta);
  } else if (type === 'Comment') {
    return b.emptyStatement();
  } else if (type === 'For') {
    return mapForStatement(node, meta);
  } else if (type === 'Class') {
    return mapClassDeclaration(node, meta);
  } else if (type === 'Switch') {
    return addBreakStatementsToSwitch(mapSwitchStatement(node, meta));
  } else if (type === 'If') {
    return mapConditionalStatement(node, meta);
  } else if (type === 'Try') {
    return mapTryCatchBlock(node, meta);
  }

  return b.expressionStatement(mapExpression(node, meta));
}