How to use the jscodeshift.returnStatement 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 Polymer / tools / src / document-processor.ts View on Github external
sourceRange: element.sourceRange!
            }).toString());
        continue;
      }

      const node = nodePath.node;
      if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
        // A Polymer 2.0 class-based element
        node.body.body.splice(
            0,
            0,
            jsc.methodDefinition(
                'get',
                jsc.identifier('template'),
                jsc.functionExpression(
                    null, [], jsc.blockStatement([jsc.returnStatement(
                                  templateLiteral)])),
                true));
      } else if (node.type === 'CallExpression') {
        // A Polymer hybrid/legacy factory function element
        const arg = node.arguments[0];
        if (arg && arg.type === 'ObjectExpression') {
          arg.properties.unshift(jsc.property(
              'init', jsc.identifier('_template'), templateLiteral));
        }
      } else {
        console.error(`Internal Error, Class or CallExpression expected, got ${
            node.type}`);
      }
    }
    return claimedDomModules;
  }
github Polymer / tools / src / document-processor.ts View on Github external
continue;
      }

      const importMeta = jsc.memberExpression(
          jsc.identifier('import'), jsc.identifier('meta'));

      const node = nodePath.node;
      if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
        // A Polymer 2.0 class-based element
        const getter = jsc.methodDefinition(
            'get',
            jsc.identifier('importMeta'),
            jsc.functionExpression(
                null,
                [],
                jsc.blockStatement([jsc.returnStatement(importMeta)])),
            true);
        node.body.body.splice(0, 0, getter);
      } else if (node.type === 'CallExpression') {
        // A Polymer hybrid/legacy factory function element
        const arg = node.arguments[0];
        if (arg && arg.type === 'ObjectExpression') {
          arg.properties.unshift(
              jsc.property('init', jsc.identifier('importMeta'), importMeta));
        }
      } else {
        console.error(`Internal Error, Class or CallExpression expected, got ${
            node.type}`);
      }
    }
  }
github Shopify / javascript / packages / shopify-codemod / transforms / utils.js View on Github external
export function getBlockStatementFromFunction({body}) {
  if (!j.BlockStatement.check(body)) {
    return j.blockStatement([j.returnStatement(body)]);
  }

  return body;
}
github Astrocoders / old-astroman / lib / utils / js / reduxAction / appendActionCreator.js View on Github external
function appendActionCreatorFunction({ast, constantName, actionCreatorName}) {
  const newFunction = j.functionDeclaration(j.identifier(actionCreatorName), [], j.blockStatement([
    j.returnStatement(
      j.objectExpression([
        j.property('init', j.literal('type'), j.identifier(constantName)),
      ])
    ),
  ]))
  const newExport = j.exportNamedDeclaration(newFunction, [], null)
  const exports = ast
    .find(j.ExportNamedDeclaration)

  exports
    .at(exports.length - 1)
    .insertAfter(newExport)
}
github Astrocoders / old-astroman / lib / utils / js / reduxAction / appendActionToReducer.js View on Github external
export default function appendActionToReducer({ast, constantName}) {
  appendConstantImport({ast, constantName})

  const switchCase = j.switchCase(j.identifier(constantName), [
    j.returnStatement(j.identifier('state')),
  ])

  return ast
    .find(j.SwitchCase, node => node.test === null)
    .insertBefore(switchCase)
}