How to use the ast-types.builders.functionExpression 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
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 probmods / webppl / src / transforms / store.js View on Github external
function store(node) {
  switch (node.type) {
    // have to add the store argument to each function
    case Syntax.FunctionExpression:
      return build.functionExpression(node.id,
          [storeIdNode].concat(node.params),
          node.body);

    // pass the store variable at each call (that isn't primitive)
    case Syntax.CallExpression:
      if (isPrimitive(node.callee)) {
        return node;
      }
      else if (node.arguments.length > 0 &&
          node.arguments[0].type === 'Identifier' &&
          node.arguments[0].name === 'globalStore') {
        return node;
      }
      else {
        return build.callExpression(node.callee,
            [storeIdNode].concat(node.arguments));
github probmods / webppl / src / transforms / naming.js View on Github external
function naming(node) {
  switch (node.type) {
    case Syntax.FunctionExpression:
      return build.functionExpression(node.id,
          [addresses.shift()].concat(node.params),
          node.body);

    // add a gensym onto the address variable
    case Syntax.CallExpression:
      if (isPrimitive(node.callee)) {
        return node;
      } else {
        return build.callExpression(node.callee,
            [makeAddressExtension(addresses[0])].concat(node.arguments));
      }

    default:
  }
}
github GothAck / javascript-x-server / autogen / lib / misc.js View on Github external
addMethod(name, args, body) {
    this.body.push(b.methodDefinition(
      'method',
      b.identifier(name),
      b.functionExpression(
        null,
        args,
        b.blockStatement(body))));
  }
github probmods / webppl / src / transforms / cps.js View on Github external
clause(Syntax.DebuggerStatement, function() {
      var body = build.blockStatement([node]);
      return metaK(buildCall(build.functionExpression(null, [], body), []));
    })
github paeckchen / paeckchen / packages / paeckchen-core / src / modules.ts View on Github external
.then(mtime => {
      return {
        index,
        name,
        ast: b.functionExpression(
          b.identifier(`_${index}`),
          [
            b.identifier('module'),
            b.identifier('exports')
          ],
          b.blockStatement(
            moduleAst.body as ESTree.Statement[]
          )
        ),
        remove: false,
        mtime
      };
    });
}
github probmods / webppl / src / syntax.js View on Github external
function thunkify(node, fail) {
  if (types.Program.check(node)) {
    return build.program([
      build.expressionStatement(
          build.functionExpression(
          null,
          [],
          build.blockStatement(returnify(node.body))
          )
      )
    ]);
  }
  else {
    return failSafe('thunkify', fail);
  }
}
github probmods / webppl / src / transforms / trampoline.js View on Github external
function thunkify(node) {
  return build.functionExpression(
      null, [],
      build.blockStatement([
        build.returnStatement(node)
      ]), false, false);
}