How to use the ast-types.builders.identifier 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 GothAck / javascript-x-server / autogen / lib / enums.js View on Github external
for (let _enum of doc.find('enum')) {
    let name = _enum.attr('name').value();
    let values = new Map();
    let bits = new Map();

    if (name === 'Atom') {
      // TODO: Bojizzle the Atom Enum
      console.error('TODO: Implement Atom Enum');
      continue;
    }

    var parent_klass = `${_enum.find('*/bit').length ? 'Bit' : 'Value'}Enum`;

    var enum_klass = klasses.newClass(`${name}Enum`, parent_klass);
    enums.set(name, b.identifier(enum_klass.name));

    for (let item of _enum.find('item')) {
      let item_name = item.attr('name').value();
      let child = item.get('*');

      if (!child) {
        console.error('Enum item without a child, wut?!', item_name);
        continue;
      }
      let item_value = parseInt(child.text());

      switch (child.name()) {
        case 'value':
          values.set(item_value, item_name);
          break;
        case 'bit':
github probmods / webppl / src / transforms / stack.js View on Github external
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 GothAck / javascript-x-server / autogen / lib / misc.js View on Github external
__addSymMethod(name, callname, read) {
    var callArguments = [];
    if (!read) {
      callArguments = [b.spreadElement(b.identifier('arguments'))];
    }
    this.addMethod(
      name,
      [],
      [(read ? b.returnStatement : b.expressionStatement)(b.callExpression(
        b.memberExpression(
          b.thisExpression(),
          b.identifier(callname)),
        callArguments
        ))]);
  }
github GothAck / javascript-x-server / autogen / lib / misc.js View on Github external
gen() {
    var extend = null;
    if (this.extend) {
      extend = b.identifier(this.extend);
    }
    return b.classDeclaration(
      b.identifier(this.name),
      b.classBody(this.body),
      extend,
      []);
  }
}
github rexxars / sql-to-graphql / steps / ast-builders / type-imports.js View on Github external
[b.variableDeclarator(
                    b.identifier('connectionArgs'),
                    b.memberExpression(
                        b.identifier('GraphQLRelay'),
                        b.identifier('connectionArgs'),
                        false
                    )
                )]
            ));
        }
    }

    declarations.push(
        b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('getType'),
                b.memberExpression(
                    b.identifier('resolveMap'),
                    b.identifier('getType'),
                    false
                )
            )]
        )
    );

    declarations.push(
        b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('registerType'),
                b.memberExpression(
                    b.identifier('resolveMap'),
                    b.identifier('registerType'),
github rexxars / sql-to-graphql / steps / generate-types.js View on Github external
function generateLimitOffsetArgs() {
        return b.property('init', b.identifier('args'), b.objectExpression([
            b.property('init', b.identifier('limit'), b.objectExpression([
                b.property('init', b.identifier('name'), b.literal('limit')),
                b.property('init', b.identifier('type'), b.identifier('GraphQLInt'))
            ])),
            b.property('init', b.identifier('offset'), b.objectExpression([
                b.property('init', b.identifier('name'), b.literal('offset')),
                b.property('init', b.identifier('type'), b.identifier('GraphQLInt'))
            ]))
        ]));
    }
github rexxars / sql-to-graphql / steps / ast-builders / resolve-map.js View on Github external
b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('GraphQLRelay'),
                b.callExpression(
                    b.identifier('require'),
                    [b.literal('graphql-relay')]
                )
            )]
        ),

        b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('connectionDefinitions'),
                b.memberExpression(
                    b.identifier('GraphQLRelay'),
                    b.identifier('connectionDefinitions'),
                    false
                )
            )]
        )
    ];
}
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 rainforestapp / decaf / src / parser.js View on Github external
} else {
    statements.push(b.variableDeclaration(
      'var',
      [b.variableDeclarator(
        expr,
        arg
      )]
    ));
  }

  if (node.value !== undefined && node.value !== null) {
    statements.push(b.ifStatement(
      b.binaryExpression(
        '===',
        arg,
        b.identifier('undefined')
      ),
      b.expressionStatement(b.assignmentExpression(
        '=',
        expr,
        mapExpression(node.value, meta)
      ))
    ));
  }
  return statements;
}