How to use the jscodeshift.callExpression 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 dvajs / dva-ast / src / collections / Entry.js View on Github external
const insertMethod = property.name === 'model' ?
      'insertAfter' :
      'insertBefore';

    const collection = points
      // get parent statement
      .map(path => path.parent)
      .at(0);

    collection[insertMethod].call(
      collection,
      j.expressionStatement(
        j.callExpression(
          j.memberExpression(object, j.identifier('model')),
          [
            j.callExpression(j.identifier('require'), [
              j.literal(modelPath)
            ])
          ]
        )
      )
    );
  },
github Polymer / tools / src / document-converter.ts View on Github external
visitMemberExpression(path: NodePath) {
        const memberPath = getMemberPath(path.node);
        if (!memberPath) {
          this.traverse(path);
          return;
        }
        const memberName = memberPath.join('.');
        const assignmentPath = getPathOfAssignmentTo(path);
        if (assignmentPath) {
          const setterName = getSetterName(memberPath);
          const exportOfMember = namespacedExports.get(setterName);
          if (!exportOfMember || exportOfMember.url === convertedUrl) {
            this.traverse(path);
            return;
          }
          const [callPath] = assignmentPath.replace(jsc.callExpression(
              jsc.identifier(setterName), [assignmentPath.node.right]));
          if (!callPath) {
            throw new Error(
                'Failed to replace a namespace object property set with a setter function call.');
          }
          addToImportedReferences(exportOfMember, callPath.get('callee')!);
          return false;
        }
        const exportOfMember = namespacedExports.get(memberName);
        if (!exportOfMember || exportOfMember.url === convertedUrl) {
          this.traverse(path);
          return;
        }
        // Store the imported reference
        addToImportedReferences(exportOfMember, path);
        return false;
github dvajs / dva-ast / src / collections / Entry.js View on Github external
});

    const { object, property } = points.get().value.callee;
    const insertMethod = property.name === 'model' ?
      'insertAfter' :
      'insertBefore';

    const collection = points
      // get parent statement
      .map(path => path.parent)
      .at(0);

    collection[insertMethod].call(
      collection,
      j.expressionStatement(
        j.callExpression(
          j.memberExpression(object, j.identifier('model')),
          [
            j.callExpression(j.identifier('require'), [
              j.literal(modelPath)
            ])
          ]
        )
      )
    );
  },
github Polymer / tools / packages / modulizer / src / document-util.ts View on Github external
jsc.identifier(varName),
          jsc.callExpression(
              jsc.memberExpression(
                  jsc.identifier('document'), jsc.identifier('createElement')),
              [jsc.literal('template')]))]);
  const setDocumentContainerStatement =
      jsc.expressionStatement(jsc.assignmentExpression(
          '=',
          jsc.memberExpression(
              jsc.identifier(varName), jsc.identifier('innerHTML')),
          templateValue));
  const targetNode = activeInBody ? 'body' : 'head';
  return [
    createElementTemplate,
    setDocumentContainerStatement,
    jsc.expressionStatement(jsc.callExpression(
        jsc.memberExpression(
            jsc.memberExpression(
                jsc.identifier('document'), jsc.identifier(targetNode)),
            jsc.identifier('appendChild')),
        [jsc.memberExpression(
            jsc.identifier(varName), jsc.identifier('content'))]))
  ];
}
github Polymer / tools / src / document-util.ts View on Github external
export function createDomNodeInsertStatements(
    nodes: parse5.ASTNode[], activeInBody = false): estree.Statement[] {
  const varName = `$_documentContainer`;
  const fragment = {
    nodeName: '#document-fragment',
    attrs: [],
    childNodes: nodes,
  };
  const templateValue = serializeNodeToTemplateLiteral(fragment as any, false);

  const createElementDiv = jsc.variableDeclaration(
      'const',
      [jsc.variableDeclarator(
          jsc.identifier(varName),
          jsc.callExpression(
              jsc.memberExpression(
                  jsc.identifier('document'), jsc.identifier('createElement')),
              [jsc.literal('template')]))]);
  const setDocumentContainerStatement =
      jsc.expressionStatement(jsc.assignmentExpression(
          '=',
          jsc.memberExpression(
              jsc.identifier(varName), jsc.identifier('innerHTML')),
          templateValue));
  if (activeInBody) {
    return [
      createElementDiv,
      setDocumentContainerStatement,
      jsc.expressionStatement(jsc.callExpression(
          jsc.memberExpression(
              jsc.memberExpression(
github Shopify / javascript / packages / shopify-codemod / transforms / assert / utils.js View on Github external
export function createAssertion(assertionNameOrProperty, args) {
  const assertionName = (assertionNameOrProperty.name == null)
    ? assertionNameOrProperty
    : assertionNameOrProperty.name;

  return j.callExpression(
    j.memberExpression(j.identifier('assert'), j.identifier(assertionName), false),
    args,
  );
}
github feathersjs / feathers / packages / generator-feathers / lib / transform.js View on Github external
.forEach(prop =>
        prop.value.elements.push(j.callExpression(j.identifier(name), []))
      );
github Polymer / tools / src / document-util.ts View on Github external
jsc.identifier(varName),
          jsc.callExpression(
              jsc.memberExpression(
                  jsc.identifier('document'), jsc.identifier('createElement')),
              [jsc.literal('template')]))]);
  const setDocumentContainerStatement =
      jsc.expressionStatement(jsc.assignmentExpression(
          '=',
          jsc.memberExpression(
              jsc.identifier(varName), jsc.identifier('innerHTML')),
          templateValue));
  if (activeInBody) {
    return [
      createElementDiv,
      setDocumentContainerStatement,
      jsc.expressionStatement(jsc.callExpression(
          jsc.memberExpression(
              jsc.memberExpression(
                  jsc.identifier('document'), jsc.identifier('body')),
              jsc.identifier('appendChild')),
          [jsc.memberExpression(
              jsc.identifier(varName), jsc.identifier('content'))]))
    ];
  }
  const setDisplayNoneStatement = jsc.expressionStatement(jsc.callExpression(
      jsc.memberExpression(
          jsc.identifier(varName), jsc.identifier('setAttribute')),
      [jsc.literal('style'), jsc.literal('display: none;')]));
  return [
    createElementDiv,
    setDisplayNoneStatement,
    setDocumentContainerStatement,
github Polymer / tools / packages / modulizer / src / document-util.ts View on Github external
export function createDomNodeInsertStatements(
    nodes: parse5.ASTNode[], activeInBody = false): estree.Statement[] {
  const varName = `$_documentContainer`;
  const fragment = {
    nodeName: '#document-fragment',
    attrs: [],
    childNodes: nodes,
    __location: {} as parse5.ElementLocationInfo,
  };
  const templateValue = serializeNodeToTemplateLiteral(fragment, false);

  const createElementTemplate = jsc.variableDeclaration(
      'const',
      [jsc.variableDeclarator(
          jsc.identifier(varName),
          jsc.callExpression(
              jsc.memberExpression(
                  jsc.identifier('document'), jsc.identifier('createElement')),
              [jsc.literal('template')]))]);
  const setDocumentContainerStatement =
      jsc.expressionStatement(jsc.assignmentExpression(
          '=',
          jsc.memberExpression(
              jsc.identifier(varName), jsc.identifier('innerHTML')),
          templateValue));
  const targetNode = activeInBody ? 'body' : 'head';
  return [
    createElementTemplate,
    setDocumentContainerStatement,
    jsc.expressionStatement(jsc.callExpression(
        jsc.memberExpression(
            jsc.memberExpression(