How to use the babel-core.types function in babel-core

To help you get started, we’ve selected a few babel-core 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 tmpfs / trucks / packages / transform-skate / src / compiler.js View on Github external
function render(el, opts, prefix) {

  opts = options(opts);

  const $ = opts.vdom
    , babel = require('babel-core')
    , t = babel.types
    , body = [];

  function getTemplateLiteralExpression(val) {
    return babel.transform(
      '`' + val  + '`', opts.babel).ast.program.body[0].expression;
  }

  function attributeIterator(key, val) {
    if(key && ON_PATTERN.test(key)) {
      const ast = babel.transform(val, opts.babel).ast;
      t.assertExpressionStatement(ast.program.body[0]);
      return ast.program.body[0].expression;
    }else if(val === true || val === false) {
      return t.booleanLiteral(val);
    // treat as string
    }else{
github fkling / JSNetworkX / transforms / async.js View on Github external
*
 * export function foo(a, b, c) {
 *   // implementation
 * }
 *
 * export function genFoo(a, b, c) {
 *   return delegateName('foo', [a, b, c]);
 * }
 *
 */

'use strict';
var babel = require('babel-core');
var path = require('path');

var t = babel.types;
var Transformer = babel.Transformer;

/**
 * This builds the call to the delegate function, i.e.
 *
 * return delegateName('functionName', args);
 */
function buildCallTo(delegateName, functionName, args) {
  return t.returnStatement(
    t.callExpression(
      t.identifier(delegateName),
      [
        t.literal(functionName),
        t.arrayExpression(args)
      ]
    )
github facebook / metro / packages / metro-bundler / src / JSTransformer / worker / constant-folding.js View on Github external
*
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 * @flow
 * @format
 */

'use strict';

const babel = require('babel-core');
const invariant = require('fbjs/lib/invariant');

import type {IntermediateTransformResult} from './types.flow';
const t = babel.types;

const Conditional = {
  exit(path) {
    const node = path.node;
    const test = node.test;
    if (t.isLiteral(test)) {
      if (test.value || node.alternate) {
        path.replaceWith(test.value ? node.consequent : node.alternate);
      } else if (!test.value) {
        path.remove();
      }
    }
  },
};

const constantFoldingPlugin = {
github ifgyong / demo / React-native / Helloword / node_modules / metro-bundler / src / JSTransformer / worker / constant-folding.js View on Github external
* All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 *
 * @format
 */

'use strict';

const babel = require('babel-core');


const t = babel.types;

const Conditional = {
    exit(path) {
        const node = path.node;
        const test = node.test;
        if (t.isLiteral(test)) {
            if (test.value || node.alternate) {
                path.replaceWith(test.value ? node.consequent : node.alternate);
            } else if (!test.value) {
                path.remove();
            }
        }
    }
};
github styled-components / styled-components-codemods / src / v4 / index.js View on Github external
"use strict";

const t = require("babel-core").types;
const _ = require("lodash");

let isExtendInScope = false;

module.exports = function() {
  return {
    manipulateOptions(opts, parserOpts) {
      parserOpts.plugins.push("asyncGenerators");
      parserOpts.plugins.push("classProperties");
      parserOpts.plugins.push("decorators");
      parserOpts.plugins.push("doExpressions");
      parserOpts.plugins.push("dynamicImport");
      parserOpts.plugins.push("flow");
      parserOpts.plugins.push("functionBind");
      parserOpts.plugins.push("functionSent");
      parserOpts.plugins.push("jsx");
github react-component / rn-packager / src / react-native / packager / react-packager / src / JSTransformer / worker / inline.js View on Github external
/**
 * Copyright (c) 2016-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */
'use strict';

const babel = require('babel-core');
const t = babel.types;

const react = {name: 'React'};
const platform = {name: 'Platform'};
const os = {name: 'OS'};
const requirePattern = {name: 'require'};

const env = {name: 'env'};
const nodeEnv = {name: 'NODE_ENV'};
const processId = {name: 'process'};

const dev = {name: '__DEV__'};

const isGlobal = (binding) => !binding;

const isToplevelBinding = (binding) => isGlobal(binding) || !binding.scope.parent;
github ifgyong / demo / React-native / Helloword / node_modules / metro-bundler / src / ModuleGraph / worker / JsFileWrapping.js View on Github external
function functionFromProgram(
    program,
    parameters) {
    const t = babel.types;
    return t.functionExpression(
        t.identifier(''),
        parameters.map(makeIdentifier),
        t.blockStatement(program.body, program.directives));

}
github format-message / format-message / src / inliner.js View on Github external
import Visitor from './visitor'
import { relative, resolve, basename, join as pathJoin } from 'path'
import * as babel from 'babel-core'
import sourceMap from 'source-map'
import Parser from 'message-format/parser'
import Transpiler from './transpiler'

const types = babel.types

/**
 * Transforms source code, translating and inlining `formatMessage` calls
 **/
export default class Inliner extends Visitor {

  constructor (options) {
    super(options)
    this.declarations = []
  }

  inline ({ sourceCode, sourceFileName, sourceMapName, inputSourceMap }) {
    this.declarations.length = 0
    return this.run({ sourceCode, sourceFileName, sourceMapName, inputSourceMap })
  }
github jscs-dev / babel-jscs / acorn-to-esprima.js View on Github external
var traverse = require("babel-core").traverse;
var tt       = require("babel-core").acorn.tokTypes;
var t        = require("babel-core").types;

var source = "";

exports.toToken = function (token) {
  var type = token.type;
  token.range = [token.start, token.end];

  if (type === tt.name) {
    token.type = "Identifier";
  } else if (type === tt.semi || type === tt.comma ||
             type === tt.parenL || type === tt.parenR ||
             type === tt.braceL || type === tt.braceR ||
             type === tt.slash || type === tt.dot ||
             type === tt.bracketL || type === tt.bracketR ||
             type === tt.ellipsis || type === tt.arrow ||
             type === tt.star || type === tt.incDec ||