How to use the ast-types.builders.variableDeclaration 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 styleguidist / react-styleguidist / src / loaders / examples-loader.js View on Github external
map(fullContext, (requireRequest, name) => [
				// const name$0 = require(path);
				b.variableDeclaration('const', [
					b.variableDeclarator(b.identifier(`${name}$0`), requireIt(requireRequest).toAST()),
				]),
				// const name = name$0[name] || name$0.default || name$0;
				b.variableDeclaration('const', [
					b.variableDeclarator(
						b.identifier(name),
						b.logicalExpression(
							'||',
							b.identifier(`${name}$0['${name}']`),
							b.logicalExpression(
								'||',
								b.identifier(`${name}$0.default`),
								b.identifier(`${name}$0`)
							)
						)
					),
				]),
			])
		)
github rexxars / sql-to-graphql / steps / ast-builders / type-imports.js View on Github external
// Require the graphql library
    if (graphql.length) {
        declarations.push(b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('GraphQL'),
                b.callExpression(
                    b.identifier('require'),
                    [b.literal('graphql')]
                )
            )]
        ));
    }

    // Relay needs the Node interface along with the globalIdField
    if (opts.relay) {
        declarations.push(b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('GraphQLRelay'),
                b.callExpression(
                    b.identifier('require'),
                    [b.literal('graphql-relay')]
                )
            )]
        ));

        declarations.push(b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('Node'),
                b.callExpression(
                    b.identifier('require'),
                    [b.literal('./Node')]
                )
github GothAck / javascript-x-server / autogen / lib / statement_body.js View on Github external
b.thisExpression(), b.identifier(`read${child_type}`)),
              [])]));
          if (fieldref === null) {
            read_stmts.push(
              b.whileStatement(
                b.binaryExpression(
                  '<',
                  b.memberExpression(
                    b.thisExpression(), b.identifier('cursor')),
                  b.memberExpression(
                    b.thisExpression(), b.identifier('length'))),
                b.blockStatement([read_stmt])));
          } else {
            read_stmts.push(
              b.forStatement(
                b.variableDeclaration(
                  'let',
                  [b.variableDeclarator(
                      b.identifier('i'),
                      b.literal(0))]),
                b.binaryExpression(
                  '<',
                  b.identifier('i'),
                  b.identifier(`${child_name}_length`)),
                b.updateExpression(
                  '++',
                  b.identifier('i'),
                  false),
                b.blockStatement([read_stmt])
            ));
          }
          write_stmts.push(
github rexxars / sql-to-graphql / steps / ast-builders / schema-imports.js View on Github external
];

    if (graphql.length) {
        declarations.push(b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('GraphQL'),
                b.callExpression(
                    b.identifier('require'),
                    [b.literal('graphql')]
                )
            )]
        ));
    }

    if (opts.relay) {
        declarations.push(b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('Node'),
                b.callExpression(
                    b.identifier('require'),
                    [b.literal('./types/Node')]
                )
            )]
        ));
    }

    declarations = declarations.concat(types.map(function(item) {
        return b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier(item),
                b.callExpression(
                    b.identifier('require'),
github paeckchen / paeckchen / packages / paeckchen-core / src / globals.ts View on Github external
if (path.scope.lookup('process') === null) {
        processPath = path;
      }
      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
          )
        )
      ]
github babel / babel / lib / 6to5 / transformers / block-binding.js View on Github external
var id = node.left.declarations[0].id;
      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 paeckchen / paeckchen / packages / paeckchen-core / src / plugins / es6-export.ts View on Github external
function importModule(identifier: ESTree.Identifier, moduleIndex: number): ESTree.VariableDeclaration {
  return b.variableDeclaration(
    'var',
    [
      b.variableDeclarator(
        identifier,
        b.callExpression(
          b.identifier('__paeckchen_require__'),
          [
            b.literal(moduleIndex)
          ]
        )
      )
    ]
  );
}
github rexxars / sql-to-graphql / steps / ast-builders / schema-imports.js View on Github external
declarations = declarations.concat(types.map(function(item) {
        return b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier(item),
                b.callExpression(
                    b.identifier('require'),
                    [b.literal('./types/' + item)]
                )
            )]
        );
    }));
github paeckchen / paeckchen / packages / paeckchen-core / src / plugins / es6-export.ts View on Github external
moduleExportsExpression(specifier.exported.name),
          b.memberExpression(
            b.memberExpression(
              tempIdentifier,
              b.identifier('exports'),
              false
            ),
            b.literal(specifier.local.name),
            true
          )
        )
      )
    );

  path.replace(
    b.variableDeclaration(
      'var',
      [
        b.variableDeclarator(
          tempIdentifier,
          b.callExpression(
            b.identifier('__paeckchen_require__'),
            [
              b.literal(reexportModuleIndex)
            ]
          )
        )
      ]
    ),
    ...exports
  );
}
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
                )
            )]
        )
    ];
}