How to use the codemod-cli.getParser function in codemod-cli

To help you get started, we’ve selected a few codemod-cli 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 ember-codemods / ember-3x-codemods / transforms / deprecate-router-events / index.js View on Github external
module.exports = function transformer(file, api) {
  const j = getParser(api);
  const options = getOptions();

  const root = j(file.source);

  const createInit = (props, exp1, exp2) => {
    // First create the super call for init
    let superCall = j.expressionStatement(
      j.callExpression(j.memberExpression(j.thisExpression(), j.identifier("_super"), false), [
        j.identifier("...arguments")
      ])
    );

    let initProp = j.objectMethod("method", j.identifier("init"), [], j.blockStatement([superCall, exp1, exp2]));

    props.push(initProp);
  };
github ember-codemods / ember-test-helpers-codemod / transforms / acceptance / transforms / click.js View on Github external
function transform(file, api) {
  let source = file.source;
  let j = getParser(api);

  let root = j(source);

  let replacements = root
    .find(j.CallExpression)
    .filter(({ node }) => isGlobalHelperExpression(j, node))
    ;

  if (replacements.length > 0) {
    makeAwait(j, replacements);
    dropAndThen(j, root);
    addImportStatement(['click']);
  }

  writeImportStatements(j, root);
  return root.toSource({ quote: 'single' });
github ember-codemods / ember-test-helpers-codemod / transforms / acceptance / transforms / visit.js View on Github external
function transform(file, api) {
  let source = file.source;
  let j = getParser(api);

  let root = j(source);

  let replacements = root
    .find(j.CallExpression)
    .filter(({ node }) => isGlobalHelperExpression(j, node))
    ;

  if (replacements.length > 0) {
    makeAwait(j, replacements);
    dropAndThen(j, root);
    addImportStatement(['visit']);
  }

  writeImportStatements(j, root);
  return root.toSource({ quote: 'single' });
github ember-codemods / ember-test-helpers-codemod / transforms / integration / transforms / text.js View on Github external
function transform(file, api) {
  let source = file.source;
  let j = getParser(api);

  let root = j(source);

  let replacements = root
    .find(j.CallExpression)
    .filter((path) => isJQueryExpression(j, path))
    .replaceWith(({ node }) => createExpression(j, node.callee.object.arguments));

  if (replacements.length > 0) {
    addImportStatement(['find']);
  }

  writeImportStatements(j, root);
  return root.toSource({quote: 'single'});
}
github ember-codemods / ember-test-helpers-codemod / transforms / integration / transforms / key-event.js View on Github external
function transform(file, api) {
  let source = file.source;
  let j = getParser(api);

  let root = j(source);

  let replacements = root
    .find(j.CallExpression)
    .filter((path) => isJQueryExpression(j, path))
    .replaceWith(({ node }) => createExpression(j, node.callee.object.arguments[0], node.arguments[0], node.arguments[1].properties[0].value))
    .forEach((path) => makeParentFunctionAsync(j, path))
    ;

  if (replacements.length > 0) {
    addImportStatement(['keyEvent']);
  }

  writeImportStatements(j, root);
  return root.toSource({ quote: 'single' });
github ember-codemods / ember-test-helpers-codemod / transforms / integration / transforms / attr.js View on Github external
function transform(file, api) {
  let source = file.source;
  let j = getParser(api);

  let root = j(source);

  let propReplacements = root
    .find(j.CallExpression)
    .filter((path) => isJQueryExpression(j, path))
    .filter(({ node }) => isPropertyAccessPreferred(j, node))
    .replaceWith(({ node }) => createPropExpression(j, node.callee.object.arguments, node.arguments[0].value));

  let attrReplacements = root
    .find(j.CallExpression)
    .filter((path) => isJQueryExpression(j, path))
    .filter(({ node }) => !isPropertyAccessPreferred(j, node))
    .replaceWith(({ node }) => createAttributeExpression(j, node.callee.object.arguments, node.arguments[0]));

  if (propReplacements.length > 0 || attrReplacements.length > 0) {
github ember-codemods / ember-test-helpers-codemod / transforms / acceptance / transforms / tail-eq.js View on Github external
function transform(file, api) {
  let source = file.source;
  let j = getParser(api);

  let root = j(source);

  let replacements = root
    .find(j.CallExpression)
    .filter(({ node }) => isAnEqExpression(j, node))
    .replaceWith(({ node }) => {
      let eqExpression = migrateSelector(j, node.arguments[0]);
      node.arguments = [ eqExpression, ...node.arguments.slice(1) ];
      return node;
    })
    ;

  if (replacements.length > 0) {
    addImportStatement(['findAll']);
  }
github ember-codemods / ember-test-helpers-codemod / transforms / integration / transforms / prop.js View on Github external
function transform(file, api) {
  let source = file.source;
  let j = getParser(api);

  let root = j(source);

  let replacements = root
      .find(j.CallExpression)
      .filter((path) => isJQueryExpression(j, path))
      .replaceWith(({ node }) => createPropExpression(j, node.callee.object.arguments, node.arguments[0].value))
    ;

  if (replacements.length > 0) {
    addImportStatement(['find']);
  }

  writeImportStatements(j, root);
  return root.toSource({ quote: 'single' });
}
github ember-codemods / ember-test-helpers-codemod / transforms / native-dom / index.js View on Github external
function transform(file, api) {
  let source = file.source;
  let j = getParser(api);
  let root = j(source);

  let nativeDomImportStatements = root.find(j.ImportDeclaration, {
    source: { value: 'ember-native-dom-helpers' }
  });
  if (nativeDomImportStatements.length === 0) {
    return root.toSource({ quote: 'single' });
  }

  let newImports = [];

  nativeDomImportStatements.forEach((importStatement) => {
    let oldSpecifiers = importStatement.get('specifiers');

    let newSpecifiers = [];
    oldSpecifiers.each(({ node: specifier }) => {
github ember-codemods / ember-test-helpers-codemod / transforms / acceptance / transforms / has-class.js View on Github external
function transform(file, api) {
  let source = file.source;
  let j = getParser(api);

  let root = j(source);

  let replacements = root
    .find(j.CallExpression)
    .filter(({ node }) => isJQueryExpression(j, node))
    .replaceWith(({ node }) => createExpression(j, node.callee.object.arguments, node.arguments[0]));

  if (replacements.length > 0) {
    addImportStatement(['find']);
  }

  writeImportStatements(j, root);
  return root.toSource({ quote: 'single' });
}

codemod-cli

a command line tool for generating, testing, and publishing codemods

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis