How to use the jscodeshift.functionDeclaration 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 / packages / modulizer / src / passes / rewrite-namespace-exports.ts View on Github external
continue;
    }
    const name = key.name;
    const fullName = `${namespaceName}.${name}`;
    // The expression for an internal `this.` reference to a namespace member
    const thisName = `this.${name}`;
    const isMutable = mutableNames.has(fullName) || mutableNames.has(thisName);
    if (value.type === 'ObjectExpression' || value.type === 'ArrayExpression' ||
        value.type === 'Literal') {
      const node = jsc.exportNamedDeclaration(jsc.variableDeclaration(
          isMutable ? 'let' : 'const', [jsc.variableDeclarator(key, value)]));
      (node as NodeWithComments).comments = getCommentsFromNode(propNode);
      exportRecords.push({name, node});
    } else if (value.type === 'FunctionExpression') {
      const func = value;
      const node = jsc.exportNamedDeclaration(jsc.functionDeclaration(
          key,  // id
          func.params,
          func.body,
          func.generator));
      (node as NodeWithComments).comments = getCommentsFromNode(propNode);
      exportRecords.push({name, node});
    } else if (value.type === 'ArrowFunctionExpression') {
      const isMutable =
          mutableNames.has(fullName) || mutableNames.has(thisName);
      const node = jsc.exportNamedDeclaration(jsc.variableDeclaration(
          isMutable ? 'let' : 'const', [jsc.variableDeclarator(key, value)]));
      (node as NodeWithComments).comments = getCommentsFromNode(propNode);
      exportRecords.push({name, node});
    } else if (value.type === 'Identifier') {
      const node = jsc.exportNamedDeclaration(
          null,
github Polymer / tools / src / passes / rewrite-namespace-exports.ts View on Github external
continue;
    }
    const name = key.name;
    const fullName = `${namespaceName}.${name}`;
    // The expression for an internal `this.` reference to a namespace member
    const thisName = `this.${name}`;
    const isMutable = mutableNames.has(fullName) || mutableNames.has(thisName);
    if (value.type === 'ObjectExpression' || value.type === 'ArrayExpression' ||
        value.type === 'Literal') {
      const node = jsc.exportNamedDeclaration(jsc.variableDeclaration(
          isMutable ? 'let' : 'const', [jsc.variableDeclarator(key, value)]));
      (node as NodeWithComments).comments = getCommentsFromNode(propNode);
      exportRecords.push({name, node});
    } else if (value.type === 'FunctionExpression') {
      const func = value;
      const node = jsc.exportNamedDeclaration(jsc.functionDeclaration(
          key,  // id
          func.params,
          func.body,
          func.generator));
      (node as NodeWithComments).comments = getCommentsFromNode(propNode);
      exportRecords.push({name, node});
    } else if (value.type === 'ArrowFunctionExpression') {
      const isMutable =
          mutableNames.has(fullName) || mutableNames.has(thisName);
      const node = jsc.exportNamedDeclaration(jsc.variableDeclaration(
          isMutable ? 'let' : 'const', [jsc.variableDeclarator(key, value)]));
      (node as NodeWithComments).comments = getCommentsFromNode(propNode);
      exportRecords.push({name, node});
    } else if (value.type === 'Identifier') {
      const node = jsc.exportNamedDeclaration(
          null,
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)
}