How to use the recast.types.namedTypes function in recast

To help you get started, we’ve selected a few recast 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 facebook / regenerator / lib / emit.js View on Github external
/**
 * Copyright (c) 2014, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * https://raw.github.com/facebook/regenerator/master/LICENSE file. An
 * additional grant of patent rights can be found in the PATENTS file in
 * the same directory.
 */

var assert = require("assert");
var types = require("recast").types;
var isArray = types.builtInTypes.array;
var b = types.builders;
var n = types.namedTypes;
var leap = require("./leap");
var meta = require("./meta");
var util = require("./util");
var runtimeProperty = util.runtimeProperty;
var hasOwn = Object.prototype.hasOwnProperty;

function Emitter(contextId) {
  assert.ok(this instanceof Emitter);
  n.Identifier.assert(contextId);

  // Used to generate unique temporary names.
  this.nextTempId = 0;

  Object.defineProperties(this, {
    // In order to make sure the context object does not collide with
    // anything in the local scope, we might have to rename it, so we
github facebook / regenerator / lib / hoist.js View on Github external
/**
 * Copyright (c) 2014, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * https://raw.github.com/facebook/regenerator/master/LICENSE file. An
 * additional grant of patent rights can be found in the PATENTS file in
 * the same directory.
 */

var assert = require("assert");
var types = require("recast").types;
var n = types.namedTypes;
var b = types.builders;
var hasOwn = Object.prototype.hasOwnProperty;

// The hoist function takes a FunctionExpression or FunctionDeclaration
// and replaces any Declaration nodes in its body with assignments, then
// returns a VariableDeclaration containing just the names of the removed
// declarations.
exports.hoist = function(funPath) {
  assert.ok(funPath instanceof types.NodePath);
  n.Function.assert(funPath.value);

  var vars = {};

  function varDeclToExpr(vdec, includeIdentifiers) {
    n.VariableDeclaration.assert(vdec);
    var exprs = [];
github riot / compiler / src / utils / build-types.js View on Github external
import {types as astTypes} from 'recast'

export const types = astTypes
export const builders = astTypes.builders
export const namedTypes = astTypes.namedTypes
github Heigvd / Wegas / wegas-app / src / main / webapp / wegas-react-form / src / Script / modules / Condition.js View on Github external
import PropTypes from 'prop-types';
import React from 'react';
import { types } from 'recast';
import Impact, { ErrorCatcher } from './Impact';
import { methodDescriptor, extractMethod } from './method';
import { methodDescriptor as globalMethodDescriptor } from './globalMethod';
import ConditionOperator from './ConditionOperator';
import { renderForm, valueToAST } from './args';
import { containerStyle } from '../Views/conditionImpactStyle';

const b = types.builders;
const isCallExpression = types.namedTypes.CallExpression.check;
const isExpressionStatement = types.namedTypes.ExpressionStatement.check;
/**
 * return a default value for the given type
 * @param {string} type the type for which a default value is required
 * @returns {string|undefined|boolean} the default value
 */
function defaultValue(type) {
    switch (type) {
        case 'string':
            return '';
        case 'number':
            return undefined;
        case 'boolean':
            return true;
        default:
            throw new Error(
github facebook / regenerator / lib / leap.js View on Github external
/**
 * Copyright (c) 2014, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * https://raw.github.com/facebook/regenerator/master/LICENSE file. An
 * additional grant of patent rights can be found in the PATENTS file in
 * the same directory.
 */

var assert = require("assert");
var types = require("recast").types;
var n = types.namedTypes;
var b = types.builders;
var inherits = require("util").inherits;
var hasOwn = Object.prototype.hasOwnProperty;

function Entry() {
  assert.ok(this instanceof Entry);
}

function FunctionEntry(returnLoc) {
  Entry.call(this);
  n.Literal.assert(returnLoc);
  this.returnLoc = returnLoc;
}

inherits(FunctionEntry, Entry);
exports.FunctionEntry = FunctionEntry;
github martinandert / react-inline / src / transformObjectExpressionIntoStyleSheetObject.js View on Github external
import assert from 'assert';
import vm from 'vm';
import extend from 'object-assign';
import { print, types } from 'recast';

const n = types.namedTypes;
const isBlank = /^\s*$/;

export default function transformObjectExpressionIntoStyleSheetObject(expr, context) {
  assert(n.ObjectExpression.check(expr), 'must be a object expression');

  context = vm.createContext(extend({}, context));

  context.evaluate = function(node) {
    return vm.runInContext(print(node).code, this);
  };

  let result = {};

  expr.properties.forEach((property) => {
    processTopLevelProperty(property.key, property.value, result, context);
  });
github facebook / regenerator / lib / util.js View on Github external
/**
 * Copyright (c) 2014-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

var assert = require("assert");
var types = require("recast").types;
var n = types.namedTypes;
var b = types.builders;
var hasOwn = Object.prototype.hasOwnProperty;

exports.defaults = function(obj) {
  var len = arguments.length;
  var extension;

  for (var i = 1; i < len; ++i) {
    if ((extension = arguments[i])) {
      for (var key in extension) {
        if (hasOwn.call(extension, key) && !hasOwn.call(obj, key)) {
          obj[key] = extension[key];
        }
      }
    }
  }
github Heigvd / Wegas / wegas-app / src / main / webapp / wegas-react-form / src / Script / modules / Condition.js View on Github external
import PropTypes from 'prop-types';
import React from 'react';
import { types } from 'recast';
import Impact, { ErrorCatcher } from './Impact';
import { methodDescriptor, extractMethod } from './method';
import { methodDescriptor as globalMethodDescriptor } from './globalMethod';
import ConditionOperator from './ConditionOperator';
import { renderForm, valueToAST } from './args';
import { containerStyle } from '../Views/conditionImpactStyle';

const b = types.builders;
const isCallExpression = types.namedTypes.CallExpression.check;
const isExpressionStatement = types.namedTypes.ExpressionStatement.check;
/**
 * return a default value for the given type
 * @param {string} type the type for which a default value is required
 * @returns {string|undefined|boolean} the default value
 */
function defaultValue(type) {
    switch (type) {
        case 'string':
            return '';
        case 'number':
            return undefined;
        case 'boolean':
            return true;
        default:
            throw new Error(
                `Default value for 'returns' property '${type}' is not implemented`
github callstack / component-docs / src / parsers / component.js View on Github external
p =>
          p.node.static &&
          types.namedTypes.ClassProperty.check(p.node) &&
          !REACT_STATICS.includes(p.node.key.name)
      )