How to use the ast-types.builders.literal 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
b.callExpression(
                    b.identifier('require'),
                    [b.literal('../resolve-map')]
                )
            )]
        )
    );

    // 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')]
                )
            )]
        ));
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(
        b.memberExpression(
          tempIdentifier,
          b.identifier('exports'),
          false
        ),
        b.literal('default'),
        true
      )
github rainforestapp / decaf / src / parser.js View on Github external
function mapLiteral(node: CNode) {
  let value;
  value = node.base.value;

  if (value === 'NaN') {
    return b.literal(NaN);
  } else if (IS_STRING.test(value)) {
    return b.literal(value.match(STRING_INSIDE_QUOTES)[1]);
  } else if (IS_NUMBER.test(value)) {
    return b.literal(Number(value));
  } else if (IS_REGEX.test(value)) {
    return b.literal(stringToRegex(value));
  }

  return b.identifier(value);
}
github rexxars / sql-to-graphql / steps / ast-builders / resolve-map.js View on Github external
function buildImports(opts) {
    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',
github rexxars / sql-to-graphql / steps / ast-builders / schema-imports.js View on Github external
function cjsImport(graphql, types, opts) {
    var declarations = [
        b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('getEntityResolver'),
                b.callExpression(
                    b.identifier('require'),
                    [b.literal('./util/entity-resolver')]
                )
            )]
        )
    ];

    if (graphql.length) {
        declarations.push(b.variableDeclaration('var',
            [b.variableDeclarator(
                b.identifier('GraphQL'),
                b.callExpression(
                    b.identifier('require'),
                    [b.literal('graphql')]
                )
            )]
        ));
    }
github rexxars / sql-to-graphql / steps / ast-builders / resolver.js View on Github external
module.exports = function buildResolver(model) {
    return b.callExpression(
        b.identifier('getEntityResolver'),
        [b.literal(model.name)]
    );
};
github paeckchen / paeckchen / packages / paeckchen-core / src / plugins / es6-export.ts View on Github external
true
          )
        )
      )
    );

  path.replace(
    b.variableDeclaration(
      'var',
      [
        b.variableDeclarator(
          tempIdentifier,
          b.callExpression(
            b.identifier('__paeckchen_require__'),
            [
              b.literal(reexportModuleIndex)
            ]
          )
        )
      ]
    ),
    ...exports
  );
}
github paeckchen / paeckchen / packages / paeckchen-core / src / bundle-json.ts View on Github external
export function buildValue(data: any): ESTree.ObjectExpression|ESTree.ArrayExpression|ESTree.Literal {
  if (data === null) {
    return b.literal(null);
  }
  switch (typeof data) {
    case 'number':
    case 'string':
    case 'boolean':
      return b.literal(data);
    default:
      if (Array.isArray(data)) {
        return buildArray(data);
      }
      return buildObject(data);
  }
};
github rexxars / sql-to-graphql / steps / ast-builders / schema-imports.js View on Github external
[b.variableDeclarator(
                b.identifier(item),
                b.callExpression(
                    b.identifier('require'),
                    [b.literal('./types/' + item)]
                )
            )]
        );
    }));

    declarations.push(b.variableDeclaration('var',
        [b.variableDeclarator(
            b.identifier('resolveMap'),
            b.callExpression(
                b.identifier('require'),
                [b.literal('./resolve-map')]
            )
        )]
    ));

    declarations.push(b.variableDeclaration('var',
        [b.variableDeclarator(
            b.identifier('types'),
            b.callExpression(
                b.identifier('require'),
                [b.literal('./types')]
            )
        )]
    ));

    declarations = declarations.concat(graphql.map(function(item) {
        return b.variableDeclaration('var',