How to use the jscodeshift.memberExpression 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
const nodePath = getNodePathInProgram(program, element.astNode);

      if (nodePath === undefined) {
        console.warn(
            new Warning({
              code: 'not-found',
              message: `Can't find recast node for element ${element.tagName}`,
              parsedDocument: this.document.parsedDocument,
              severity: Severity.WARNING,
              sourceRange: element.sourceRange!
            }).toString());
        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
github Polymer / tools / src / document-processor.ts View on Github external
}
      if (!canDomModuleBeInlined(domModule)) {
        continue;
      }
      claimedDomModules.add(domModule);
      const template = dom5.query(domModule, (e) => e.tagName === 'template');
      if (template === null) {
        continue;
      }

      // It's ok to tag templates with the expression `Polymer.html` without
      // adding an import because `Polymer.html` is re-exported by both
      // polymer.html and polymer-element.html and, crucially, template
      // inlining happens before rewriting references.
      const templateLiteral = jsc.taggedTemplateExpression(
          jsc.memberExpression(
              jsc.identifier('Polymer'), jsc.identifier('html')),
          serializeNodeToTemplateLiteral(
              parse5.treeAdapters.default.getTemplateContent(template)));
      const nodePath = getNodePathInProgram(program, element.astNode);

      if (nodePath === undefined) {
        console.warn(
            new Warning({
              code: 'not-found',
              message: `Can't find recast node for element ${element.tagName}`,
              parsedDocument: this.document.parsedDocument,
              severity: Severity.WARNING,
              sourceRange: element.sourceRange!
            }).toString());
        continue;
      }
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.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
];
  }
  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,
    jsc.expressionStatement(jsc.callExpression(
        jsc.memberExpression(
            jsc.memberExpression(
                jsc.identifier('document'), jsc.identifier('head')),
            jsc.identifier('appendChild')),
        [jsc.memberExpression(
            jsc.identifier(varName), jsc.identifier('content'))]))
  ];
}
github Polymer / tools / packages / modulizer / src / document-util.ts View on Github external
__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(
                jsc.identifier('document'), jsc.identifier(targetNode)),
            jsc.identifier('appendChild')),
        [jsc.memberExpression(
            jsc.identifier(varName), jsc.identifier('content'))]))
  ];
}
github Polymer / tools / packages / modulizer / src / document-util.ts View on Github external
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'))]))
  ];
}