How to use the ast-types.builders.variableDeclarator 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 rexxars / sql-to-graphql / steps / ast-builders / type-imports.js View on Github external
function cjsImport(graphql, others, opts) {
    // Require the entity resolver
    var declarations = [
        b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('getEntityResolver'),
                b.callExpression(
                    b.identifier('require'),
                    [b.literal('../util/entity-resolver')]
                )
            )]
        )
    ];

    if (opts.relay && graphql.indexOf('GraphQLList') >= 0) {
        declarations.push(
            b.variableDeclaration('var',
                [b.variableDeclarator(
                    b.identifier('getConnectionResolver'),
                    b.callExpression(
                        b.identifier('require'),
github paeckchen / paeckchen / packages / paeckchen-core / src / plugins / es6-import.ts View on Github external
function convertImport(tempIdentifier: ESTree.Identifier, specifier: ESTree.ImportSpecifier
    | ESTree.ImportDefaultSpecifier | ESTree.ImportNamespaceSpecifier): ESTree.VariableDeclarator {
  if (n.ImportSpecifier.check(specifier)) {
    // e.g. import { a as b, c } from './dep';
    return b.variableDeclarator(
      b.identifier(specifier.local.name),
      b.memberExpression(
        b.memberExpression(
          tempIdentifier,
          b.identifier('exports'),
          false
        ),
        b.literal(specifier.imported.name),
        true
      )
    );
  } else if (n.ImportDefaultSpecifier.check(specifier)) {
    // e.g. import dep from './dep';
    return b.variableDeclarator(
      b.identifier(specifier.local.name),
      b.memberExpression(
github paeckchen / paeckchen / packages / paeckchen-core / src / plugins / es6-import.ts View on Github external
function replaceImports(path: Path, importModuleIndex: number): void {
  const tempIdentifier = path.scope.declareTemporary(`__import${importModuleIndex}`);
  const imports = path.node.specifiers.map((specifier) => convertImport(tempIdentifier, specifier));
  path.replace(
    b.variableDeclaration(
      'var',
      [
        b.variableDeclarator(
          tempIdentifier,
          b.callExpression(
            b.identifier('__paeckchen_require__'),
            [
              b.literal(importModuleIndex)
            ]
          )
        ),
        ...imports
      ]
    )
  );
}
github paeckchen / paeckchen / packages / paeckchen-core / src / globals.ts View on Github external
return false;
    }
  });

  if (processPath === undefined) {
    return Promise.resolve();
  }

  const processModulePath = await getModulePath('.', 'process', context);
  const processIndex = getModuleIndex(processModulePath, state);
  const body = processPath.get('body');
  body.get(body.value.length - 1).insertBefore(
    b.variableDeclaration(
      'var',
      [
        b.variableDeclarator(
          b.identifier('process'),
          b.memberExpression(
            b.callExpression(
              b.identifier('__paeckchen_require__'),
              [
                b.literal(processIndex)
              ]
            ),
            b.identifier('exports'),
            false
          )
        )
      ]
    )
  );
  enqueueModule(processModulePath, state, context);
github rexxars / sql-to-graphql / steps / ast-builders / resolve-map.js View on Github external
];
    }

    return [
        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 babel / babel / lib / 6to5 / transformers / block-binding.js View on Github external
node.left = id;
      nodes.push(util.template("variable-declare", {
        KEY: id
      }));
    }

    return node;
  });

  //

  var argumentsId = util.aliasArguments(generateUid, node);

  if (argumentsId) {
    nodes.push(b.variableDeclaration("var", [
      b.variableDeclarator(argumentsId, b.identifier("arguments"))
    ]));
  }

  //

  var block = b.blockStatement([]);
  block.body = node;

  var func = b.functionExpression(null, [], block, false);

  //

  var templateName = "function-call";
  if (traverse.hasType(node, "ThisExpression")) templateName += "-this";
  if (traverse.hasType(node, "ReturnStatement", traverse.FUNCTION_TYPES)) templateName += "-return";
github babel / babel / lib / 6to5 / transformers / block-binding.js View on Github external
var body = node.body;

  var built = buildNode(node.body, generateUid);
  node.body = built.node;

  traverse(built.body, function (node) {
    if (node.type === "ContinueStatement") {
      return b.returnStatement(null);
    }
  }, blockTypes);

  if (traverse.hasType(body, "BreakStatement", blockTypes)) {
    var id = b.identifier(generateUid("break"));

    node.body.unshift(b.variableDeclaration("var", [
      b.variableDeclarator(id, b.literal(false))
    ]));

    traverse(built.body, function (node) {
      if (node.type === "BreakStatement") {
        return b.returnStatement(b.assignmentExpression("=", id, b.literal(true)));
      }
    }, blockTypes);

    node.body.push(b.ifStatement(id, b.breakStatement()));
  }
};
github rexxars / sql-to-graphql / steps / ast-builders / resolve-map.js View on Github external
if (!opts.relay) {
        return [];
    }

    if (opts.es6) {
        return [
            b.importDeclaration(
                [importSpecifier('connectionDefinitions')],
                b.literal('graphql-relay')
            )
        ];
    }

    return [
        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 zerobias / effector / src / model-gen / generate.js View on Github external
]),
      ),
    )
    let listStoreId = b.identifier(camelCase(path.node.id.name + 'List'))
    listStoreId.typeAnnotation = b.typeAnnotation(
      b.genericTypeAnnotation(
        b.identifier('Store'),
        b.typeParameterInstantiation([
          b.arrayTypeAnnotation(b.genericTypeAnnotation(path.node.id, null)),
        ]),
      ),
    )
    path.parentPath.insertAfter(
      b.exportNamedDeclaration(
        b.variableDeclaration('const', [
          b.variableDeclarator(
            listStoreId,
            b.callExpression(b.identifier('createStore'), [
              b.arrayExpression([]),
            ]),
          ),
        ]),
      ),
    )
    path.parentPath.insertAfter(
      b.exportNamedDeclaration(
        b.variableDeclaration('const', [
          b.variableDeclarator(
            singleStoreId,
            b.callExpression(b.identifier('createStore'), [
              b.identifier('null'),
            ]),
github GothAck / javascript-x-server / autogen / lib / statement_body.js View on Github external
b.memberExpression(
                b.thisExpression(),
                b.identifier('moveCursor')),
              [b.literal(2)])));
          write_stmts.push(
            b.expressionStatement(b.callExpression(
              b.memberExpression(
                b.thisExpression(),
                b.identifier('moveCursor')),
              [b.literal(2)])));
        }

        read_stmts.push(
          b.variableDeclaration(
            'var',
            [b.variableDeclarator(
              b.identifier('value'),
              b.newExpression(b.identifier('Map'), []))]));

        read_stmts.push(b.expressionStatement(
          b.assignmentExpression(
            '=',
            b.memberExpression(
              b.identifier('obj'), b.identifier('value')),
            b.identifier('value'))));

        read_stmts.push(b.forOfStatement(
          b.variableDeclaration(
            'let',
            [b.identifier('field')]),
          b.memberExpression(
            b.identifier('obj'), b.identifier(value_mask_name)),