How to use the jscodeshift.templateElement 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 / passes / rewrite-namespace-exports.ts View on Github external
private rewriteNamespaceObject(
      fullyQualifiedName: string, body: estree.ObjectExpression,
      nodePath: NodePath) {
    const namespaceExports =
        getNamespaceExports(body, this.mutableNames, fullyQualifiedName);

    // Replace nodePath with some number of namespace exports. Easiest way
    // is to insert the exports after nodePath, then remove nodePath.
    const nodePathComments = getComments(nodePath);
    if (nodePathComments.length > 0) {
      const message =
          `TODO(modulizer): A namespace named ${fullyQualifiedName} was\n` +
          `declared here. The surrounding comments should be reviewed,\n` +
          `and this string can then be deleted`;
      const tombstone = jsc.expressionStatement(jsc.templateLiteral(
          [jsc.templateElement({raw: message, cooked: message}, true)], []));
      (tombstone as NodeWithComments).comments = nodePathComments;
      nodePath.insertBefore(tombstone);
    }
    for (const {node} of namespaceExports) {
      nodePath.insertBefore(node);
    }
    nodePath.prune();

    for (const e of namespaceExports) {
      this.exportMigrationRecords.push({
        oldNamespacedName: `${fullyQualifiedName}.${e.name}`,
        es6ExportName: e.name
      });
    }
    this.exportMigrationRecords.push(
        {oldNamespacedName: fullyQualifiedName, es6ExportName: '*'});
github Polymer / tools / packages / modulizer / src / passes / rewrite-namespace-exports.ts View on Github external
private rewriteNamespaceObject(
      fullyQualifiedName: string, body: estree.ObjectExpression,
      nodePath: NodePath) {
    const namespaceExports =
        getNamespaceExports(body, this.mutableNames, fullyQualifiedName);

    // Replace nodePath with some number of namespace exports. Easiest way
    // is to insert the exports after nodePath, then remove nodePath.
    const nodePathComments = getComments(nodePath);
    if (nodePathComments.length > 0) {
      const message =
          `TODO(modulizer): A namespace named ${fullyQualifiedName} was\n` +
          `declared here. The surrounding comments should be reviewed,\n` +
          `and this string can then be deleted`;
      const tombstone = jsc.expressionStatement(jsc.templateLiteral(
          [jsc.templateElement({raw: message, cooked: message}, true)], []));
      (tombstone as NodeWithComments).comments = nodePathComments;
      nodePath.insertBefore(tombstone);
    }
    for (const {node} of namespaceExports) {
      nodePath.insertBefore(node);
    }
    nodePath.prune();

    for (const e of namespaceExports) {
      this.exportMigrationRecords.push({
        oldNamespacedName: `${fullyQualifiedName}.${e.name}`,
        es6ExportName: e.name
      });
    }
    this.exportMigrationRecords.push(
        {oldNamespacedName: fullyQualifiedName, es6ExportName: '*'});