How to use the jscodeshift.Identifier function in jscodeshift

To help you get started, we’ve selected a few jscodeshift 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 cpojer / js-codemod / extensions / imports / utils / getDeclarationName.js View on Github external
function getDeclarationName(node) {
  var declaration = node.declarations[0];
  if (jscs.Identifier.check(declaration.id)) {
    return declaration.id.name;
  }
  // Order by the first property name in the object pattern.
  if (jscs.ObjectPattern.check(declaration.id)) {
    return declaration.id.properties[0].key.name;
  }
  // Order by the first element name in the array pattern.
  if (jscs.ArrayPattern.check(declaration.id)) {
    return declaration.id.elements[0].name;
  }
  return '';
}
github dvajs / dva-ast / src / collections / RouteComponent.js View on Github external
this.find(j.ClassDeclaration).forEach(path => {
      const superClass = path.node.superClass;
      if (superClass) {
        if (
          // TODO: 处理 Component 和 React.Component 的来源信赖问题
          // class A extends Component {}
          (j.Identifier.check(superClass) && superClass.name === 'Component') ||
          // class A extends React.Component {}
          (j.MemberExpression.check(superClass) && isReactComponent(superClass))
        ) {
          pathes.push(path);
        }
      }
    });
github dvajs / dva-ast / src / collections / Entry.js View on Github external
function isDvaInstance(identifierName, path) {
  const scope = path.scope.lookup(identifierName);
  if (scope) {
    const declaratorPath = scope.getBindings()[identifierName][0].parent;
    const declaratorNode = declaratorPath.value;
    if (j.VariableDeclarator.check(declaratorNode)) {
      const { init } = declaratorNode;
      if (j.CallExpression.check(init) && j.Identifier.check(init.callee)) {
        return getImportRequirePath(init.callee.name, path) === 'dva';
      }
    }
  }
}
github Astrocoders / old-astroman / lib / commands / plug / react-native / utils / getExportedArrayKeys.js View on Github external
export default function getExportedObjectKeys({fileContent}) {
  return j(fileContent)
    .find(j.ExportDefaultDeclaration)
    .find(j.Identifier)
    .nodes()
    .map(prop => prop.name)
}
github cpojer / js-codemod / extensions / imports / utils / isValidRequireDeclaration.js View on Github external
function isValidRequireDeclaration(node) {
  if (!hasOneRequireDeclaration(node)) {
    return false;
  }
  var declaration = node.declarations[0];
  if (jscs.Identifier.check(declaration.id)) {
    return true;
  }
  if (jscs.ObjectPattern.check(declaration.id)) {
    return declaration.id.properties.every(
      prop => prop.shorthand && jscs.Identifier.check(prop.key)
    );
  }
  if (jscs.ArrayPattern.check(declaration.id)) {
    return declaration.id.elements.every(
      element => jscs.Identifier.check(element)
    );
  }
  return false;
}
github feathersjs / feathers / packages / generator-feathers / lib / transform.js View on Github external
findIdentifier(name) {
    const result = this.find(j.Identifier);

    if(name) {
      return result.filter(i => i.value.name === name);
    }

    return result;
  },
github SergioCrisostomo / vue-codemods / transformers / sort_keys / sortKeys.js View on Github external
if (typeof a.key.name === 'number' && typeof b.key.name === 'number') {
        return b.key.name - a.key.name;
      }

      return a.key.name.localeCompare(b.key.name);
    });
  };

  const jsSorted = j(file.source)
    .find(j.ObjectExpression)
    .forEach(naturalSortObject)
    .toSource();

  return j(jsSorted)
    .find(jscodeshift.Identifier, {name: 'Vue'})
    .filter((path) => path.parentPath.value.type === 'NewExpression')
    .map((path) => {
      if (!path.parentPath.value.arguments[0] || !path.parentPath.value.arguments[0].properties) {
        return path;
      }

      path.parentPath.value.arguments[0].properties = path.parentPath.value.arguments[0].properties.sort((a, b) => {
        if (a.type.match(/^Spread/)) {
          return -1;
        }

        if (b.type.match(/^Spread/)) {
          return 1;
        }

        if (!a.key || !b.key) {
github iopipe / serverless-plugin-iopipe / src / transform.js View on Github external
function wrap(node){
  const token = options().placeholder ? 'process.env.IOPIPE_TOKEN' : `\'${options().token || 'DEFAULT_TOKEN'}\'`;
  const str = `require('iopipe')({clientId: ${token}, installMethod: 'plugin-sls'})(REPLACE)`;
  return j(str)
    .find(j.Identifier, {
      name: 'REPLACE'
    })
    .replaceWith(node.right)
    .toSource({quote: options().quote});
}
github Shopify / javascript / packages / shopify-codemod / transforms / utils.js View on Github external
export function getPropertyName({key, computed}) {
  if (computed) { return null; }
  return j.Identifier.check(key) ? key.name : key.value;
}