How to use the ast-types.namedTypes.Identifier 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 reactjs / react-docgen / src / handlers / displayNameHandler.js View on Github external
} else if (
      t.ArrowFunctionExpression.check(path.node) ||
      t.FunctionExpression.check(path.node)
    ) {
      let currentPath = path;
      while (currentPath.parent) {
        if (t.VariableDeclarator.check(currentPath.parent.node)) {
          documentation.set(
            'displayName',
            getNameOrValue(currentPath.parent.get('id')),
          );
          return;
        } else if (t.AssignmentExpression.check(currentPath.parent.node)) {
          const leftPath = currentPath.parent.get('left');
          if (
            t.Identifier.check(leftPath.node) ||
            t.Literal.check(leftPath.node)
          ) {
            documentation.set('displayName', getNameOrValue(leftPath));
            return;
          }
        }
        currentPath = currentPath.parent;
      }
    }
    return;
  }
  displayNamePath = resolveToValue(displayNamePath);

  // If display name is defined as a getter we get a function expression as
  // value. In that case we try to determine the value from the return
  // statement.
github reactjs / react-docgen / src / utils / resolveToValue.js View on Github external
t.ImportNamespaceSpecifier.check(node) ||
    t.ImportSpecifier.check(node)
  ) {
    // go up two levels as first level is only the array of specifiers
    return path.parentPath.parentPath;
  } else if (t.AssignmentExpression.check(node)) {
    if (node.operator === '=') {
      return resolveToValue(path.get('right'));
    }
  } else if (
    t.TypeCastExpression.check(node) ||
    t.TSAsExpression.check(node) ||
    t.TSTypeAssertion.check(node)
  ) {
    return resolveToValue(path.get('expression'));
  } else if (t.Identifier.check(node)) {
    if (
      (t.ClassDeclaration.check(path.parentPath.node) ||
        t.ClassExpression.check(path.parentPath.node) ||
        t.Function.check(path.parentPath.node)) &&
      path.parentPath.get('id') === path
    ) {
      return path.parentPath;
    }

    let scope = path.scope.lookup(node.name);
    let resolvedPath: ?NodePath;
    if (scope) {
      // The variable may be assigned a different value after initialization.
      // We are first trying to find all assignments to the variable in the
      // block where it is defined (i.e. we are not traversing into statements)
      resolvedPath = findLastAssignedValue(scope, node.name);
github reactjs / react-docgen / src / utils / isReactBuiltinCall.js View on Github external
path = path.get('expression');
  }

  if (match(path.node, { callee: { property: { name } } })) {
    const module = resolveToModule(path.get('callee', 'object'));
    return Boolean(module && isReactModuleName(module));
  }

  if (t.CallExpression.check(path.node)) {
    const value = resolveToValue(path.get('callee'));
    if (value === path.get('callee')) return false;

    if (
      // `require('react').createElement`
      (t.MemberExpression.check(value.node) &&
        t.Identifier.check(value.get('property').node) &&
        value.get('property').node.name === name) ||
      // `import { createElement } from 'react'`
      (t.ImportDeclaration.check(value.node) &&
        value.node.specifiers.some(
          specifier => specifier.imported && specifier.imported.name === name,
        ))
    ) {
      const module = resolveToModule(value);
      return Boolean(module && isReactModuleName(module));
    }
  }

  return false;
}
github probmods / webppl / src / analysis / analyze.js View on Github external
function update(s1, s2, s3, s4) {
    assert(s1.type === 'UApplyEntry');
    assert(s2.type === 'UEvalCall');
    assert(s3.type === 'UApplyEntry');
    assert(s4.type === 'CEvalExit');

    var fDependence = Au(s2.store, s2.environment, s2.dependence, s2.callee).states;

    var environment = s2.environment;

    if (types.Identifier.check(s2.callee) && (!s2.callee.heapRef)) {
      environment = envExtend(environment, s2.callee.name, s3.f, fDependence);
    }

    var argument = s4.evaluatedArgument();

    propagate(s1, new CApply({
      store: s4.store,
      environment: environment,
      dependence: s2.dependence, // XXX check this
      cont: s2.k,
      argument: new AValue({
        values: argument.values,
        states: argument.states.union(fDependence)
      })
    }));
  }
github probmods / webppl / src / analysis / analyze.js View on Github external
function makeCEval(store, environment, dependence, cont, argument) {
  if (types.Identifier.check(cont)) {
    return new CEvalExit({
      store: store,
      environment: environment,
      dependence: dependence,
      argument: argument
    });
  }
  else {
    return new CEvalInner({
      store: store,
      environment: environment,
      dependence: dependence,
      cont: cont,
      argument: argument
    });
  }
github reactjs / react-docgen / src / utils / resolveToModule.js View on Github external
export default function resolveToModule(path: NodePath): ?string {
  const node = path.node;
  switch (node.type) {
    case t.VariableDeclarator.name:
      if (node.init) {
        return resolveToModule(path.get('init'));
      }
      break;
    case t.CallExpression.name:
      if (match(node.callee, { type: t.Identifier.name, name: 'require' })) {
        return node.arguments[0].value;
      }
      return resolveToModule(path.get('callee'));
    case t.Identifier.name:
    case t.JSXIdentifier.name: {
      const valuePath = resolveToValue(path);
      if (valuePath !== path) {
        return resolveToModule(valuePath);
      }
      break;
    }
    case t.ImportDeclaration.name:
      return node.source.value;
    case t.MemberExpression.name:
      while (path && t.MemberExpression.check(path.node)) {
        path = path.get('object');
github TooTallNate / node-degenerator / src / index.ts View on Github external
visitAssignmentExpression(path) {
				if (
					n.Identifier.check(path.node.left) &&
					n.Identifier.check(path.node.right) &&
					checkName(path.node.right.name, names) &&
					!checkName(path.node.left.name, names)
				) {
					names.push(path.node.left.name);
				}
				return false;
			},
			visitFunction(path) {
github reactjs / react-docgen / src / utils / resolveObjectKeysToArray.js View on Github external
function isWhitelistedObjectProperty(prop) {
  return (
    (t.Property.check(prop) &&
      ((t.Identifier.check(prop.key) && !prop.computed) ||
        t.Literal.check(prop.key))) ||
    t.SpreadElement.check(prop)
  );
}
github reactjs / react-docgen / src / utils / resolveObjectKeysToArray.js View on Github external
function isObjectKeysCall(node: ASTNode): boolean {
  return (
    t.CallExpression.check(node) &&
    node.arguments.length === 1 &&
    t.MemberExpression.check(node.callee) &&
    t.Identifier.check(node.callee.object) &&
    node.callee.object.name === 'Object' &&
    t.Identifier.check(node.callee.property) &&
    node.callee.property.name === 'keys'
  );
}
github framer / component-importer / src / utils.ts View on Github external
export function getNameOrValue(path: NodePath, raw?: boolean): string {
    const node = path.node
    switch (node.type) {
        case (t.Identifier as any).name:
            return node.name
        case (t.Literal as any).name:
            return raw ? node.raw : node.value
        default:
            throw new TypeError("Argument must be an Identifier or a Literal")
    }
}